Merge lp:~3v1n0/unity/shortcuts-hidpi into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Superseded
Proposed branch: lp:~3v1n0/unity/shortcuts-hidpi
Merge into: lp:unity
Prerequisite: lp:~3v1n0/unity/shutdown-hidpi-fixes
Diff against target: 595 lines (+210/-84)
7 files modified
shortcuts/ShortcutController.cpp (+1/-1)
shortcuts/ShortcutView.cpp (+113/-48)
shortcuts/ShortcutView.h (+9/-3)
tests/test_unity_window_view.cpp (+9/-9)
unity-shared/UnityWindowStyle.cpp (+65/-15)
unity-shared/UnityWindowStyle.h (+6/-3)
unity-shared/UnityWindowView.cpp (+7/-5)
To merge this branch: bzr merge lp:~3v1n0/unity/shortcuts-hidpi
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Andrea Azzarone (community) Needs Fixing
Review via email: mp+218738@code.launchpad.net

This proposal has been superseded by a proposal from 2014-05-16.

Commit message

ShortcutView: use RawPixel's for the size values and convert them to match current scaling

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Andrea Azzarone (azzar1) wrote :
review: Needs Fixing
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

> Here the overlay appears different before and after the fix.
>
> https://www.dropbox.com/s/0is33cmdjf6uj19/before.png
> https://www.dropbox.com/s/9dph4shu4p3ym5r/after.png

