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

Side by Side Diff: ui/views/examples/vector_example.cc

Issue 1268633002: Make it easier to test changes to a .icon file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix build? Created 5 years, 4 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 unified diff | Download patch
« no previous file with comments | « ui/views/examples/examples.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/examples/vector_example.h" 5 #include "ui/views/examples/vector_example.h"
6 6
7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h"
7 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
9 #include "ui/gfx/paint_vector_icon.h" 11 #include "ui/gfx/paint_vector_icon.h"
10 #include "ui/gfx/vector_icons_public2.h" 12 #include "ui/gfx/vector_icons_public2.h"
13 #include "ui/views/controls/button/blue_button.h"
14 #include "ui/views/controls/button/button.h"
11 #include "ui/views/controls/image_view.h" 15 #include "ui/views/controls/image_view.h"
12 #include "ui/views/controls/textfield/textfield.h" 16 #include "ui/views/controls/textfield/textfield.h"
13 #include "ui/views/controls/textfield/textfield_controller.h" 17 #include "ui/views/controls/textfield/textfield_controller.h"
14 #include "ui/views/layout/box_layout.h" 18 #include "ui/views/layout/box_layout.h"
15 #include "ui/views/layout/fill_layout.h" 19 #include "ui/views/layout/fill_layout.h"
16 #include "ui/views/view.h" 20 #include "ui/views/view.h"
17 21
18 namespace views { 22 namespace views {
19 namespace examples { 23 namespace examples {
20 24
21 namespace { 25 namespace {
22 26
23 class VectorIconGallery : public View, public TextfieldController { 27 class VectorIconGallery : public View,
28 public TextfieldController,
29 public ButtonListener {
24 public: 30 public:
25 VectorIconGallery() 31 VectorIconGallery()
26 : image_view_(new ImageView()), 32 : image_view_(new ImageView()),
27 size_input_(new Textfield()), 33 size_input_(new Textfield()),
28 color_input_(new Textfield()), 34 color_input_(new Textfield()),
35 file_chooser_(new Textfield()),
36 file_go_button_(new BlueButton(this, base::ASCIIToUTF16("Render"))),
29 vector_id_(0), 37 vector_id_(0),
30 size_(32), 38 size_(32),
31 color_(SK_ColorRED) { 39 color_(SK_ColorRED) {
32 AddChildView(size_input_); 40 AddChildView(size_input_);
33 AddChildView(color_input_); 41 AddChildView(color_input_);
34 AddChildView(image_view_); 42 AddChildView(image_view_);
35 43
44 file_chooser_->set_placeholder_text(
45 base::ASCIIToUTF16("Or enter a file to read"));
46 View* file_container = new View();
47 BoxLayout* file_box = new BoxLayout(BoxLayout::kHorizontal, 10, 10, 10);
48 file_container->SetLayoutManager(file_box);
49 file_container->AddChildView(file_chooser_);
50 file_container->AddChildView(file_go_button_);
51 file_box->SetFlexForView(file_chooser_, 1);
52 AddChildView(file_container);
53
36 size_input_->set_placeholder_text(base::ASCIIToUTF16("Size in dip")); 54 size_input_->set_placeholder_text(base::ASCIIToUTF16("Size in dip"));
37 size_input_->set_controller(this); 55 size_input_->set_controller(this);
38 color_input_->set_placeholder_text(base::ASCIIToUTF16("Color (AARRGGBB)")); 56 color_input_->set_placeholder_text(base::ASCIIToUTF16("Color (AARRGGBB)"));
39 color_input_->set_controller(this); 57 color_input_->set_controller(this);
40 58
41 BoxLayout* box = new BoxLayout(BoxLayout::kVertical, 10, 10, 10); 59 BoxLayout* box = new BoxLayout(BoxLayout::kVertical, 10, 10, 10);
42 SetLayoutManager(box); 60 SetLayoutManager(box);
43 box->SetFlexForView(image_view_, 1); 61 box->SetFlexForView(image_view_, 1);
44 UpdateImage(); 62 UpdateImage();
45 } 63 }
(...skipping 27 matching lines...) Expand all
73 if (new_contents.size() != 8u) 91 if (new_contents.size() != 8u)
74 return; 92 return;
75 unsigned new_color = 93 unsigned new_color =
76 strtoul(base::UTF16ToASCII(new_contents).c_str(), nullptr, 16); 94 strtoul(base::UTF16ToASCII(new_contents).c_str(), nullptr, 16);
77 if (new_color <= 0xffffffff) { 95 if (new_color <= 0xffffffff) {
78 color_ = new_color; 96 color_ = new_color;
79 UpdateImage(); 97 UpdateImage();
80 } 98 }
81 } 99 }
82 100
101 // ButtonListener
102 void ButtonPressed(Button* sender, const ui::Event& event) override {
103 DCHECK_EQ(file_go_button_, sender);
104 std::string contents;
105 #if defined(OS_POSIX)
106 base::FilePath path(base::UTF16ToUTF8(file_chooser_->text()));
107 #elif defined(OS_WIN)
108 base::FilePath path(file_chooser_->text());
109 #endif
110 base::ReadFileToString(path, &contents);
111 image_view_->SetImage(
112 gfx::CreateVectorIconFromSource(contents, size_, color_));
113 }
114
83 void UpdateImage() { 115 void UpdateImage() {
84 image_view_->SetImage(gfx::CreateVectorIcon( 116 image_view_->SetImage(gfx::CreateVectorIcon(
85 static_cast<gfx::VectorIconId>(vector_id_), size_, color_)); 117 static_cast<gfx::VectorIconId>(vector_id_), size_, color_));
86 } 118 }
87 119
88 private: 120 private:
89 ImageView* image_view_; 121 ImageView* image_view_;
90 Textfield* size_input_; 122 Textfield* size_input_;
91 Textfield* color_input_; 123 Textfield* color_input_;
124 Textfield* file_chooser_;
125 Button* file_go_button_;
92 126
93 int vector_id_; 127 int vector_id_;
94 size_t size_; 128 size_t size_;
95 SkColor color_; 129 SkColor color_;
96 130
97 DISALLOW_COPY_AND_ASSIGN(VectorIconGallery); 131 DISALLOW_COPY_AND_ASSIGN(VectorIconGallery);
98 }; 132 };
99 133
100 } // namespace 134 } // namespace
101 135
102 VectorExample::VectorExample() : ExampleBase("Vector Icon") {} 136 VectorExample::VectorExample() : ExampleBase("Vector Icon") {}
103 137
104 VectorExample::~VectorExample() {} 138 VectorExample::~VectorExample() {}
105 139
106 void VectorExample::CreateExampleView(View* container) { 140 void VectorExample::CreateExampleView(View* container) {
107 container->SetLayoutManager(new FillLayout()); 141 container->SetLayoutManager(new FillLayout());
108 container->AddChildView(new VectorIconGallery()); 142 container->AddChildView(new VectorIconGallery());
109 } 143 }
110 144
111 } // namespace examples 145 } // namespace examples
112 } // namespace views 146 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/examples/examples.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698