Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(839)

Unified Diff: ui/views/examples/button_example.cc

Issue 10174014: views: Add optional overlay image to ImageButton (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove debugging tweak Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/examples/button_example.h ('k') | ui/views/views.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/examples/button_example.cc
diff --git a/ui/views/examples/button_example.cc b/ui/views/examples/button_example.cc
index 39fa76901d825472755e60b9b1c5aa646b57bbdf..fec2d1c12cde0897b8b5d3b3288d7aa52d4d6bd5 100644
--- a/ui/views/examples/button_example.cc
+++ b/ui/views/examples/button_example.cc
@@ -8,15 +8,22 @@
#include "grit/ui_resources.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image.h"
-#include "ui/views/controls/button/checkbox.h"
-#include "ui/views/layout/fill_layout.h"
+#include "ui/views/controls/button/image_button.h"
+#include "ui/views/controls/button/text_button.h"
+#include "ui/views/layout/box_layout.h"
#include "ui/views/view.h"
+namespace {
+const int kLayoutSpacing = 10; // pixels
+} // namespace
+
namespace views {
namespace examples {
ButtonExample::ButtonExample()
- : ExampleBase("Text Button"),
+ : ExampleBase("Button"),
+ text_button_(NULL),
+ image_button_(NULL),
alignment_(TextButton::ALIGN_LEFT),
use_native_theme_border_(false),
icon_(NULL),
@@ -29,10 +36,22 @@ ButtonExample::~ButtonExample() {
}
void ButtonExample::CreateExampleView(View* container) {
- TextButton* tb = new TextButton(this, ASCIIToUTF16("Button"));
- button_ = tb;
- container->SetLayoutManager(new FillLayout);
- container->AddChildView(button_);
+ container->SetLayoutManager(
+ new BoxLayout(BoxLayout::kVertical, 0, 0, kLayoutSpacing));
+
+ text_button_ = new TextButton(this, ASCIIToUTF16("Text Button"));
+ container->AddChildView(text_button_);
+
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ image_button_ = new ImageButton(this);
+ image_button_->SetImage(ImageButton::BS_NORMAL,
+ rb.GetImageNamed(IDR_CLOSE).ToSkBitmap());
+ image_button_->SetImage(ImageButton::BS_HOT,
+ rb.GetImageNamed(IDR_CLOSE_H).ToSkBitmap());
+ image_button_->SetImage(ImageButton::BS_PUSHED,
+ rb.GetImageNamed(IDR_CLOSE_P).ToSkBitmap());
+ image_button_->SetOverlayImage(rb.GetImageNamed(IDR_MENU_CHECK).ToSkBitmap());
+ container->AddChildView(image_button_);
}
void ButtonExample::ButtonPressed(Button* sender, const Event& event) {
@@ -41,29 +60,29 @@ void ButtonExample::ButtonPressed(Button* sender, const Event& event) {
if (event.IsControlDown()) {
if (event.IsShiftDown()) {
if (event.IsAltDown()) {
- button_->SetMultiLine(!button_->multi_line());
- if (button_->multi_line()) {
- button_->SetText(ASCIIToUTF16("Multi-line text\n") +
+ text_button_->SetMultiLine(!text_button_->multi_line());
+ if (text_button_->multi_line()) {
+ text_button_->SetText(ASCIIToUTF16("Multi-line text\n") +
ASCIIToUTF16("is here to stay all the way!\n") +
ASCIIToUTF16("123"));
} else {
- button_->SetText(ASCIIToUTF16("Button"));
+ text_button_->SetText(ASCIIToUTF16("Button"));
}
} else {
- switch(button_->icon_placement()) {
+ switch(text_button_->icon_placement()) {
case TextButton::ICON_ON_LEFT:
- button_->set_icon_placement(TextButton::ICON_ON_RIGHT);
+ text_button_->set_icon_placement(TextButton::ICON_ON_RIGHT);
break;
case TextButton::ICON_ON_RIGHT:
- button_->set_icon_placement(TextButton::ICON_ON_LEFT);
+ text_button_->set_icon_placement(TextButton::ICON_ON_LEFT);
break;
}
}
} else if (event.IsAltDown()) {
- if (button_->HasIcon())
- button_->SetIcon(SkBitmap());
+ if (text_button_->HasIcon())
+ text_button_->SetIcon(SkBitmap());
else
- button_->SetIcon(*icon_);
+ text_button_->SetIcon(*icon_);
} else {
switch(alignment_) {
case TextButton::ALIGN_LEFT:
@@ -76,30 +95,31 @@ void ButtonExample::ButtonPressed(Button* sender, const Event& event) {
alignment_ = TextButton::ALIGN_LEFT;
break;
}
- button_->set_alignment(alignment_);
+ text_button_->set_alignment(alignment_);
}
} else if (event.IsShiftDown()) {
if (event.IsAltDown()) {
- if (button_->text().length() < 10) {
- button_->SetText(
+ if (text_button_->text().length() < 10) {
+ text_button_->SetText(
ASCIIToUTF16("Startof") +
ASCIIToUTF16("ReallyReallyReallyReallyReallyReallyReally") +
ASCIIToUTF16("ReallyReallyReallyReallyReallyReallyReally") +
ASCIIToUTF16("ReallyReallyReallyReallyReallyReallyReally") +
ASCIIToUTF16("LongButtonText"));
} else {
- button_->SetText(ASCIIToUTF16("Button"));
+ text_button_->SetText(ASCIIToUTF16("Button"));
}
} else {
use_native_theme_border_ = !use_native_theme_border_;
if (use_native_theme_border_)
- button_->set_border(new TextButtonNativeThemeBorder(button_));
+ text_button_->set_border(new TextButtonNativeThemeBorder(text_button_));
else
- button_->set_border(new TextButtonBorder());
+ text_button_->set_border(new TextButtonBorder());
}
} else if (event.IsAltDown()) {
- button_->SetIsDefault(!button_->is_default());
+ text_button_->SetIsDefault(!text_button_->is_default());
}
+ example_view()->GetLayoutManager()->Layout(example_view());
}
} // namespace examples
« no previous file with comments | « ui/views/examples/button_example.h ('k') | ui/views/views.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698