blob: 99882590f4710c508103ee52091e3dce8eed38c5 (
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
|
// Copyright (c) 2013-2021 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
using System;
using System.ComponentModel;
using Drawing2D;
namespace Crow
{
/// <summary>
/// templeted numeric control
/// </summary>
public class ScrollBar : Slider
{
#region CTOR
protected ScrollBar () {}
public ScrollBar(Interface iface, string style = null) : base (iface, style) { }
#endregion
double cursorRatio;
/// <summary>
/// Ratio of CusorSize / CursorContainerSize, -1 if not in use.
/// </summary>
[DefaultValue(-1.0)]
public double CursorRatio {
get => cursorRatio;
set {
if (cursorRatio == value)
return;
if (double.IsFinite(value) && cursorRatio < 1.0)
cursorRatio = value;
else
cursorRatio = -1;
updateCursor ();
}
}
void updateCursor () {
if (cursorRatio < 0 || !double.IsFinite(cursorRatio) || cursorRatio > 1.0)
return;
ILayoutable l = cursor?.Parent;
if (l == null)
return;
Rectangle r = cursor.Parent.ClientRectangle;
if (Orientation == Orientation.Horizontal)
CursorSize = (int)(cursorRatio * r.Width);
else
CursorSize = (int)(cursorRatio * r.Height);
}
protected override void HandleCursorContainerLayoutChanged (object sender, LayoutingEventArgs e) {
base.HandleCursorContainerLayoutChanged (sender, e);
updateCursor ();
}
}
}
|