|
3 | 3 |
|
4 | 4 | import WinSDK
|
5 | 5 |
|
| 6 | +/// A control for selecting a single value from a continuous range of values. |
6 | 7 | public class Slider: Control {
|
7 | 8 | private static let `class`: WindowClass = WindowClass(named: TRACKBAR_CLASS)
|
8 | 9 | private static let style: WindowStyle =
|
9 | 10 | (base: WS_POPUP | DWORD(TBS_HORZ | TBS_TRANSPARENTBKGND), extended: 0)
|
10 | 11 |
|
| 12 | + // MARK - Accessing the Slider's Value |
| 13 | + |
| 14 | + /// The slider’s current value. |
11 | 15 | public var value: Float {
|
12 |
| - get { Float(SendMessageW(hWnd, UINT(TBM_GETPOS), 0, 0)) / 100.0 } |
| 16 | + get { |
| 17 | + Float(SendMessageW(hWnd, UINT(TBM_GETPOS), 0, 0)) / 100.0 |
| 18 | + } |
13 | 19 | set(value) {
|
14 |
| - SendMessageW(hWnd, UINT(TBM_SETPOS), WPARAM(1), LPARAM(value * 100.0)) |
| 20 | + _ = SendMessageW(hWnd, UINT(TBM_SETPOS), WPARAM(1), LPARAM(value * 100.0)) |
15 | 21 | }
|
16 | 22 | }
|
17 | 23 |
|
| 24 | + // MARK - Accessing the Slider's Value Limits |
| 25 | + |
| 26 | + /// The minimum value of the slider. |
18 | 27 | public var minimumValue: Float {
|
19 |
| - get { Float(SendMessageW(hWnd, UINT(TBM_GETRANGEMIN), 0, 0)) / 100.0 } |
| 28 | + get { |
| 29 | + Float(SendMessageW(self.hWnd, UINT(TBM_GETRANGEMIN), 0, 0)) / 100.0 |
| 30 | + } |
20 | 31 | set(value) {
|
21 |
| - SendMessageW(hWnd, UINT(TBM_SETRANGEMIN), WPARAM(1), LPARAM(value * 100.0)) |
| 32 | + _ = SendMessageW(self.hWnd, UINT(TBM_SETRANGEMIN), |
| 33 | + WPARAM(1), LPARAM(value * 100.0)) |
22 | 34 | }
|
23 | 35 | }
|
24 | 36 |
|
| 37 | + /// The maximum value of the slider. |
25 | 38 | public var maximumValue: Float {
|
26 |
| - get { Float(SendMessageW(hWnd, UINT(TBM_GETRANGEMAX), 0, 0)) / 100.0 } |
| 39 | + get { |
| 40 | + Float(SendMessageW(self.hWnd, UINT(TBM_GETRANGEMAX), 0, 0)) / 100.0 |
| 41 | + } |
27 | 42 | set(value) {
|
28 |
| - SendMessageW(hWnd, UINT(TBM_SETRANGEMAX), WPARAM(1), LPARAM(value * 100.0)) |
| 43 | + _ = SendMessageW(self.hWnd, UINT(TBM_SETRANGEMAX), |
| 44 | + WPARAM(1), LPARAM(value * 100.0)) |
29 | 45 | }
|
30 | 46 | }
|
31 | 47 |
|
| 48 | + // MARK - |
| 49 | + |
32 | 50 | public init(frame: Rect) {
|
33 | 51 | super.init(frame: frame, class: Slider.class, style: Slider.style)
|
34 |
| - SendMessageW(hWnd, UINT(TBM_SETLINESIZE), WPARAM(1), LPARAM(100)) |
| 52 | + _ = SendMessageW(self.hWnd, UINT(TBM_SETLINESIZE), WPARAM(1), LPARAM(100)) |
35 | 53 | }
|
36 | 54 | }
|
0 commit comments