Merge lp:~tintou/slingshot/fix-layout into lp:~elementary-pantheon/slingshot/trunk

Proposed by Corentin Noël on 2014-10-15
Status: Merged
Approved by: Corentin Noël on 2014-10-16
Approved revision: 465
Merged at revision: 466
Proposed branch: lp:~tintou/slingshot/fix-layout
Merge into: lp:~elementary-pantheon/slingshot/trunk
Diff against target: 368 lines (+76/-98)
6 files modified
src/SlingshotView.vala (+1/-7)
src/Utils.vala (+0/-9)
src/Widgets/AppEntry.vala (+29/-29)
src/Widgets/CategoryView.vala (+29/-43)
src/Widgets/Grid.vala (+13/-5)
src/Widgets/Sidebar.vala (+4/-5)
To merge this branch: bzr merge lp:~tintou/slingshot/fix-layout
Reviewer Review Type Date Requested Status
Tom Beckmann (community) codestyle & code Approve on 2014-10-16
Daniel Fore ux 2014-10-15 Approve on 2014-10-15
elementary Pantheon team code 2014-10-15 Pending
Review via email: mp+238506@code.launchpad.net

Commit message

Adapt to category bar size.

Description of the change

 * Category layout now autoadapts if the sidebar is larger than expected
 * Removed Gtk.Layout + set_size_request in favor of get_preferred_width/height overriding
 * Aligned AppItems with two lines support

To post a comment you must log in.
Daniel Fore (danrabbit) wrote :

Looks good to me. Having two lines available for descriptions is a nice improvement. I don't see any distortions/regressions in regards to alignment. UX Approve :)

review: Approve (ux)
Tom Beckmann (tombeckmann) wrote :

Code looks good :)

