Merge lp:~unity-team/unity/fix-long-section-names into lp:unity

Proposed by Neil J. Patel
Status: Merged
Merged at revision: 567
Proposed branch: lp:~unity-team/unity/fix-long-section-names
Merge into: lp:unity
Diff against target: 281 lines (+143/-9)
3 files modified
unity-private/places/places-place-search-bar.vala (+60/-3)
unity-private/places/places-place-search-entry.vala (+25/-4)
unity-private/places/places-place-search-sections-bar.vala (+58/-2)
To merge this branch: bzr merge lp:~unity-team/unity/fix-long-section-names
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve
Review via email: mp+37236@code.launchpad.net

Description of the change

This is a very horrible way of making sure we can fit all the sections on the screen. It works around a bunch of bugs in ClutterText wrt size-negotiation with ellipsis.

The main thing that happens is:

If the sections bar is too long for the screen when a place is activated, we figure that out in the allocation cycle and then request the section to go into small mode (as well as asking the search entry to become smaller too). At this point, the section will enable ellipsising on it's sections, and the bar will repack the sections to be expand=true, so we'll try and use as much space as possible. The sections themselves need to store their width when they were allowed to show all the text, so they have a reference point (as they cannot get this ever again when they need it).

When we switch places, we need to create a new sections bar to undo the damage we did and then go through the cycle again.

If i had more time, and I'll do this for SRU, I would have staged the "make things fit" into two allocation cycles:

1. First decrease the entry width and, if sections still don't fit,
2. Make sections go into small mode

There is a slight visual flicker when this happens first time, but I can try and fix that for SRU too.

To post a comment you must log in.
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Code looks ok (in light of the comments above) and I can confirm it works. In fact I don't see the flickering :-)

Approved!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'unity-private/places/places-place-search-bar.vala'
2--- unity-private/places/places-place-search-bar.vala 2010-09-20 15:53:08 +0000
3+++ unity-private/places/places-place-search-bar.vala 2010-10-01 10:58:40 +0000
4@@ -32,6 +32,7 @@
5 private PlaceSearchNavigation navigation;
6 public PlaceSearchEntry entry;
7 public PlaceSearchSectionsBar sections;
8+ public Clutter.Rectangle space;
9 public PlaceSearchExtraAction extra_action;
10
11 private bool _search_fail = false;
12@@ -80,7 +81,7 @@
13 sections.show ();
14
15 /* We need a dummy to be able to space the action label */
16- var space = new Clutter.Rectangle.with_color ({255, 255, 255, 0});
17+ space = new Clutter.Rectangle.with_color ({255, 255, 255, 0});
18 pack (space, true, true);
19 space.show ();
20
21@@ -111,6 +112,27 @@
22 return entry.text.text;
23 }
24
25+ private bool update_broken_views ()
26+ {
27+ sections.small_mode = true;
28+ entry.small_mode = true;
29+
30+ sections.ref ();
31+ extra_action.ref ();
32+
33+ remove_actor (sections);
34+ remove_actor (space);
35+ remove_actor (extra_action);
36+
37+ pack (sections, true, true);
38+ pack (extra_action, false, true);
39+
40+ extra_action.unref ();
41+ sections.unref ();
42+
43+ return false;
44+ }
45+
46 private override void allocate (Clutter.ActorBox box,
47 Clutter.AllocationFlags flags)
48 {
49@@ -119,6 +141,16 @@
50
51 base.allocate (box, flags);
52
53+ float children_width = navigation.width + SPACING +
54+ entry.width + SPACING +
55+ sections.width + SPACING;
56+ if (box.x2 - box.x1 < children_width)
57+ {
58+ /* Basically sections is too big */
59+ if (sections.small_mode == false)
60+ Timeout.add (0, update_broken_views);
61+ }
62+
63 if (entry.x != ex || entry.width != ewidth)
64 {
65 /* After discussion with upstream Clutter guys, it seems like the
66@@ -139,6 +171,7 @@
67 float mheight, nheight;
68
69 entry.get_preferred_height (RANDOM_TEXT_WIDTH, out mheight, out nheight);
70+
71 min_height = mheight + SPACING * 3;
72 nat_height = nheight + SPACING * 3;
73 }
74@@ -181,6 +214,27 @@
75 */
76 public void set_active_entry_view (PlaceEntry entry, int x, uint section=0)
77 {
78+ if (sections.small_mode)
79+ {
80+ extra_action.ref ();
81+
82+ remove_actor (sections);
83+ remove_actor (extra_action);
84+
85+ sections = new PlaceSearchSectionsBar ();
86+ pack (sections, false, true);
87+ sections.show ();
88+
89+ /* We need a dummy to be able to space the action label */
90+ space = new Clutter.Rectangle.with_color ({255, 255, 255, 0});
91+ pack (space, true, true);
92+ space.show ();
93+
94+ pack (extra_action, false, true);
95+
96+ extra_action.unref ();
97+ }
98+
99 active_entry = entry;
100 bg.entry_position = x;
101 sections.set_active_entry (entry);
102@@ -400,8 +454,11 @@
103 /* Cut out the search entry */
104 cr.set_operator (Cairo.Operator.CLEAR);
105
106- x = (int)search_entry.x;
107- y = (int)(search_entry.y) - 1;
108+ if (search_entry.x < 1.0f)
109+ x += width + 12;
110+ else
111+ x = (int)search_entry.x;
112+ //y = (int)(search_entry.y) - 1;
113 width = x + (int)search_entry.width;
114 height = y + (int)search_entry.height +1;
115
116
117=== modified file 'unity-private/places/places-place-search-entry.vala'
118--- unity-private/places/places-place-search-entry.vala 2010-09-02 19:19:10 +0000
119+++ unity-private/places/places-place-search-entry.vala 2010-10-01 10:58:40 +0000
120@@ -37,6 +37,18 @@
121 public Ctk.Text text;
122 public CairoCanvas right_icon;
123
124+ public bool _small_mode = false;
125+ public bool small_mode {
126+ get {
127+ return _small_mode;;
128+ }
129+ set {
130+ _small_mode = value;
131+ hint_text.set_markup ("<i>" + _("Search") + "</i>");
132+ queue_relayout ();
133+ }
134+ }
135+
136 private uint _cursor_blink_count = 0;
137
138 private bool upward = true;
139@@ -88,7 +100,8 @@
140 {
141 Object (orientation:Ctk.Orientation.HORIZONTAL,
142 homogeneous:false,
143- spacing:0);
144+ spacing:0,
145+ small_mode:false);
146 }
147
148 ~PlaceSearchEntry ()
149@@ -157,8 +170,16 @@
150 out float nat_width)
151 {
152 /* FIXME: Make these dependant on size of screen & font */
153- min_width = 270.0f;
154- nat_width = 270.0f;
155+ if (small_mode)
156+ {
157+ min_width = 135.0f;
158+ nat_width = 135.0f;
159+ }
160+ else
161+ {
162+ min_width = 270.0f;
163+ nat_width = 270.0f;
164+ }
165 }
166
167 private void on_text_changed ()
168@@ -253,7 +274,7 @@
169 {
170 string name = "";
171
172- if (entry is PlaceHomeEntry == false)
173+ if (entry is PlaceHomeEntry == false && _small_mode == false)
174 name = entry.name;
175
176 hint_text.set_markup ("<i>" +
177
178=== modified file 'unity-private/places/places-place-search-sections-bar.vala'
179--- unity-private/places/places-place-search-sections-bar.vala 2010-09-22 09:40:10 +0000
180+++ unity-private/places/places-place-search-sections-bar.vala 2010-10-01 10:58:40 +0000
181@@ -45,6 +45,41 @@
182 }
183 }
184
185+ private bool _small_mode = false;
186+ public bool small_mode {
187+ get { return _small_mode; }
188+ set {
189+ if (_small_mode != value)
190+ {
191+ _small_mode = value;
192+
193+ if (_small_mode)
194+ {
195+ padding = { 0.0f, 0.0f, 0.0f, 0.0f };
196+
197+ var secs = get_children ();
198+ foreach (Clutter.Actor s in secs)
199+ {
200+ (s as Section).full_alloc_size = s.width;
201+ (s as Section).text.ellipsize = Pango.EllipsizeMode.END;
202+ }
203+ }
204+ else
205+ {
206+ padding = { 0.0f, PADDING, 0.0f, PADDING };
207+ var secs = get_children ();
208+ foreach (Clutter.Actor s in secs)
209+ {
210+ (s as Section).text.ellipsize = Pango.EllipsizeMode.NONE;
211+ s.queue_relayout ();
212+ }
213+ }
214+
215+ bg.update ();
216+ }
217+ }
218+ }
219+
220 private PlaceEntry? active_entry = null;
221 private Section? active_section = null;
222 public uint active_section_n = 0;
223@@ -123,7 +158,6 @@
224 (actor as Section).dirty = true;
225 }
226
227-
228 active_entry = entry;
229 var model = active_entry.sections_model;
230 sections_model = model;
231@@ -173,6 +207,8 @@
232 model.row_added.connect (on_section_added);
233 model.row_changed.connect (on_section_changed);
234 model.row_removed.connect (on_section_removed);
235+
236+ bg.update ();
237 }
238
239 private static int sort_sections (Section asec, Section bsec)
240@@ -184,7 +220,9 @@
241 private void on_section_added (Dee.Model model, Dee.ModelIter iter)
242 {
243 var section = new Section (model, iter);
244- pack (section, false, true);
245+ if (small_mode)
246+ section.text.ellipsize = Pango.EllipsizeMode.END;
247+ pack (section, false, true);
248 section.show ();
249
250 section.button_release_event.connect (on_section_clicked);
251@@ -414,6 +452,8 @@
252 private float _last_width = 0.0f;
253 private float _resize_width = 0.0f;
254
255+ public float full_alloc_size = 0.0f;
256+
257 public Section (Dee.Model model, Dee.ModelIter iter)
258 {
259 Object (reactive:true,
260@@ -465,6 +505,22 @@
261
262 base.get_preferred_width (for_height, out mw, out nw);
263
264+ if (text.ellipsize != Pango.EllipsizeMode.NONE)
265+ {
266+ if (full_alloc_size < 10.0f || full_alloc_size > 75.0f)
267+ {
268+ min_width = 75.0f;
269+ nat_width = 75.0f;
270+ }
271+ else
272+ {
273+ text.ellipsize = Pango.EllipsizeMode.NONE;
274+ min_width = full_alloc_size;
275+ nat_width = full_alloc_size;
276+ }
277+ return;
278+ }
279+
280 min_width = (mw + padding.right + padding.left) * _destroy_factor;
281 nat_width = (nw + padding.right + padding.left) * _destroy_factor;
282