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
=== modified file 'src/SlingshotView.vala'
--- src/SlingshotView.vala 2014-10-15 19:18:53 +0000
+++ src/SlingshotView.vala 2014-10-15 22:00:11 +0000
@@ -179,20 +179,15 @@
179 stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT;179 stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT;
180180
181 // Create the "NORMAL_VIEW"181 // Create the "NORMAL_VIEW"
182 var scrolled_normal = new Gtk.ScrolledWindow (null, null);
183 scrolled_normal.set_size_request (calculate_grid_width (), calculate_grid_height ());
184 grid_view = new Widgets.Grid (default_rows, default_columns);182 grid_view = new Widgets.Grid (default_rows, default_columns);
185 scrolled_normal.add_with_viewport (grid_view);183 stack.add_named (grid_view, "normal");
186 stack.add_named (scrolled_normal, "normal");
187184
188 // Create the "CATEGORY_VIEW"185 // Create the "CATEGORY_VIEW"
189 category_view = new Widgets.CategoryView (this);186 category_view = new Widgets.CategoryView (this);
190 category_view.set_size_request (calculate_grid_width (), calculate_grid_height ());
191 stack.add_named (category_view, "category");187 stack.add_named (category_view, "category");
192188
193 // Create the "SEARCH_VIEW"189 // Create the "SEARCH_VIEW"
194 search_view = new Widgets.SearchView (this);190 search_view = new Widgets.SearchView (this);
195 search_view.set_size_request (calculate_grid_width (), calculate_grid_height ());
196 search_view.start_search.connect ((match, target) => {191 search_view.start_search.connect ((match, target) => {
197 search.begin (search_entry.text, match, target);192 search.begin (search_entry.text, match, target);
198 });193 });
@@ -316,7 +311,6 @@
316311
317 categories = app_system.get_categories ();312 categories = app_system.get_categories ();
318 apps = app_system.get_apps ();313 apps = app_system.get_apps ();
319
320 populate_grid_view ();314 populate_grid_view ();
321 category_view.setup_sidebar ();315 category_view.setup_sidebar ();
322 });316 });
323317
=== modified file 'src/Utils.vala'
--- src/Utils.vala 2014-10-15 19:18:53 +0000
+++ src/Utils.vala 2014-10-15 22:00:11 +0000
@@ -20,15 +20,6 @@
2020
21 class Utils : GLib.Object {21 class Utils : GLib.Object {
2222
23 public static Gtk.Widget set_padding (Gtk.Widget widget, int top,
24 int end, int bottom, int start) {
25 widget.set_margin_top (top);
26 widget.set_margin_end (end);
27 widget.set_margin_bottom (bottom);
28 widget.set_margin_start (start);
29 return widget;
30 }
31
32 public static int sort_apps_by_name (Backend.App a, Backend.App b) {23 public static int sort_apps_by_name (Backend.App a, Backend.App b) {
33 return a.name.collate (b.name);24 return a.name.collate (b.name);
34 }25 }
3526
=== modified file 'src/Widgets/AppEntry.vala'
--- src/Widgets/AppEntry.vala 2014-10-14 19:22:11 +0000
+++ src/Widgets/AppEntry.vala 2014-10-15 22:00:11 +0000
@@ -17,10 +17,9 @@
17//17//
1818
19public class Slingshot.Widgets.AppEntry : Gtk.Button {19public class Slingshot.Widgets.AppEntry : Gtk.Button {
20
21 public Gtk.Label app_label;20 public Gtk.Label app_label;
22 private Gdk.Pixbuf icon;21 private Gdk.Pixbuf icon;
23 private Gtk.Box layout;22 private new Gtk.Image image;
2423
25 public string exec_name;24 public string exec_name;
26 public string app_name;25 public string app_name;
@@ -30,8 +29,7 @@
3029
31 public signal void app_launched ();30 public signal void app_launched ();
3231
33 private double alpha = 1.0;32 private bool dragging = false; //prevent launching
34 private bool dragging = false; //prevent launching
3533
36 private Backend.App application;34 private Backend.App application;
3735
@@ -40,9 +38,6 @@
40 Gtk.drag_source_set (this, Gdk.ModifierType.BUTTON1_MASK, {dnd},38 Gtk.drag_source_set (this, Gdk.ModifierType.BUTTON1_MASK, {dnd},
41 Gdk.DragAction.COPY);39 Gdk.DragAction.COPY);
4240
43 app_paintable = true;
44 set_visual (get_screen ().get_rgba_visual());
45 set_size_request (Pixels.ITEM_SIZE, Pixels.ITEM_SIZE);
46 desktop_id = app.desktop_id;41 desktop_id = app.desktop_id;
47 desktop_path = app.desktop_path;42 desktop_path = app.desktop_path;
4843
@@ -58,16 +53,25 @@
58 app_label = new Gtk.Label (app_name);53 app_label = new Gtk.Label (app_name);
59 app_label.halign = Gtk.Align.CENTER;54 app_label.halign = Gtk.Align.CENTER;
60 app_label.justify = Gtk.Justification.CENTER;55 app_label.justify = Gtk.Justification.CENTER;
61 app_label.set_line_wrap (true); // Need a smarter way56 app_label.set_line_wrap (true);
57 app_label.lines = 2;
62 app_label.set_single_line_mode (false);58 app_label.set_single_line_mode (false);
63 app_label.set_ellipsize (Pango.EllipsizeMode.END);59 app_label.set_ellipsize (Pango.EllipsizeMode.END);
6460
65 layout = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);61 image = new Gtk.Image.from_pixbuf (icon);
66 layout.homogeneous = false;62 image.icon_size = icon_size;
6763 image.margin_top = 12;
68 layout.pack_start (app_label, false, true, 0);64
6965 var grid = new Gtk.Grid ();
70 add (Utils.set_padding (layout, 78, 5, 5, 5));66 grid.orientation = Gtk.Orientation.VERTICAL;
67 grid.row_spacing = 6;
68 grid.expand = true;
69 grid.halign = Gtk.Align.CENTER;
70 grid.add (image);
71 grid.add (app_label);
72
73 add (grid);
74 set_size_request (Pixels.ITEM_SIZE, Pixels.ITEM_SIZE);
7175
72 this.clicked.connect (launch_app);76 this.clicked.connect (launch_app);
7377
@@ -77,34 +81,30 @@
77 this.dragging = true;81 this.dragging = true;
78 Gtk.drag_set_icon_pixbuf (ctx, icon, 0, 0);82 Gtk.drag_set_icon_pixbuf (ctx, icon, 0, 0);
79 });83 });
84
80 this.drag_end.connect ( () => {85 this.drag_end.connect ( () => {
81 this.dragging = false;86 this.dragging = false;
82 });87 });
88
83 this.drag_data_get.connect ( (ctx, sel, info, time) => {89 this.drag_data_get.connect ( (ctx, sel, info, time) => {
84 sel.set_uris ({File.new_for_path (desktop_path).get_uri ()});90 sel.set_uris ({File.new_for_path (desktop_path).get_uri ()});
85 });91 });
8692
87 app.icon_changed.connect (() => {93 app.icon_changed.connect (() => {
88 icon = app.icon;94 icon = app.icon;
89 queue_draw ();95 image.set_from_pixbuf (icon);
90 });96 });
9197
92 }98 }
9399
94 protected override bool draw (Cairo.Context cr) {100 public override void get_preferred_width (out int minimum_width, out int natural_width) {
95 Gtk.Allocation size;101 minimum_width = Pixels.ITEM_SIZE;
96 get_allocation (out size);102 natural_width = Pixels.ITEM_SIZE;
97103 }
98 base.draw (cr);104
99105 public override void get_preferred_height (out int minimum_height, out int natural_height) {
100 // Draw icon106 minimum_height = Pixels.ITEM_SIZE;
101 if (icon != null) {107 natural_height = Pixels.ITEM_SIZE;
102 Gdk.cairo_set_source_pixbuf (cr, icon, (icon.width - size.width) / -2.0, 10);
103 cr.paint_with_alpha (alpha);
104 }
105
106 return true;
107
108 }108 }
109109
110 public void launch_app () {110 public void launch_app () {
111111
=== modified file 'src/Widgets/CategoryView.vala'
--- src/Widgets/CategoryView.vala 2014-10-15 19:18:53 +0000
+++ src/Widgets/CategoryView.vala 2014-10-15 22:00:11 +0000
@@ -24,8 +24,6 @@
24 public Widgets.Grid app_view;24 public Widgets.Grid app_view;
25 private SlingshotView view;25 private SlingshotView view;
2626
27 private Gtk.Grid page_switcher;
28
29 private const string ALL_APPLICATIONS = _("All Applications");27 private const string ALL_APPLICATIONS = _("All Applications");
30 private const string NEW_FILTER = _("Create a new Filter");28 private const string NEW_FILTER = _("Create a new Filter");
31 private const string SWITCHBOARD_CATEGORY = "switchboard";29 private const string SWITCHBOARD_CATEGORY = "switchboard";
@@ -35,40 +33,36 @@
35 public Gee.HashMap<int, string> category_ids = new Gee.HashMap<int, string> ();33 public Gee.HashMap<int, string> category_ids = new Gee.HashMap<int, string> ();
3634
37 public CategoryView (SlingshotView parent) {35 public CategoryView (SlingshotView parent) {
38
39 view = parent;36 view = parent;
40
41 set_visible_window (false);37 set_visible_window (false);
42 setup_ui ();38 hexpand = true;
43 setup_sidebar ();
44 connect_events ();
45 }
4639
47 private void setup_ui () {
48 container = new Gtk.Grid ();40 container = new Gtk.Grid ();
41 container.hexpand = true;
42 container.orientation = Gtk.Orientation.HORIZONTAL;
49 separator = new Gtk.Separator (Gtk.Orientation.VERTICAL);43 separator = new Gtk.Separator (Gtk.Orientation.VERTICAL);
5044
45 category_switcher = new Sidebar ();
46 category_switcher.can_focus = false;
47
51 app_view = new Widgets.Grid (view.rows, view.columns - 1);48 app_view = new Widgets.Grid (view.rows, view.columns - 1);
52 app_view.margin_start = Pixels.SIDEBAR_GRID_PADDING;49 app_view.margin_start = Pixels.SIDEBAR_GRID_PADDING;
5350
54 container.attach (separator, 1, 0, 1, 2);51 container.add (category_switcher);
55 container.attach (app_view, 2, 0, 1, 1);52 container.add (separator);
5653 container.add (app_view);
57 add (container);54 add (container);
5855
56 setup_sidebar ();
57 connect_events ();
59 }58 }
6059
61 public void setup_sidebar () {60 public void setup_sidebar () {
6261 category_ids.clear ();
63 if (category_switcher != null)62 category_switcher.clear ();
64 category_switcher.destroy ();63 app_view.set_size_request (-1, -1);
65
66 category_switcher = new Sidebar ();
67 category_switcher.can_focus = false;
68
69 // Fill the sidebar64 // Fill the sidebar
70 int n = 0;65 int n = 0;
71
72 foreach (string cat_name in view.apps.keys) {66 foreach (string cat_name in view.apps.keys) {
73 if (cat_name == SWITCHBOARD_CATEGORY)67 if (cat_name == SWITCHBOARD_CATEGORY)
74 continue;68 continue;
@@ -77,20 +71,27 @@
77 category_switcher.add_category (GLib.dgettext ("gnome-menus-3.0", cat_name).dup ());71 category_switcher.add_category (GLib.dgettext ("gnome-menus-3.0", cat_name).dup ());
78 n++;72 n++;
79 }73 }
8074 category_switcher.show_all ();
81 container.attach (category_switcher, 0, 0, 1, 2);75
76 int minimum_width;
77 category_switcher.get_preferred_width (out minimum_width, null);
78
79 // Because of the different sizes of the column widget, we need to calculate if it will fit.
80 int removing_columns = (int)((double)minimum_width / (double)Pixels.ITEM_SIZE);
81 if (minimum_width % Pixels.ITEM_SIZE != 0)
82 removing_columns++;
83
84 int columns = view.columns - removing_columns;
85 app_view.resize (view.rows, columns);
86 }
87
88 private void connect_events () {
82 category_switcher.selection_changed.connect ((name, nth) => {89 category_switcher.selection_changed.connect ((name, nth) => {
83
84 view.reset_category_focus ();90 view.reset_category_focus ();
85 string category = category_ids.get (nth);91 string category = category_ids.get (nth);
86 show_filtered_apps (category);92 show_filtered_apps (category);
87 });93 });
8894
89 category_switcher.show_all ();
90 }
91
92 private void connect_events () {
93
94 category_switcher.selected = 0; //Must be after everything else95 category_switcher.selected = 0; //Must be after everything else
95 }96 }
9697
@@ -113,19 +114,4 @@
113114
114 }115 }
115116
116 public void show_page_switcher (bool show) {
117
118 if (page_switcher.get_parent () == null)
119 container.attach (page_switcher, 2, 1, 1, 1);
120
121 if (show) {
122 page_switcher.show_all ();
123 }
124 else
125 page_switcher.hide ();
126
127 view.search_entry.grab_focus ();
128
129 }
130
131}117}
132\ No newline at end of file118\ No newline at end of file
133119
=== modified file 'src/Widgets/Grid.vala'
--- src/Widgets/Grid.vala 2014-10-15 19:18:53 +0000
+++ src/Widgets/Grid.vala 2014-10-15 22:00:11 +0000
@@ -45,16 +45,14 @@
45 var main_grid = new Gtk.Grid ();45 var main_grid = new Gtk.Grid ();
46 main_grid.orientation = Gtk.Orientation.VERTICAL;46 main_grid.orientation = Gtk.Orientation.VERTICAL;
47 stack = new Gtk.Stack ();47 stack = new Gtk.Stack ();
48 stack.expand = true;
48 stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT;49 stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT;
49 page_switcher = new Widgets.Switcher ();50 page_switcher = new Widgets.Switcher ();
50 page_switcher.set_stack (stack);51 page_switcher.set_stack (stack);
51 var fake_grid = new Gtk.Grid ();52 var fake_grid = new Gtk.Grid ();
52 fake_grid.hexpand = true;53 fake_grid.expand = true;
53 var stack_layout = new Gtk.Layout ();
54 stack_layout.expand = true;
55 stack_layout.add (stack);
5654
57 main_grid.add (stack_layout);55 main_grid.add (stack);
58 main_grid.add (fake_grid);56 main_grid.add (fake_grid);
59 main_grid.add (page_switcher);57 main_grid.add (page_switcher);
60 add (main_grid);58 add (main_grid);
@@ -101,6 +99,16 @@
101 }99 }
102 }100 }
103101
102 public override void get_preferred_width (out int minimum_width, out int natural_width) {
103 minimum_width = (int)page.columns * Pixels.ITEM_SIZE;
104 natural_width = minimum_width;
105 }
106
107 public override void get_preferred_height (out int minimum_height, out int natural_height) {
108 minimum_height = (int)page.rows * Pixels.ITEM_SIZE + ((int)page.rows - 1) * Pixels.ROW_SPACING;
109 natural_height = minimum_height;
110 }
111
104 public void clear () {112 public void clear () {
105 foreach (Gtk.Grid grid in grids.values) {113 foreach (Gtk.Grid grid in grids.values) {
106 foreach (Gtk.Widget widget in grid.get_children ()) {114 foreach (Gtk.Widget widget in grid.get_children ()) {
107115
=== modified file 'src/Widgets/Sidebar.vala'
--- src/Widgets/Sidebar.vala 2014-08-14 20:09:40 +0000
+++ src/Widgets/Sidebar.vala 2014-10-15 22:00:11 +0000
@@ -59,12 +59,10 @@
59 set_show_expanders (false);59 set_show_expanders (false);
60 set_level_indentation (8);60 set_level_indentation (8);
6161
62 set_size_request (Pixels.SIDEBAR_WIDTH, -1);62 hexpand = true;
63 get_style_context ().add_class ("sidebar");63 get_style_context ().add_class ("sidebar");
6464
65 var cell = new Gtk.CellRendererText ();65 var cell = new Gtk.CellRendererText ();
66 cell.wrap_mode = Pango.WrapMode.WORD;
67 cell.wrap_width = Pixels.SIDEBAR_WIDTH - 2 * Pixels.PADDING;
68 cell.xpad = Pixels.PADDING;66 cell.xpad = Pixels.PADDING;
6967
70 insert_column_with_attributes (-1, "Filters", cell, "markup", Columns.TEXT);68 insert_column_with_attributes (-1, "Filters", cell, "markup", Columns.TEXT);
@@ -75,12 +73,13 @@
75 }73 }
7674
77 public void add_category (string entry_name) {75 public void add_category (string entry_name) {
78
79 store.append (out entry_iter, null);76 store.append (out entry_iter, null);
80 store.set (entry_iter, Columns.INT, cat_size - 1, Columns.TEXT, Markup.escape_text (entry_name), -1);77 store.set (entry_iter, Columns.INT, cat_size - 1, Columns.TEXT, Markup.escape_text (entry_name), -1);
81
82 expand_all ();78 expand_all ();
79 }
8380
81 public void clear () {
82 store.clear ();
84 }83 }
8584
86 public void selection_change () {85 public void selection_change () {

Subscribers

People subscribed via source and target branches