diff --git a/lib/dlangui.lib b/lib/dlangui.lib new file mode 100644 index 00000000..81427d9c Binary files /dev/null and b/lib/dlangui.lib differ diff --git a/lib/libfreetype-6.dll b/lib/libfreetype-6.dll new file mode 100644 index 00000000..850b650b Binary files /dev/null and b/lib/libfreetype-6.dll differ diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index 534b003c..e271e3ec 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -2528,7 +2528,108 @@ class EditLine : EditWidgetBase { } } +// SpinCtrl +private { + import std.ascii; + alias _ui = UIString.fromRaw; +} +class SpinCtrl : HorizontalLayout { + + TextWidget label; + int min, max; + + private EditLine linEdit; + private Button butUp, butDown; + + + @property int value() { return linEdit.text.to!int; } + @property void value(int val) { + linEdit.text = val.to!dstring; + } + + this(int min, int max, int initialVal = 0, string labelText = null){ + this.min = min; + this.max = max; + + if(labelText !is null){ + label = new TextWidget("label", _ui(labelText)); + addChild(label); + } + + linEdit = new class EditLine { + this(){super("linEdit", "0"d);} + override bool onKeyEvent(KeyEvent event) { + if (( KeyAction.Text == event.action && event.text[0].isDigit) + || event.keyCode == KeyCode.BACK + || event.keyCode == KeyCode.DEL + || event.keyCode == KeyCode.LEFT + || event.keyCode == KeyCode.RIGHT + || event.keyCode == KeyCode.TAB + ){ + return super.onKeyEvent(event); + } + return false; + } + + override bool onMouseEvent(MouseEvent event) { + if(event.action == MouseAction.Wheel){ + if((event.wheelDelta == 1) && (value < max)) + value = value + event.wheelDelta; + if((event.wheelDelta == -1) && (value > min)) + value = value + event.wheelDelta; + return true; + } + return super.onMouseEvent(event); + } + }; + + linEdit.addOnFocusChangeListener((w, t){ + if(linEdit.text == "") + linEdit.text = "0"; + if(linEdit.text.to!int > max) + value = max; + if(linEdit.text.to!int < min) + value = min; + return true; + }); + + linEdit.minHeight = 35; + if(initialVal != 0) + value = initialVal; + addChild(linEdit); + + + auto butContainer = new VerticalLayout(); + butContainer.maxHeight = linEdit.minHeight; + + butUp = new Button("butUp", "+"d); + butUp.margins(Rect(1.pointsToPixels, 1.pointsToPixels, 1.pointsToPixels, 1.pointsToPixels)); + + butDown = new Button("butDown", "-"d); + butDown.margins(Rect(1.pointsToPixels, 1.pointsToPixels, 1.pointsToPixels, 1.pointsToPixels)); + + butContainer.addChild(butUp); + butContainer.addChild(butDown); + + addChild(butContainer); + + butUp.click = delegate(Widget w) { + immutable val = linEdit.text.to!int; + if(val < max ) + linEdit.text = (val + 1).to!string._ui; + return true; + }; + + butDown.click = delegate(Widget w) { + immutable val = linEdit.text.to!int; + if(val > min ) + linEdit.text = (val - 1).to!string._ui; + return true; + }; + } + +} /// multiline editor class EditBox : EditWidgetBase {