Skip to content

Commit 8b5cd45

Browse files
committed
Scale badges and progress bars with icon size
1 parent 1f55ec4 commit 8b5cd45

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

data/Application.css

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,45 @@ launcher progressbar progress {
6666
min-width: 0;
6767
}
6868

69+
launcher progressbar.small {
70+
margin-left: 4px;
71+
margin-right: 4px;
72+
margin-bottom: 4px;
73+
}
74+
75+
launcher progressbar.small trough {
76+
min-height: 1px;
77+
}
78+
79+
launcher progressbar.small progress {
80+
min-height: 1px;
81+
}
82+
83+
launcher progressbar.large trough {
84+
min-height: 6px;
85+
}
86+
87+
launcher progressbar.large {
88+
margin-left: 7px;
89+
margin-right: 7px;
90+
margin-bottom: 7px;
91+
}
92+
93+
launcher progressbar.large progress {
94+
min-height: 6px;
95+
}
96+
97+
launcher .badge.small {
98+
min-width: 18px;
99+
min-height: 18px;
100+
}
101+
102+
launcher .badge.large {
103+
font-size: 16px;
104+
min-width: 28px;
105+
min-height: 28px;
106+
}
107+
69108
tooltip {
70109
margin-bottom: 0.5em;
71110
}

src/AppSystem/Launcher.vala

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public class Dock.Launcher : BaseItem {
111111

112112
var badge = new Gtk.Label ("!");
113113
badge.add_css_class (Granite.STYLE_CLASS_BADGE);
114+
badge.set_data<Scalable> ("scalable", new Scalable (badge));
114115

115116
animatable_badge = new AnimatableWidget () {
116117
child = badge
@@ -442,6 +443,7 @@ public class Dock.Launcher : BaseItem {
442443
valign = END
443444
};
444445
app.bind_property ("progress", progress_bar, "fraction", SYNC_CREATE);
446+
progress_bar.set_data<Scalable> ("scalable", new Scalable (progress_bar));
445447

446448
progress_revealer.child = progress_bar;
447449
}
@@ -461,4 +463,46 @@ public class Dock.Launcher : BaseItem {
461463
to_value.set_string (src > 0 ? "%lld".printf (src) : "!");
462464
return true;
463465
}
466+
467+
/**
468+
* Scalable is a class that handles scale style classes on Gtk.Widgets.
469+
* Can be used for scaling widgets based on icon-size with CSS only.
470+
* Possible CSS classes are "large" and "small".
471+
*/
472+
private class Scalable : Object {
473+
private const string CSS_CLASS_LARGE = "large";
474+
private const string CSS_CLASS_SMALL = "small";
475+
private static Settings settings = new Settings ("io.elementary.dock");
476+
477+
private weak Gtk.Widget widget;
478+
479+
public Scalable (Gtk.Widget widget) {
480+
this.widget = widget;
481+
this.widget.weak_ref (on_widget_disposed);
482+
483+
settings.changed["icon-size"].connect (update_icon_size);
484+
update_icon_size ();
485+
}
486+
487+
~Scalable () {
488+
widget?.weak_unref (on_widget_disposed);
489+
}
490+
491+
private void on_widget_disposed () {
492+
widget = null;
493+
}
494+
495+
private void update_icon_size () {
496+
var icon_size = settings.get_int ("icon-size");
497+
498+
widget.remove_css_class (CSS_CLASS_LARGE);
499+
widget.remove_css_class (CSS_CLASS_SMALL);
500+
501+
if (icon_size >= 64) {
502+
widget.add_css_class (CSS_CLASS_LARGE);
503+
} else if (icon_size <= 32) {
504+
widget.add_css_class (CSS_CLASS_SMALL);
505+
}
506+
}
507+
}
464508
}

0 commit comments

Comments
 (0)