Merge lp:~victored/noise/fix-album-view-text-rendering into lp:~elementary-apps/noise/trunk

Proposed by Victor Martinez
Status: Merged
Approved by: Danielle Foré
Approved revision: 1579
Merged at revision: 1580
Proposed branch: lp:~victored/noise/fix-album-view-text-rendering
Merge into: lp:~elementary-apps/noise/trunk
Diff against target: 158 lines (+31/-25)
1 file modified
src/Widgets/FastView/TileView/TileRenderer.vala (+31/-25)
To merge this branch: bzr merge lp:~victored/noise/fix-album-view-text-rendering
Reviewer Review Type Date Requested Status
Danielle Foré Approve
Review via email: mp+216559@code.launchpad.net

Commit message

Left-align album title and artist name in grid view.

Also make sure enough vertical space is allocated in order to display the artist name properly.

Description of the change

Left-align album title and artist name in grid view.

Also fixes a bug that'd cut off the lower part of the artist name.

To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Widgets/FastView/TileView/TileRenderer.vala'
2--- src/Widgets/FastView/TileView/TileRenderer.vala 2013-08-17 04:38:12 +0000
3+++ src/Widgets/FastView/TileView/TileRenderer.vala 2014-04-20 22:12:07 +0000
4@@ -18,15 +18,12 @@
5 private int last_image_width = 0;
6 private int last_image_height = 0;
7 private Granite.Drawing.BufferSurface shadow_buffer;
8- private Pango.Rectangle title_text_logical_rect;
9- private Pango.Rectangle subtitle_text_logical_rect;
10 private Pango.Layout title_text_layout;
11 private Pango.Layout subtitle_text_layout;
12 private Gtk.Border margin;
13 private Gtk.Border padding;
14 private Gtk.Border border;
15
16- [Deprecated (replacement = "Gtk.CellRenderer.get_preferred_size", since = "")]
17 public override void get_size (Gtk.Widget widget, Gdk.Rectangle? cell_area,
18 out int x_offset, out int y_offset,
19 out int width, out int height)
20@@ -44,11 +41,14 @@
21 {
22 update_layout_properties (widget);
23
24+ int x_padding;
25+ get_padding (out x_padding, null);
26+
27 int width = compute_total_image_width ()
28 + margin.left + margin.right
29 + padding.left + padding.right
30 + border.left + border.right
31- + 2 * (int) xpad;
32+ + 2 * x_padding;
33
34 minimum_size = natural_size = width;
35 }
36@@ -59,13 +59,20 @@
37 {
38 update_layout_properties (widget);
39
40+ int y_padding;
41+ get_padding (null, out y_padding);
42+
43+ int subtitle_height, title_height;
44+ title_text_layout.get_pixel_size (null, out title_height);
45+ subtitle_text_layout.get_pixel_size (null, out subtitle_height);
46+
47 int height = compute_total_image_height ()
48- + title_text_logical_rect.height
49- + subtitle_text_logical_rect.height
50+ + title_height + subtitle_height
51 + margin.top + margin.bottom
52 + padding.top + padding.bottom
53 + border.top + border.bottom
54- + 2 * (int) ypad;
55+ + 2 * y_padding
56+ + IMAGE_SHADOW_RADIUS;
57
58 minimum_height = natural_height = height;
59 }
60@@ -97,12 +104,12 @@
61 width -= border.left + border.right + padding.left + padding.right;
62 height -= border.top + border.bottom + padding.top + padding.bottom;
63
64- render_image (ctx, cr, x, ref y, width, flags);
65+ render_image (ctx, cr, ref x, ref y, width, flags);
66 render_title (ctx, cr, x, ref y, width);
67 render_subtitle (ctx, cr, x, y, width);
68 }
69
70- private void render_image (Gtk.StyleContext ctx, Cairo.Context cr, int x,
71+ private void render_image (Gtk.StyleContext ctx, Cairo.Context cr, ref int x,
72 ref int y, int width, Gtk.CellRendererState flags)
73 {
74 int image_width = compute_total_image_width ();
75@@ -139,37 +146,38 @@
76 ctx.render_icon (cr, image, x + offset, y + offset);
77
78 if (should_draw_highlight (flags)) {
79+ ctx.save ();
80 ctx.add_class (Gtk.STYLE_CLASS_IMAGE);
81 ctx.render_frame (cr, x + offset - border.left,
82 y + offset - border.top,
83 pixbuf.width + border.left + border.right,
84 pixbuf.height + border.top + border.bottom);
85+ ctx.restore ();
86 }
87
88 y += image_height;
89+
90+ // move x to the start of the actual image
91+ x += (image_width - image.width) / 2;
92 }
93
94 private void render_title (Gtk.StyleContext ctx, Cairo.Context cr, int x,
95 ref int y, int width)
96 {
97- // Center title layout horizontally
98- int offset = (width - title_text_logical_rect.width) / 2;
99- x += title_text_logical_rect.x + int.max (0, offset);
100-
101+ ctx.save ();
102 ctx.add_class ("title-text");
103 ctx.render_layout (cr, x, y, title_text_layout);
104- ctx.remove_class ("title-text");
105-
106- y += title_text_logical_rect.height;
107+ ctx.restore ();
108+
109+ int title_height;
110+ title_text_layout.get_pixel_size (null, out title_height);
111+
112+ y += title_height;
113 }
114
115 private void render_subtitle (Gtk.StyleContext ctx, Cairo.Context cr, int x,
116 int y, int width)
117 {
118- // Center title layout horizontally
119- int offset = (width - subtitle_text_logical_rect.width) / 2;
120- x += subtitle_text_logical_rect.x + int.max (0, offset);
121-
122 ctx.render_layout (cr, x, y, subtitle_text_layout);
123 }
124
125@@ -182,6 +190,7 @@
126 margin = ctx.get_margin (state);
127 padding = ctx.get_padding (state);
128 border = ctx.get_border (state);
129+ ctx.restore ();
130
131 subtitle_text_layout = widget.create_pango_layout (subtitle);
132 unowned Pango.FontDescription font_description;
133@@ -192,6 +201,7 @@
134 int text_width = pixbuf.width * Pango.SCALE;
135 subtitle_text_layout.set_width (text_width);
136
137+ ctx.save ();
138 ctx.add_class ("title-text");
139 title_text_layout = widget.create_pango_layout (title);
140 ctx.get (state, Gtk.STYLE_PROPERTY_FONT, out font_description);
141@@ -200,10 +210,6 @@
142 title_text_layout.set_ellipsize (Pango.EllipsizeMode.END);
143 title_text_layout.set_alignment (Pango.Alignment.LEFT);
144 ctx.restore ();
145-
146- Pango.Rectangle ink_rect;
147- title_text_layout.get_pixel_extents (out ink_rect, out title_text_logical_rect);
148- subtitle_text_layout.get_pixel_extents (out ink_rect, out subtitle_text_logical_rect);
149 }
150
151 private int compute_total_image_width () {
152@@ -231,4 +237,4 @@
153 ImageUtils.shift_colors (brightened, BRIGHTEN_SHIFT, BRIGHTEN_SHIFT, BRIGHTEN_SHIFT, 0);
154 return brightened;
155 }
156-}
157+}
158\ No newline at end of file

Subscribers

People subscribed via source and target branches