This is because both in English and many localized versions the keys
or descriptions are cut, while there's no reason to limit the
horizontal size, since most of netbooks will still be able to see it.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'shortcuts/ShortcutController.cpp'
--- shortcuts/ShortcutController.cpp 2014-05-16 00:33:37 +0000
+++ shortcuts/ShortcutController.cpp 2014-05-16 00:33:37 +0000
@@ -70,11 +70,11 @@
70 if (!view_)70 if (!view_)
71 return;71 return;
7272
73 model->Fill();
73 view_->SetModel(model);74 view_->SetModel(model);
7475
75 if (Visible())76 if (Visible())
76 {77 {
77 model->Fill();
78 auto const& offset = GetOffsetPerMonitor(view_->monitor());78 auto const& offset = GetOffsetPerMonitor(view_->monitor());
7979
80 if (offset.x < 0 || offset.y < 0)80 if (offset.x < 0 || offset.y < 0)
8181
=== modified file 'shortcuts/ShortcutView.cpp'
--- shortcuts/ShortcutView.cpp 2013-11-16 11:44:23 +0000
+++ shortcuts/ShortcutView.cpp 2014-05-16 00:33:37 +0000
@@ -38,10 +38,16 @@
38 const unsigned MAIN_TITLE_FONT_SIZE = 15;38 const unsigned MAIN_TITLE_FONT_SIZE = 15;
39 const unsigned SECTION_NAME_FONT_SIZE = 12;39 const unsigned SECTION_NAME_FONT_SIZE = 12;
40 const unsigned SHORTKEY_ENTRY_FONT_SIZE = 9;40 const unsigned SHORTKEY_ENTRY_FONT_SIZE = 9;
41 const unsigned INTER_SPACE_SHORTKEY_DESCRIPTION = 10;41 const RawPixel INTER_SPACE_SHORTKEY_DESCRIPTION = 10_em;
42 const unsigned SHORTKEY_COLUMN_WIDTH = 150;42 const RawPixel SHORTKEY_COLUMN_DEFAULT_WIDTH = 150_em;
43 const unsigned DESCRIPTION_COLUMN_WIDTH = 265;43 const RawPixel SHORTKEY_COLUMN_MAX_WIDTH = 350_em;
44 const unsigned LINE_SPACING = 5;44 const RawPixel DESCRIPTION_COLUMN_DEFAULT_WIDTH = 265_em;
45 const RawPixel DESCRIPTION_COLUMN_MAX_WIDTH = 500_em;
46 const RawPixel LINE_SPACING = 3_em;
47 const RawPixel MAIN_HORIZONTAL_PADDING = 30_em;
48 const RawPixel MAIN_VERTICAL_PADDING = 18_em;
49 const RawPixel MAIN_CHILDREN_SPACE = 20_em;
50 const RawPixel COLUMNS_CHILDREN_SPACE = 30_em;
4551
46 // We need this class because SetVisible doesn't work for layouts.52 // We need this class because SetVisible doesn't work for layouts.
47 class SectionView : public nux::View53 class SectionView : public nux::View
@@ -72,8 +78,8 @@
72 : ui::UnityWindowView()78 : ui::UnityWindowView()
73{79{
74 auto main_layout = new nux::VLayout();80 auto main_layout = new nux::VLayout();
75 main_layout->SetPadding(30, 18);81 main_layout->SetPadding(MAIN_HORIZONTAL_PADDING.CP(scale), MAIN_VERTICAL_PADDING.CP(scale));
76 main_layout->SetSpaceBetweenChildren(20);82 main_layout->SetSpaceBetweenChildren(MAIN_CHILDREN_SPACE.CP(scale));
77 SetLayout(main_layout);83 SetLayout(main_layout);
7884
79 std::string header = "<b>"+std::string(_("Keyboard Shortcuts"))+"</b>";85 std::string header = "<b>"+std::string(_("Keyboard Shortcuts"))+"</b>";
@@ -81,13 +87,22 @@
81 auto* header_view = new StaticCairoText(header, NUX_TRACKER_LOCATION);87 auto* header_view = new StaticCairoText(header, NUX_TRACKER_LOCATION);
82 header_view->SetFont(FONT_NAME+" "+std::to_string(MAIN_TITLE_FONT_SIZE));88 header_view->SetFont(FONT_NAME+" "+std::to_string(MAIN_TITLE_FONT_SIZE));
83 header_view->SetLines(-1);89 header_view->SetLines(-1);
90 header_view->SetScale(scale);
84 main_layout->AddView(header_view, 1 , nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);91 main_layout->AddView(header_view, 1 , nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
8592
86 main_layout->AddView(new HSeparator(), 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);93 main_layout->AddView(new HSeparator(), 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
8794
88 columns_layout_ = new nux::HLayout();95 columns_layout_ = new nux::HLayout();
89 columns_layout_->SetSpaceBetweenChildren(30);96 columns_layout_->SetSpaceBetweenChildren(COLUMNS_CHILDREN_SPACE.CP(scale));
90 main_layout->AddLayout(columns_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);97 main_layout->AddLayout(columns_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
98
99 scale.changed.connect([this, main_layout, header_view] (double scale) {
100 main_layout->SetPadding(MAIN_HORIZONTAL_PADDING.CP(scale), MAIN_VERTICAL_PADDING.CP(scale));
101 main_layout->SetSpaceBetweenChildren(MAIN_CHILDREN_SPACE.CP(scale));
102 columns_layout_->SetSpaceBetweenChildren(COLUMNS_CHILDREN_SPACE.CP(scale));
103 header_view->SetScale(scale);
104 RenderColumns();
105 });
91}106}
92107
93void View::SetModel(Model::Ptr model)108void View::SetModel(Model::Ptr model)
@@ -114,14 +129,17 @@
114 auto* section_name_view = new StaticCairoText(name, NUX_TRACKER_LOCATION);129 auto* section_name_view = new StaticCairoText(name, NUX_TRACKER_LOCATION);
115 section_name_view->SetFont(FONT_NAME+" "+std::to_string(SECTION_NAME_FONT_SIZE));130 section_name_view->SetFont(FONT_NAME+" "+std::to_string(SECTION_NAME_FONT_SIZE));
116 section_name_view->SetLines(-1);131 section_name_view->SetLines(-1);
117 layout->AddView(new nux::SpaceLayout(10, 10, 10, 10), 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT);132 section_name_view->SetScale(scale);
133 const int top_space = (10_em).CP(scale);
134 const int bottom_space = (15_em).CP(scale);
135 layout->AddView(new nux::SpaceLayout(top_space, top_space, top_space, top_space), 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT);
118 layout->AddView(section_name_view, 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT);136 layout->AddView(section_name_view, 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT);
119 layout->AddView(new nux::SpaceLayout(15, 15, 15, 15), 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT);137 layout->AddView(new nux::SpaceLayout(bottom_space, bottom_space, bottom_space, bottom_space), 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT);
120138
121 return layout;139 return layout;
122}140}
123141
124nux::View* View::CreateShortKeyEntryView(AbstractHint::Ptr const& hint)142nux::View* View::CreateShortKeyEntryView(AbstractHint::Ptr const& hint, StaticCairoText* shortkey_view, StaticCairoText* description_view)
125{143{
126 auto* view = new SectionView(NUX_TRACKER_LOCATION);144 auto* view = new SectionView(NUX_TRACKER_LOCATION);
127145
@@ -131,56 +149,56 @@
131 nux::HLayout* shortkey_layout = new nux::HLayout(NUX_TRACKER_LOCATION);149 nux::HLayout* shortkey_layout = new nux::HLayout(NUX_TRACKER_LOCATION);
132 nux::HLayout* description_layout = new nux::HLayout(NUX_TRACKER_LOCATION);150 nux::HLayout* description_layout = new nux::HLayout(NUX_TRACKER_LOCATION);
133151
134 glib::String shortkey(g_markup_escape_text(hint->shortkey().c_str(), -1));
135
136 std::string skey = "<b>"+shortkey.Str()+"</b>";
137 auto* shortkey_view = new StaticCairoText(skey, NUX_TRACKER_LOCATION);
138 shortkey_view->SetTextAlignment(StaticCairoText::AlignState::NUX_ALIGN_LEFT);
139 shortkey_view->SetFont(FONT_NAME+" "+std::to_string(SHORTKEY_ENTRY_FONT_SIZE));
140 shortkey_view->SetLines(-1);
141 shortkey_view->SetMinimumWidth(SHORTKEY_COLUMN_WIDTH);
142 shortkey_view->SetMaximumWidth(SHORTKEY_COLUMN_WIDTH);
143
144 glib::String es_desc(g_markup_escape_text(hint->description().c_str(), -1));
145
146 auto* description_view = new StaticCairoText(es_desc.Str(), NUX_TRACKER_LOCATION);
147 description_view->SetTextAlignment(StaticCairoText::AlignState::NUX_ALIGN_LEFT);
148 description_view->SetFont(FONT_NAME+" "+std::to_string(SHORTKEY_ENTRY_FONT_SIZE));
149 description_view->SetLines(-1);
150 description_view->SetMinimumWidth(DESCRIPTION_COLUMN_WIDTH);
151 description_view->SetMaximumWidth(DESCRIPTION_COLUMN_WIDTH);
152
153 shortkey_layout->AddView(shortkey_view, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);152 shortkey_layout->AddView(shortkey_view, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);
154 shortkey_layout->SetContentDistribution(nux::MAJOR_POSITION_START);153 shortkey_layout->SetContentDistribution(nux::MAJOR_POSITION_START);
155 shortkey_layout->SetMinimumWidth(SHORTKEY_COLUMN_WIDTH);
156 shortkey_layout->SetMaximumWidth(SHORTKEY_COLUMN_WIDTH);
157154
158 description_layout->AddView(description_view, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);155 description_layout->AddView(description_view, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);
159 description_layout->SetContentDistribution(nux::MAJOR_POSITION_START);156 description_layout->SetContentDistribution(nux::MAJOR_POSITION_START);
160 description_layout->SetMinimumWidth(DESCRIPTION_COLUMN_WIDTH);
161 description_layout->SetMaximumWidth(DESCRIPTION_COLUMN_WIDTH);
162157
163 layout->AddLayout(shortkey_layout, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);158 layout->AddLayout(shortkey_layout, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);
164 layout->AddLayout(description_layout, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);159 layout->AddLayout(description_layout, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);
165 layout->SetSpaceBetweenChildren(INTER_SPACE_SHORTKEY_DESCRIPTION);160 layout->SetSpaceBetweenChildren(INTER_SPACE_SHORTKEY_DESCRIPTION.CP(scale));
166 description_layout->SetContentDistribution(nux::MAJOR_POSITION_START);161 description_layout->SetContentDistribution(nux::MAJOR_POSITION_START);
167162
168 view->key_changed_conn_ = hint->shortkey.changed.connect([this, view, shortkey_view] (std::string const& new_key) {163 view->key_changed_conn_ = hint->shortkey.changed.connect([this, view, shortkey_view] (std::string const& key) {
169 bool enabled = !new_key.empty();164 std::string escaped = glib::String(g_markup_escape_text(key.c_str(), -1)).Str();
170 shortkey_view->SetText(enabled ? "<b>"+new_key+"</b>" : "");165
171 view->SetVisible(enabled);166 if (!escaped.empty())
167 escaped = "<b>"+escaped+"</b>";
168
169 shortkey_view->SetText(escaped);
170 shortkey_view->SetVisible(!escaped.empty());
171 view->SetVisible(shortkey_view->IsVisible());
172 QueueRelayout();172 QueueRelayout();
173 QueueDraw();
173 });174 });
174175
175 view->SetVisible(!shortkey.Str().empty());176 view->SetVisible(shortkey_view->IsVisible());
176177
177 return view;178 return view;
178}179}
179180
181StaticCairoText* View::CreateShortcutTextView(std::string const& text, bool bold)
182{
183 std::string escaped = glib::String(g_markup_escape_text(text.c_str(), -1)).Str();
184
185 if (bold && !text.empty())
186 escaped = "<b>"+escaped+"</b>";
187
188 auto* text_view = new StaticCairoText(escaped, NUX_TRACKER_LOCATION);
189 text_view->SetTextAlignment(StaticCairoText::AlignState::NUX_ALIGN_LEFT);
190 text_view->SetFont(FONT_NAME+" "+std::to_string(SHORTKEY_ENTRY_FONT_SIZE));
191 text_view->SetLines(-1);
192 text_view->SetScale(scale);
193 text_view->SetVisible(!escaped.empty());
194
195 return text_view;
196}
197
180nux::LinearLayout* View::CreateIntermediateLayout()198nux::LinearLayout* View::CreateIntermediateLayout()
181{199{
182 nux::VLayout* layout = new nux::VLayout(NUX_TRACKER_LOCATION);200 nux::VLayout* layout = new nux::VLayout(NUX_TRACKER_LOCATION);
183 layout->SetSpaceBetweenChildren(LINE_SPACING);201 layout->SetSpaceBetweenChildren(LINE_SPACING.CP(scale));
184202
185 return layout;203 return layout;
186}204}
@@ -195,9 +213,38 @@
195 view_layout_->ProcessDraw(GfxContext, force_draw);213 view_layout_->ProcessDraw(GfxContext, force_draw);
196}214}
197215
216void View::PreLayoutManagement()
217{
218 UnityWindowView::PreLayoutManagement();
219
220 for (auto const& column : shortkeys_)
221 {
222 int min_width = SHORTKEY_COLUMN_DEFAULT_WIDTH.CP(scale);
223
224 for (auto* shortkey : column)
225 min_width = std::min(std::max(min_width, shortkey->GetTextExtents().width), shortkey->GetMaximumWidth());
226
227 for (auto* shortkey : column)
228 shortkey->SetMinimumWidth(min_width);
229 }
230
231 for (auto const& column : descriptions_)
232 {
233 int min_width = DESCRIPTION_COLUMN_DEFAULT_WIDTH.CP(scale);
234
235 for (auto* description : column)
236 min_width = std::min(std::max(min_width, description->GetTextExtents().width), description->GetMaximumWidth());
237
238 for (auto* description : column)
239 description->SetMinimumWidth(min_width);
240 }
241}
242
198void View::RenderColumns()243void View::RenderColumns()
199{244{
200 columns_layout_->Clear();245 columns_layout_->Clear();
246 shortkeys_.clear();
247 descriptions_.clear();
201248
202 if (!model_)249 if (!model_)
203 {250 {
@@ -209,11 +256,21 @@
209 int i = 0;256 int i = 0;
210 int column_idx = 0;257 int column_idx = 0;
211 auto const& columns = columns_layout_->GetChildren();258 auto const& columns = columns_layout_->GetChildren();
212259 auto const& categories = model_->categories();
213 for (auto const& category : model_->categories())260 const int categories_per_column = model_->categories_per_column();
261 const int columns_number = categories.size() / categories_per_column + 1;
262 const int top_space = (23_em).CP(scale);
263 const int bottom_space = (20_em).CP(scale);
264 const int max_shortkeys_width = SHORTKEY_COLUMN_MAX_WIDTH.CP(scale);
265 const int max_descriptions_width = DESCRIPTION_COLUMN_MAX_WIDTH.CP(scale);
266
267 shortkeys_.resize(columns_number);
268 descriptions_.resize(columns_number);
269
270 for (auto const& category : categories)
214 {271 {
215 // Computing column index based on current index272 // Computing column index based on current index
216 column_idx = i/model_->categories_per_column();273 column_idx = i/categories_per_column;
217274
218 nux::LinearLayout* section_layout = CreateSectionLayout(category);275 nux::LinearLayout* section_layout = CreateSectionLayout(category);
219 nux::LinearLayout* intermediate_layout = CreateIntermediateLayout();276 nux::LinearLayout* intermediate_layout = CreateIntermediateLayout();
@@ -221,19 +278,27 @@
221278
222 for (auto const& hint : model_->hints().at(category))279 for (auto const& hint : model_->hints().at(category))
223 {280 {
224 nux::View* view = CreateShortKeyEntryView(hint);281 StaticCairoText* shortkey = CreateShortcutTextView(hint->shortkey(), true);
282 shortkey->SetMaximumWidth(max_shortkeys_width);
283 shortkeys_[column_idx].push_back(shortkey);
284
285 StaticCairoText* description = CreateShortcutTextView(hint->description(), false);
286 description->SetMaximumWidth(max_descriptions_width);
287 descriptions_[column_idx].push_back(description);
288
289 nux::View* view = CreateShortKeyEntryView(hint, shortkey, description);
225 intermediate_layout->AddView(view, 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL);290 intermediate_layout->AddView(view, 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL);
226 }291 }
227292
228 section_layout->AddLayout(intermediate_layout, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);293 section_layout->AddLayout(intermediate_layout, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
229294
230 if ((i + 1) % model_->categories_per_column() != 0 && category != model_->categories().back())295 if ((i + 1) % categories_per_column != 0 && category != categories.back())
231 {296 {
232 // Add a line with some padding after and before each category that is not297 // Add a line with some padding after and before each category that is not
233 // the last of the column.298 // the last of the column.
234 section_layout->AddView(new nux::SpaceLayout(23, 23, 23, 23), 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT);299 section_layout->AddView(new nux::SpaceLayout(top_space, top_space, top_space, top_space), 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT);
235 section_layout->AddView(new HSeparator(), 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);300 section_layout->AddView(new HSeparator(), 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
236 section_layout->AddView(new nux::SpaceLayout(20, 20, 20, 20), 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT);301 section_layout->AddView(new nux::SpaceLayout(bottom_space, bottom_space, bottom_space, bottom_space), 0, nux::MINOR_POSITION_START, nux::MINOR_SIZE_MATCHCONTENT);
237 }302 }
238303
239 nux::VLayout* column = nullptr;304 nux::VLayout* column = nullptr;
@@ -251,7 +316,7 @@
251316
252 column->AddView(section_layout, 1, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL);317 column->AddView(section_layout, 1, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL);
253318
254 i++;319 ++i;
255 }320 }
256321
257 ComputeContentSize();322 ComputeContentSize();
258323
=== modified file 'shortcuts/ShortcutView.h'
--- shortcuts/ShortcutView.h 2013-11-16 11:44:23 +0000
+++ shortcuts/ShortcutView.h 2014-05-16 00:33:37 +0000
@@ -29,6 +29,8 @@
2929
30namespace unity30namespace unity
31{31{
32class StaticCairoText;
33
32namespace shortcut34namespace shortcut
33{35{
3436
@@ -47,8 +49,9 @@
4749
48protected:50protected:
49 // Protected methods51 // Protected methods
50 void DrawOverlay(nux::GraphicsEngine& GfxContext, bool force_draw, nux::Geometry const& clip);52 void DrawOverlay(nux::GraphicsEngine& GfxContext, bool force_draw, nux::Geometry const& clip) override;
51 nux::Geometry GetBackgroundGeometry();53 nux::Geometry GetBackgroundGeometry() override;
54 void PreLayoutManagement() override;
5255
53 // Introspectable methods56 // Introspectable methods
54 std::string GetName() const;57 std::string GetName() const;
@@ -56,7 +59,8 @@
56private:59private:
57 // Private methods60 // Private methods
58 nux::LinearLayout* CreateSectionLayout(std::string const& section_name);61 nux::LinearLayout* CreateSectionLayout(std::string const& section_name);
59 nux::View* CreateShortKeyEntryView(AbstractHint::Ptr const& hint);62 nux::View* CreateShortKeyEntryView(AbstractHint::Ptr const&, StaticCairoText* shortkey, StaticCairoText* description);
63 StaticCairoText* CreateShortcutTextView(std::string const& text, bool bold);
60 nux::LinearLayout* CreateIntermediateLayout();64 nux::LinearLayout* CreateIntermediateLayout();
6165
62 void RenderColumns();66 void RenderColumns();
@@ -64,6 +68,8 @@
64 // Private members68 // Private members
65 Model::Ptr model_;69 Model::Ptr model_;
66 nux::HLayout* columns_layout_;70 nux::HLayout* columns_layout_;
71 std::vector<std::vector<StaticCairoText*>> shortkeys_;
72 std::vector<std::vector<StaticCairoText*>> descriptions_;
6773
68 friend class TestShortcutView;74 friend class TestShortcutView;
69};75};
7076
=== modified file 'tests/test_unity_window_view.cpp'
--- tests/test_unity_window_view.cpp 2014-03-21 04:40:12 +0000
+++ tests/test_unity_window_view.cpp 2014-05-16 00:33:37 +0000
@@ -82,10 +82,10 @@
82 view.closable = true;82 view.closable = true;
83 ASSERT_NE(view.close_button_, nullptr);83 ASSERT_NE(view.close_button_, nullptr);
8484
85 EXPECT_EQ(view.close_button_->texture(), view.style()->GetCloseIcon());85 EXPECT_EQ(view.close_button_->texture(), view.style()->GetTexture(view.scale, WindowTextureType::CLOSE_ICON));
86 EXPECT_EQ(view.close_button_->GetParentObject(), &view);86 EXPECT_EQ(view.close_button_->GetParentObject(), &view);
8787
88 int padding = view.style()->GetCloseButtonPadding();88 int padding = view.style()->GetCloseButtonPadding(view.scale);
89 EXPECT_EQ(view.close_button_->GetBaseX(), padding);89 EXPECT_EQ(view.close_button_->GetBaseX(), padding);
90 EXPECT_EQ(view.close_button_->GetBaseY(), padding);90 EXPECT_EQ(view.close_button_->GetBaseY(), padding);
91}91}
@@ -96,16 +96,16 @@
96 ASSERT_NE(view.close_button_, nullptr);96 ASSERT_NE(view.close_button_, nullptr);
9797
98 view.close_button_->mouse_enter.emit(0, 0, 0, 0);98 view.close_button_->mouse_enter.emit(0, 0, 0, 0);
99 EXPECT_EQ(view.close_button_->texture(), view.style()->GetCloseIconHighligted());99 EXPECT_EQ(view.close_button_->texture(), view.style()->GetTexture(view.scale, WindowTextureType::CLOSE_ICON_HIGHLIGHTED));
100100
101 view.close_button_->mouse_leave.emit(0, 0, 0, 0);101 view.close_button_->mouse_leave.emit(0, 0, 0, 0);
102 EXPECT_EQ(view.close_button_->texture(), view.style()->GetCloseIcon());102 EXPECT_EQ(view.close_button_->texture(), view.style()->GetTexture(view.scale, WindowTextureType::CLOSE_ICON));
103103
104 view.close_button_->mouse_down.emit(0, 0, 0, 0);104 view.close_button_->mouse_down.emit(0, 0, 0, 0);
105 EXPECT_EQ(view.close_button_->texture(), view.style()->GetCloseIconPressed());105 EXPECT_EQ(view.close_button_->texture(), view.style()->GetTexture(view.scale, WindowTextureType::CLOSE_ICON_PRESSED));
106106
107 view.close_button_->mouse_up.emit(0, 0, 0, 0);107 view.close_button_->mouse_up.emit(0, 0, 0, 0);
108 EXPECT_EQ(view.close_button_->texture(), view.style()->GetCloseIcon());108 EXPECT_EQ(view.close_button_->texture(), view.style()->GetTexture(view.scale, WindowTextureType::CLOSE_ICON));
109}109}
110110
111TEST_F(TestUnityWindowView, CloseButtonClicksRequestsClose)111TEST_F(TestUnityWindowView, CloseButtonClicksRequestsClose)
@@ -185,7 +185,7 @@
185 view.SetLayout(layout);185 view.SetLayout(layout);
186 view.ComputeContentSize();186 view.ComputeContentSize();
187187
188 int offset = view.style()->GetInternalOffset();188 int offset = view.style()->GetInternalOffset(view.scale);
189 EXPECT_EQ(layout->GetBaseX(), offset);189 EXPECT_EQ(layout->GetBaseX(), offset);
190 EXPECT_EQ(layout->GetBaseY(), offset);190 EXPECT_EQ(layout->GetBaseY(), offset);
191}191}
@@ -199,7 +199,7 @@
199199
200TEST_F(TestUnityWindowView, GetInternalBackground)200TEST_F(TestUnityWindowView, GetInternalBackground)
201{201{
202 int offset = view.style()->GetInternalOffset();202 int offset = view.style()->GetInternalOffset(view.scale);
203 view.background_geo_.Set(g_random_int(), g_random_int(), g_random_int(), g_random_int());203 view.background_geo_.Set(g_random_int(), g_random_int(), g_random_int(), g_random_int());
204 EXPECT_EQ(view.GetInternalBackground(), view.background_geo_.GetExpand(-offset, -offset));204 EXPECT_EQ(view.GetInternalBackground(), view.background_geo_.GetExpand(-offset, -offset));
205}205}
@@ -240,4 +240,4 @@
240}240}
241241
242} // ui242} // ui
243} // unity
244\ No newline at end of file243\ No newline at end of file
244} // unity
245245
=== modified file 'unity-shared/UnityWindowStyle.cpp'
--- unity-shared/UnityWindowStyle.cpp 2014-05-16 00:33:37 +0000
+++ unity-shared/UnityWindowStyle.cpp 2014-05-16 00:33:37 +0000
@@ -21,9 +21,13 @@
2121
22#include <NuxCore/Logger.h>22#include <NuxCore/Logger.h>
2323
24#include "UnitySettings.h"
24#include "UnityWindowStyle.h"25#include "UnityWindowStyle.h"
26#include "UScreen.h"
25#include "config.h"27#include "config.h"
2628
29#include <unordered_set>
30
27namespace unity31namespace unity
28{32{
29namespace ui33namespace ui
@@ -38,14 +42,31 @@
38 const char* const DIALOG_HIGHLIGHT = PKGDATADIR"/dialog_close_highlight.png";42 const char* const DIALOG_HIGHLIGHT = PKGDATADIR"/dialog_close_highlight.png";
39 const char* const DIALOG_PRESS = PKGDATADIR"/dialog_close_press.png";43 const char* const DIALOG_PRESS = PKGDATADIR"/dialog_close_press.png";
4044
41 double const DEFAULT_SCALE = 1.0;45
46 RawPixel const INTERNAL_OFFSET = 20_em;
47 RawPixel const BORDER_SIZE = 30_em;
48 RawPixel const CLOSE_PADDING = 3_em;
42}49}
4350
44DECLARE_LOGGER(logger, "unity.ui.unity.window.style");51DECLARE_LOGGER(logger, "unity.ui.unity.window.style");
4552
53
46UnityWindowStyle::UnityWindowStyle()54UnityWindowStyle::UnityWindowStyle()
47{55{
48 LoadAllTextureInScale(DEFAULT_SCALE);56 unsigned monitors = UScreen::GetDefault()->GetPluggedMonitorsNumber();
57 auto& settings = Settings::Instance();
58
59 // Pre-load scale values per monitor
60 for (unsigned i = 0; i < monitors; ++i)
61 {
62 double scale = settings.Instance().em(i)->DPIScale();
63
64 if (unity_window_textures_.find(scale) == unity_window_textures_.end())
65 LoadAllTextureInScale(scale);
66 }
67
68 settings.Instance().dpi_changed.connect(sigc::mem_fun(this, &UnityWindowStyle::CleanUpUnusedTextures));
69 UScreen::GetDefault()->changed.connect(sigc::mem_fun(this, &UnityWindowStyle::OnMonitorChanged));
49}70}
5071
51void UnityWindowStyle::LoadAllTextureInScale(double scale)72void UnityWindowStyle::LoadAllTextureInScale(double scale)
@@ -76,6 +97,35 @@
76 return max_size;97 return max_size;
77}98}
7899
100void UnityWindowStyle::OnMonitorChanged(int primary, std::vector<nux::Geometry> const& monitors)
101{
102 CleanUpUnusedTextures();
103}
104
105// Get current in use scale values, if a scaled value is allocated, but
106// not in use clean up the scaled textures in unity_window_textures
107void UnityWindowStyle::CleanUpUnusedTextures()
108{
109 unsigned monitors = UScreen::GetDefault()->GetPluggedMonitorsNumber();
110 auto& settings = Settings::Instance();
111 std::unordered_set<double> used_scales;
112
113 for (unsigned i = 0; i < monitors; ++i)
114 used_scales.insert(settings.em(i)->DPIScale());
115
116 for (auto it = unity_window_textures_.begin(); it != unity_window_textures_.end();)
117 {
118 if (used_scales.find(it->first) == used_scales.end())
119 {
120 it = unity_window_textures_.erase(it);
121 }
122 else
123 {
124 ++it;
125 }
126 }
127}
128
79UnityWindowStyle::Ptr const& UnityWindowStyle::Get()129UnityWindowStyle::Ptr const& UnityWindowStyle::Get()
80{130{
81 // This is set only the first time;131 // This is set only the first time;
@@ -83,19 +133,19 @@
83 return instance;133 return instance;
84}134}
85135
86int UnityWindowStyle::GetBorderSize() const136int UnityWindowStyle::GetBorderSize(double scale) const
87{137{
88 return 30; // as measured from textures138 return BORDER_SIZE.CP(scale); // as measured from textures
89}139}
90140
91int UnityWindowStyle::GetInternalOffset() const141int UnityWindowStyle::GetInternalOffset(double scale) const
92{142{
93 return 20;143 return INTERNAL_OFFSET.CP(scale);
94}144}
95145
96int UnityWindowStyle::GetCloseButtonPadding() const146int UnityWindowStyle::GetCloseButtonPadding(double scale) const
97{147{
98 return 3;148 return CLOSE_PADDING.CP(scale);
99}149}
100150
101UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetTexture(double scale, WindowTextureType const& type)151UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetTexture(double scale, WindowTextureType const& type)
102152
=== modified file 'unity-shared/UnityWindowStyle.h'
--- unity-shared/UnityWindowStyle.h 2014-05-16 00:33:37 +0000
+++ unity-shared/UnityWindowStyle.h 2014-05-16 00:33:37 +0000
@@ -52,9 +52,9 @@
52 static UnityWindowStyle::Ptr const& Get();52 static UnityWindowStyle::Ptr const& Get();
5353
54 BaseTexturePtr GetTexture(double scale, WindowTextureType const& type);54 BaseTexturePtr GetTexture(double scale, WindowTextureType const& type);
55 int GetCloseButtonPadding() const;55 int GetCloseButtonPadding(double scale) const;
56 int GetBorderSize() const;56 int GetBorderSize(double scale) const;
57 int GetInternalOffset() const;57 int GetInternalOffset(double scale) const;
5858
59private:59private:
60 UnityWindowStyle();60 UnityWindowStyle();
@@ -63,6 +63,9 @@
63 void LoadAllTextureInScale(double scale);63 void LoadAllTextureInScale(double scale);
64 nux::BaseTexture* LoadTexture(double scale, const char* const texture_name) const;64 nux::BaseTexture* LoadTexture(double scale, const char* const texture_name) const;
65 RawPixel GetDefaultMaxTextureSize(const char* const texture_name) const;65 RawPixel GetDefaultMaxTextureSize(const char* const texture_name) const;
66
67 void OnMonitorChanged(int primary, std::vector<nux::Geometry> const& monitors);
68 void CleanUpUnusedTextures();
6669
67 typedef std::array<BaseTexturePtr, size_t(WindowTextureType::Size)> UnityWindowTextures;70 typedef std::array<BaseTexturePtr, size_t(WindowTextureType::Size)> UnityWindowTextures;
68 std::unordered_map<double, UnityWindowTextures> unity_window_textures_;71 std::unordered_map<double, UnityWindowTextures> unity_window_textures_;
6972
=== modified file 'unity-shared/UnityWindowView.cpp'
--- unity-shared/UnityWindowView.cpp 2014-05-16 00:33:37 +0000
+++ unity-shared/UnityWindowView.cpp 2014-05-16 00:33:37 +0000
@@ -70,7 +70,7 @@
7070
71 if (internal_layout_)71 if (internal_layout_)
72 {72 {
73 int offset = RawPixel(style()->GetInternalOffset()).CP(scale);73 int offset = style()->GetInternalOffset(scale);
74 view_layout_->SetPadding(offset, offset);74 view_layout_->SetPadding(offset, offset);
75 }75 }
76}76}
@@ -138,7 +138,7 @@
138 }138 }
139139
140 auto const& texture = style()->GetTexture(scale, WindowTextureType::CLOSE_ICON);140 auto const& texture = style()->GetTexture(scale, WindowTextureType::CLOSE_ICON);
141 int padding = RawPixel(style()->GetCloseButtonPadding()).CP(scale);141 int padding = style()->GetCloseButtonPadding(scale);
142142
143 close_button_ = new IconTexture(texture);143 close_button_ = new IconTexture(texture);
144 close_button_->SetBaseXY(padding, padding);144 close_button_->SetBaseXY(padding, padding);
@@ -179,7 +179,7 @@
179{179{
180 if (layout && layout->IsLayout())180 if (layout && layout->IsLayout())
181 {181 {
182 int offset = RawPixel(style()->GetInternalOffset()).CP(scale);182 int offset = style()->GetInternalOffset(scale);
183183
184 // We wrap the internal layout adding some padding, so that inherited classes184 // We wrap the internal layout adding some padding, so that inherited classes
185 // can ignore the offsets we define here.185 // can ignore the offsets we define here.
@@ -204,7 +204,8 @@
204204
205nux::Geometry UnityWindowView::GetInternalBackground()205nux::Geometry UnityWindowView::GetInternalBackground()
206{206{
207 int offset = RawPixel(style()->GetInternalOffset()).CP(scale);207 int offset = style()->GetInternalOffset(scale);
208
208 return GetBackgroundGeometry().GetExpand(-offset, -offset);209 return GetBackgroundGeometry().GetExpand(-offset, -offset);
209}210}
210211
@@ -354,7 +355,8 @@
354355
355void UnityWindowView::DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geometry const& geo)356void UnityWindowView::DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geometry const& geo)
356{357{
357 int border = RawPixel(style()->GetBorderSize()).CP(scale);358 int border = style()->GetBorderSize(scale);
359
358 auto background_corner_textrue = style()->GetTexture(scale, WindowTextureType::BACKGROUND_CORNER)->GetDeviceTexture();360 auto background_corner_textrue = style()->GetTexture(scale, WindowTextureType::BACKGROUND_CORNER)->GetDeviceTexture();
359361
360 GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);362 GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);