Merge lp:~wingpanel-devs/wingpanel/icon-buttons into lp:~wingpanel-devs/wingpanel/trunk

Proposed by Djax
Status: Merged
Approved by: Marcus Wichelmann
Approved revision: 100
Merged at revision: 99
Proposed branch: lp:~wingpanel-devs/wingpanel/icon-buttons
Merge into: lp:~wingpanel-devs/wingpanel/trunk
Diff against target: 83 lines (+21/-17)
1 file modified
lib/Widgets/Button.vala (+21/-17)
To merge this branch: bzr merge lp:~wingpanel-devs/wingpanel/icon-buttons
Reviewer Review Type Date Requested Status
Marcus Wichelmann (community) Approve
Review via email: mp+282128@code.launchpad.net

Commit message

Add methods to to set the image on the button with icon and not only pixbufs.
Also switch the constructor to it since it is recommended to get proper hidpi support.

Description of the change

Add methods to to set the image on the button with icon and not only pixbufs.
Also switch the constructor to it since it is recommended to get proper hidpi support.

To post a comment you must log in.
Revision history for this message
Marcus Wichelmann (l-admin-3) wrote :

I've added two comments.

Needs testing if it works and breaks other indicators.

review: Needs Fixing (code)
100. By Djax

minor variable name change

Revision history for this message
Djax (parnold-x) wrote :

changed the minor things.
Afaik only the keyboard indicator used the pixbuf thing.
Did a branch for it. https://code.launchpad.net/~wingpanel-devs/wingpanel-indicator-keyboard/adapt_to_lib_change

Revision history for this message
Marcus Wichelmann (l-admin-3) wrote :

Nice work! :-)

review: Approve (code)
Revision history for this message
Marcus Wichelmann (l-admin-3) wrote :

works.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/Widgets/Button.vala'
2--- lib/Widgets/Button.vala 2015-10-20 14:07:07 +0000
3+++ lib/Widgets/Button.vala 2016-01-16 10:47:51 +0000
4@@ -22,28 +22,24 @@
5
6 private Gtk.Image button_image;
7
8- public Button (string caption, Gdk.Pixbuf? pixbuf = null) {
9+ public Button (string caption, string? icon_name = null) {
10 var content_widget = this.get_content_widget ();
11
12- button_image = create_image_for_pixbuf (pixbuf);
13+ button_image = create_image_for_icon_name (icon_name);
14 button_label = create_label_for_caption (caption);
15
16 content_widget.attach (button_image, 0, 0, 1, 1);
17 content_widget.attach (button_label, 1, 0, 1, 1);
18-
19- connect_signals ();
20 }
21
22- public Button.with_mnemonic (string caption, Gdk.Pixbuf? pixbuf = null) {
23+ public Button.with_mnemonic (string caption, string? icon_name = null) {
24 var content_widget = this.get_content_widget ();
25
26- button_image = create_image_for_pixbuf (pixbuf);
27+ button_image = create_image_for_icon_name (icon_name);
28 button_label = create_label_for_caption (caption, true);
29
30 content_widget.attach (button_image, 0, 0, 1, 1);
31 content_widget.attach (button_label, 1, 0, 1, 1);
32-
33- connect_signals ();
34 }
35
36 public void set_caption (string caption) {
37@@ -54,8 +50,18 @@
38 return button_label.get_label ();
39 }
40
41+ public void set_icon (string? icon_name) {
42+ if (icon_name == null) {
43+ button_image.visible = false;
44+ } else {
45+ button_image.set_from_icon_name (icon_name, Gtk.IconSize.BUTTON);
46+ button_image.visible = true;
47+ }
48+ }
49+
50 public void set_pixbuf (Gdk.Pixbuf? pixbuf) {
51 button_image.set_from_pixbuf (pixbuf);
52+ button_image.visible = pixbuf != null;
53 }
54
55 public Gdk.Pixbuf? get_pixbuf () {
56@@ -84,19 +90,17 @@
57 return label_widget;
58 }
59
60- private Gtk.Image create_image_for_pixbuf (Gdk.Pixbuf? pixbuf) {
61+ private Gtk.Image create_image_for_icon_name (string? icon_name) {
62 var image = new Gtk.Image ();
63- image.pixbuf = pixbuf;
64 image.margin_start = 6;
65 image.no_show_all = true;
66- image.visible = pixbuf != null;
67+ if (icon_name != null) {
68+ image.set_from_icon_name (icon_name, Gtk.IconSize.BUTTON);
69+ image.visible = true;
70+ } else {
71+ image.visible = false;
72+ }
73
74 return image;
75 }
76-
77- private void connect_signals () {
78- button_image.notify["pixbuf"].connect (() => {
79- button_image.visible = button_image.get_pixbuf () != null;
80- });
81- }
82 }
83\ No newline at end of file

Subscribers

People subscribed via source and target branches

to all changes: