@@ -24,42 +24,54 @@ public abstract class Dock.BaseIconGroup : ContainerItem {
2424 child = flow_box;
2525 }
2626
27- private Gtk .Widget create_flow_box_child (Object ? item ) {
28- var image = new Gtk .Image .from_gicon ((Icon ) item);
29- bind_property (" icon-size" , image, " pixel-size" , SYNC_CREATE , (binding, from_value, ref to_value) = > {
30- var icon_size = from_value. get_int ();
31- to_value. set_int (get_pixel_size (icon_size));
32- return true ;
33- });
34- // We use margin instead of grid spacing because grid spacing in combination with
35- // min children per line causes the flow box to request the grid spacing as additional width
36- // even when there is only one child making it off center.
37- bind_property (" icon-size" , image, " margin-start" , SYNC_CREATE , icon_size_to_margin);
38- bind_property (" icon-size" , image, " margin-top" , SYNC_CREATE , icon_size_to_margin);
39- bind_property (" icon-size" , image, " margin-end" , SYNC_CREATE , icon_size_to_margin);
40- bind_property (" icon-size" , image, " margin-bottom" , SYNC_CREATE , icon_size_to_margin);
41-
27+ private static Gtk .Widget create_flow_box_child (Object item ) {
4228 return new Gtk .FlowBoxChild () {
43- child = image ,
29+ child = new CustomImage (( Icon ) item) ,
4430 can_focus = false ,
4531 can_target = false
4632 };
4733 }
4834
49- private static bool icon_size_to_margin (Binding binding , Value from_value , ref Value to_value ) {
50- var icon_size = from_value. get_int ();
51- var pixel_size = get_pixel_size (icon_size);
52- var spacing = (int ) Math . round ((icon_size - pixel_size * MAX_IN_ROW ) / 6 );
53- to_value. set_int (spacing);
54- return true ;
55- }
35+ private class CustomImage : Granite .Bin {
36+ private const string ICON_SIZE = " icon-size" ;
37+ private static Settings settings = new Settings (" io.elementary.dock" );
38+
39+ public Gtk . Image image { private get ; construct; }
40+
41+ public CustomImage (Icon icon ) {
42+ Object (image: new Gtk .Image .from_gicon (icon));
43+ }
44+
45+ construct {
46+ child = image;
47+
48+ settings. changed[ICON_SIZE ]. connect (on_icon_size_changed);
49+ on_icon_size_changed ();
50+ }
51+
52+ private void on_icon_size_changed () {
53+ var new_icon_size = settings. get_int (ICON_SIZE );
54+ var new_pixel_size = icon_size_to_pixel_size (new_icon_size);
55+
56+ image. pixel_size = new_pixel_size;
57+
58+ // We use margin instead of grid spacing because grid spacing in combination with
59+ // min children per line causes the flow box to request the grid spacing as additional width
60+ // even when there is only one child making it off center.
61+ var margin = (new_icon_size - new_pixel_size * MAX_IN_ROW ) / 6 ;
62+ margin_start = margin;
63+ margin_top = margin;
64+ margin_end = margin;
65+ margin_bottom = margin;
66+ }
5667
57- private static int get_pixel_size (int for_icon_size ) {
58- switch (for_icon_size) {
59- case 64 : return 24 ;
60- case 48 : return 16 ;
61- case 32 : return 8 ;
62- default: return (int ) Math . round (for_icon_size / 3 );
68+ private static int icon_size_to_pixel_size (int icon_size ) {
69+ switch (icon_size) {
70+ case 64 : return 24 ;
71+ case 48 : return 16 ;
72+ case 32 : return 8 ;
73+ default: return (int ) Math . round (icon_size / 3 );
74+ }
6375 }
6476 }
6577}
0 commit comments