review: Approve (codestyle & code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/SlingshotView.vala'
2--- src/SlingshotView.vala 2014-10-15 19:18:53 +0000
3+++ src/SlingshotView.vala 2014-10-15 22:00:11 +0000
4@@ -179,20 +179,15 @@
5 stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT;
6
7 // Create the "NORMAL_VIEW"
8- var scrolled_normal = new Gtk.ScrolledWindow (null, null);
9- scrolled_normal.set_size_request (calculate_grid_width (), calculate_grid_height ());
10 grid_view = new Widgets.Grid (default_rows, default_columns);
11- scrolled_normal.add_with_viewport (grid_view);
12- stack.add_named (scrolled_normal, "normal");
13+ stack.add_named (grid_view, "normal");
14
15 // Create the "CATEGORY_VIEW"
16 category_view = new Widgets.CategoryView (this);
17- category_view.set_size_request (calculate_grid_width (), calculate_grid_height ());
18 stack.add_named (category_view, "category");
19
20 // Create the "SEARCH_VIEW"
21 search_view = new Widgets.SearchView (this);
22- search_view.set_size_request (calculate_grid_width (), calculate_grid_height ());
23 search_view.start_search.connect ((match, target) => {
24 search.begin (search_entry.text, match, target);
25 });
26@@ -316,7 +311,6 @@
27
28 categories = app_system.get_categories ();
29 apps = app_system.get_apps ();
30-
31 populate_grid_view ();
32 category_view.setup_sidebar ();
33 });
34
35=== modified file 'src/Utils.vala'
36--- src/Utils.vala 2014-10-15 19:18:53 +0000
37+++ src/Utils.vala 2014-10-15 22:00:11 +0000
38@@ -20,15 +20,6 @@
39
40 class Utils : GLib.Object {
41
42- public static Gtk.Widget set_padding (Gtk.Widget widget, int top,
43- int end, int bottom, int start) {
44- widget.set_margin_top (top);
45- widget.set_margin_end (end);
46- widget.set_margin_bottom (bottom);
47- widget.set_margin_start (start);
48- return widget;
49- }
50-
51 public static int sort_apps_by_name (Backend.App a, Backend.App b) {
52 return a.name.collate (b.name);
53 }
54
55=== modified file 'src/Widgets/AppEntry.vala'
56--- src/Widgets/AppEntry.vala 2014-10-14 19:22:11 +0000
57+++ src/Widgets/AppEntry.vala 2014-10-15 22:00:11 +0000
58@@ -17,10 +17,9 @@
59 //
60
61 public class Slingshot.Widgets.AppEntry : Gtk.Button {
62-
63 public Gtk.Label app_label;
64 private Gdk.Pixbuf icon;
65- private Gtk.Box layout;
66+ private new Gtk.Image image;
67
68 public string exec_name;
69 public string app_name;
70@@ -30,8 +29,7 @@
71
72 public signal void app_launched ();
73
74- private double alpha = 1.0;
75- private bool dragging = false; //prevent launching
76+ private bool dragging = false; //prevent launching
77
78 private Backend.App application;
79
80@@ -40,9 +38,6 @@
81 Gtk.drag_source_set (this, Gdk.ModifierType.BUTTON1_MASK, {dnd},
82 Gdk.DragAction.COPY);
83
84- app_paintable = true;
85- set_visual (get_screen ().get_rgba_visual());
86- set_size_request (Pixels.ITEM_SIZE, Pixels.ITEM_SIZE);
87 desktop_id = app.desktop_id;
88 desktop_path = app.desktop_path;
89
90@@ -58,16 +53,25 @@
91 app_label = new Gtk.Label (app_name);
92 app_label.halign = Gtk.Align.CENTER;
93 app_label.justify = Gtk.Justification.CENTER;
94- app_label.set_line_wrap (true); // Need a smarter way
95+ app_label.set_line_wrap (true);
96+ app_label.lines = 2;
97 app_label.set_single_line_mode (false);
98 app_label.set_ellipsize (Pango.EllipsizeMode.END);
99
100- layout = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
101- layout.homogeneous = false;
102-
103- layout.pack_start (app_label, false, true, 0);
104-
105- add (Utils.set_padding (layout, 78, 5, 5, 5));
106+ image = new Gtk.Image.from_pixbuf (icon);
107+ image.icon_size = icon_size;
108+ image.margin_top = 12;
109+
110+ var grid = new Gtk.Grid ();
111+ grid.orientation = Gtk.Orientation.VERTICAL;
112+ grid.row_spacing = 6;
113+ grid.expand = true;
114+ grid.halign = Gtk.Align.CENTER;
115+ grid.add (image);
116+ grid.add (app_label);
117+
118+ add (grid);
119+ set_size_request (Pixels.ITEM_SIZE, Pixels.ITEM_SIZE);
120
121 this.clicked.connect (launch_app);
122
123@@ -77,34 +81,30 @@
124 this.dragging = true;
125 Gtk.drag_set_icon_pixbuf (ctx, icon, 0, 0);
126 });
127+
128 this.drag_end.connect ( () => {
129 this.dragging = false;
130 });
131+
132 this.drag_data_get.connect ( (ctx, sel, info, time) => {
133 sel.set_uris ({File.new_for_path (desktop_path).get_uri ()});
134 });
135
136 app.icon_changed.connect (() => {
137 icon = app.icon;
138- queue_draw ();
139+ image.set_from_pixbuf (icon);
140 });
141
142 }
143
144- protected override bool draw (Cairo.Context cr) {
145- Gtk.Allocation size;
146- get_allocation (out size);
147-
148- base.draw (cr);
149-
150- // Draw icon
151- if (icon != null) {
152- Gdk.cairo_set_source_pixbuf (cr, icon, (icon.width - size.width) / -2.0, 10);
153- cr.paint_with_alpha (alpha);
154- }
155-
156- return true;
157-
158+ public override void get_preferred_width (out int minimum_width, out int natural_width) {
159+ minimum_width = Pixels.ITEM_SIZE;
160+ natural_width = Pixels.ITEM_SIZE;
161+ }
162+
163+ public override void get_preferred_height (out int minimum_height, out int natural_height) {
164+ minimum_height = Pixels.ITEM_SIZE;
165+ natural_height = Pixels.ITEM_SIZE;
166 }
167
168 public void launch_app () {
169
170=== modified file 'src/Widgets/CategoryView.vala'
171--- src/Widgets/CategoryView.vala 2014-10-15 19:18:53 +0000
172+++ src/Widgets/CategoryView.vala 2014-10-15 22:00:11 +0000
173@@ -24,8 +24,6 @@
174 public Widgets.Grid app_view;
175 private SlingshotView view;
176
177- private Gtk.Grid page_switcher;
178-
179 private const string ALL_APPLICATIONS = _("All Applications");
180 private const string NEW_FILTER = _("Create a new Filter");
181 private const string SWITCHBOARD_CATEGORY = "switchboard";
182@@ -35,40 +33,36 @@
183 public Gee.HashMap<int, string> category_ids = new Gee.HashMap<int, string> ();
184
185 public CategoryView (SlingshotView parent) {
186-
187 view = parent;
188-
189 set_visible_window (false);
190- setup_ui ();
191- setup_sidebar ();
192- connect_events ();
193- }
194+ hexpand = true;
195
196- private void setup_ui () {
197 container = new Gtk.Grid ();
198+ container.hexpand = true;
199+ container.orientation = Gtk.Orientation.HORIZONTAL;
200 separator = new Gtk.Separator (Gtk.Orientation.VERTICAL);
201
202+ category_switcher = new Sidebar ();
203+ category_switcher.can_focus = false;
204+
205 app_view = new Widgets.Grid (view.rows, view.columns - 1);
206 app_view.margin_start = Pixels.SIDEBAR_GRID_PADDING;
207
208- container.attach (separator, 1, 0, 1, 2);
209- container.attach (app_view, 2, 0, 1, 1);
210-
211+ container.add (category_switcher);
212+ container.add (separator);
213+ container.add (app_view);
214 add (container);
215
216+ setup_sidebar ();
217+ connect_events ();
218 }
219
220 public void setup_sidebar () {
221-
222- if (category_switcher != null)
223- category_switcher.destroy ();
224-
225- category_switcher = new Sidebar ();
226- category_switcher.can_focus = false;
227-
228+ category_ids.clear ();
229+ category_switcher.clear ();
230+ app_view.set_size_request (-1, -1);
231 // Fill the sidebar
232 int n = 0;
233-
234 foreach (string cat_name in view.apps.keys) {
235 if (cat_name == SWITCHBOARD_CATEGORY)
236 continue;
237@@ -77,20 +71,27 @@
238 category_switcher.add_category (GLib.dgettext ("gnome-menus-3.0", cat_name).dup ());
239 n++;
240 }
241-
242- container.attach (category_switcher, 0, 0, 1, 2);
243+ category_switcher.show_all ();
244+
245+ int minimum_width;
246+ category_switcher.get_preferred_width (out minimum_width, null);
247+
248+ // Because of the different sizes of the column widget, we need to calculate if it will fit.
249+ int removing_columns = (int)((double)minimum_width / (double)Pixels.ITEM_SIZE);
250+ if (minimum_width % Pixels.ITEM_SIZE != 0)
251+ removing_columns++;
252+
253+ int columns = view.columns - removing_columns;
254+ app_view.resize (view.rows, columns);
255+ }
256+
257+ private void connect_events () {
258 category_switcher.selection_changed.connect ((name, nth) => {
259-
260 view.reset_category_focus ();
261 string category = category_ids.get (nth);
262 show_filtered_apps (category);
263 });
264
265- category_switcher.show_all ();
266- }
267-
268- private void connect_events () {
269-
270 category_switcher.selected = 0; //Must be after everything else
271 }
272
273@@ -113,19 +114,4 @@
274
275 }
276
277- public void show_page_switcher (bool show) {
278-
279- if (page_switcher.get_parent () == null)
280- container.attach (page_switcher, 2, 1, 1, 1);
281-
282- if (show) {
283- page_switcher.show_all ();
284- }
285- else
286- page_switcher.hide ();
287-
288- view.search_entry.grab_focus ();
289-
290- }
291-
292 }
293\ No newline at end of file
294
295=== modified file 'src/Widgets/Grid.vala'
296--- src/Widgets/Grid.vala 2014-10-15 19:18:53 +0000
297+++ src/Widgets/Grid.vala 2014-10-15 22:00:11 +0000
298@@ -45,16 +45,14 @@
299 var main_grid = new Gtk.Grid ();
300 main_grid.orientation = Gtk.Orientation.VERTICAL;
301 stack = new Gtk.Stack ();
302+ stack.expand = true;
303 stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT;
304 page_switcher = new Widgets.Switcher ();
305 page_switcher.set_stack (stack);
306 var fake_grid = new Gtk.Grid ();
307- fake_grid.hexpand = true;
308- var stack_layout = new Gtk.Layout ();
309- stack_layout.expand = true;
310- stack_layout.add (stack);
311+ fake_grid.expand = true;
312
313- main_grid.add (stack_layout);
314+ main_grid.add (stack);
315 main_grid.add (fake_grid);
316 main_grid.add (page_switcher);
317 add (main_grid);
318@@ -101,6 +99,16 @@
319 }
320 }
321
322+ public override void get_preferred_width (out int minimum_width, out int natural_width) {
323+ minimum_width = (int)page.columns * Pixels.ITEM_SIZE;
324+ natural_width = minimum_width;
325+ }
326+
327+ public override void get_preferred_height (out int minimum_height, out int natural_height) {
328+ minimum_height = (int)page.rows * Pixels.ITEM_SIZE + ((int)page.rows - 1) * Pixels.ROW_SPACING;
329+ natural_height = minimum_height;
330+ }
331+
332 public void clear () {
333 foreach (Gtk.Grid grid in grids.values) {
334 foreach (Gtk.Widget widget in grid.get_children ()) {
335
336=== modified file 'src/Widgets/Sidebar.vala'
337--- src/Widgets/Sidebar.vala 2014-08-14 20:09:40 +0000
338+++ src/Widgets/Sidebar.vala 2014-10-15 22:00:11 +0000
339@@ -59,12 +59,10 @@
340 set_show_expanders (false);
341 set_level_indentation (8);
342
343- set_size_request (Pixels.SIDEBAR_WIDTH, -1);
344+ hexpand = true;
345 get_style_context ().add_class ("sidebar");
346
347 var cell = new Gtk.CellRendererText ();
348- cell.wrap_mode = Pango.WrapMode.WORD;
349- cell.wrap_width = Pixels.SIDEBAR_WIDTH - 2 * Pixels.PADDING;
350 cell.xpad = Pixels.PADDING;
351
352 insert_column_with_attributes (-1, "Filters", cell, "markup", Columns.TEXT);
353@@ -75,12 +73,13 @@
354 }
355
356 public void add_category (string entry_name) {
357-
358 store.append (out entry_iter, null);
359 store.set (entry_iter, Columns.INT, cat_size - 1, Columns.TEXT, Markup.escape_text (entry_name), -1);
360-
361 expand_all ();
362+ }
363
364+ public void clear () {
365+ store.clear ();
366 }
367
368 public void selection_change () {

Subscribers

People subscribed via source and target branches