blob: b927e32ae54a543391e36173db9f067792598110 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
/**
* Subclass of [[email protected]] which adds a signal and property for the drag state.
*/
public class Astal.Slider : Gtk.Scale {
/**
* Corresponds to [[email protected] :orientation].
*/
[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 or uses keyboard arrows and its value changes.
*/
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;
}
if (page == 0) {
page = 0.01;
}
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();
});
}
/**
* `true` when the user drags the slider or uses keyboard arrows.
*/
public bool dragging { get; private set; }
/**
* Value of this slider. Defaults to `0`.
*/
public double value {
get { return adjustment.value; }
set { if (!dragging) adjustment.value = value; }
}
/**
* Minimum possible value of this slider. Defaults to `0`.
*/
public double min {
get { return adjustment.lower; }
set { adjustment.lower = value; }
}
/**
* Maximum possible value of this slider. Defaults to `1`.
*/
public double max {
get { return adjustment.upper; }
set { adjustment.upper = value; }
}
/**
* Size of step increments. Defaults to `0.05`.
*/
public double step {
get { return adjustment.step_increment; }
set { adjustment.step_increment = value; }
}
/**
* Size of page increments. Defaults to `0.01`.
*/
public double page {
get { return adjustment.page_increment; }
set { adjustment.page_increment = value; }
}
// TODO: marks
}
|