This commit is contained in:
aferust 2020-01-13 10:56:19 +03:00
parent 1822edb88d
commit 3b3ed044c8
3 changed files with 101 additions and 0 deletions

BIN
lib/dlangui.lib Normal file

Binary file not shown.

BIN
lib/libfreetype-6.dll Normal file

Binary file not shown.

View File

@ -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 {