diff options
author | Aylur <[email protected]> | 2024-10-14 16:45:03 +0000 |
---|---|---|
committer | Aylur <[email protected]> | 2024-10-14 16:45:03 +0000 |
commit | 9fab13452a26ed55c01047d4225f699f43bba20d (patch) | |
tree | 8dc3097994e8664572c3a94a62257604bdaa1f8d /lib/astal/gtk3/src/widget/slider.vala | |
parent | 6a8c41cd1d5e218d0dacffb836fdd7d4ec6333dd (diff) |
feat: Astal3
Diffstat (limited to 'lib/astal/gtk3/src/widget/slider.vala')
-rw-r--r-- | lib/astal/gtk3/src/widget/slider.vala | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/lib/astal/gtk3/src/widget/slider.vala b/lib/astal/gtk3/src/widget/slider.vala new file mode 100644 index 0000000..466275b --- /dev/null +++ b/lib/astal/gtk3/src/widget/slider.vala @@ -0,0 +1,71 @@ +public class Astal.Slider : Gtk.Scale { + [CCode (notify = false)] + public bool vertical { + get { return orientation == Gtk.Orientation.VERTICAL; } + set { orientation = value ? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL; } + } + + // emitted when the user drags the slider + public signal void dragged (); + + construct { + draw_value = false; + + if (adjustment == null) + adjustment = new Gtk.Adjustment(0,0,0,0,0,0); + + if (max == 0 && min == 0) { + max = 1; + } + + if (step == 0) { + step = 0.05; + } + + notify["orientation"].connect(() => { + notify_property("vertical"); + }); + + button_press_event.connect(() => { dragging = true; }); + key_press_event.connect(() => { dragging = true; }); + button_release_event.connect(() => { dragging = false; }); + key_release_event.connect(() => { dragging = false; }); + scroll_event.connect((event) => { + dragging = true; + if (event.delta_y > 0) + value -= step; + else + value += step; + dragging = false; + }); + + value_changed.connect(() => { + if (dragging) + dragged(); + }); + } + + public bool dragging { get; private set; } + + public double value { + get { return adjustment.value; } + set { if (!dragging) adjustment.value = value; } + } + + public double min { + get { return adjustment.lower; } + set { adjustment.lower = value; } + } + + public double max { + get { return adjustment.upper; } + set { adjustment.upper = value; } + } + + public double step { + get { return adjustment.step_increment; } + set { adjustment.step_increment = value; } + } + + // TODO: marks +} |