mirror of https://github.com/adamdruppe/arsd.git
better scroll clicking
This commit is contained in:
parent
aa35f13e60
commit
05850b77b9
52
minigui.d
52
minigui.d
|
@ -552,6 +552,8 @@ else version(custom_widgets) {
|
|||
enum activeListXorColor = Color(255, 255, 127);
|
||||
enum progressBarColor = Color(0, 0, 128);
|
||||
enum activeMenuItemColor = Color(0, 0, 128);
|
||||
|
||||
enum scrollClickRepeatInterval = 50;
|
||||
}
|
||||
else static assert(false);
|
||||
// these are used by horizontal rule so not just custom_widgets. for now at least.
|
||||
|
@ -567,6 +569,52 @@ private const(wchar)* toWstringzInternal(in char[] s) {
|
|||
return str.ptr;
|
||||
}
|
||||
|
||||
void setClickRepeat(Widget w, int interval, int delay = 250) {
|
||||
Timer timer;
|
||||
int delayRemaining = delay / interval;
|
||||
if(delayRemaining <= 1)
|
||||
delayRemaining = 2;
|
||||
|
||||
immutable originalDelayRemaining = delayRemaining;
|
||||
|
||||
w.addDirectEventListener("mousedown", (Event ev) {
|
||||
if(ev.srcElement !is w)
|
||||
return;
|
||||
if(timer !is null) {
|
||||
timer.destroy();
|
||||
timer = null;
|
||||
}
|
||||
delayRemaining = originalDelayRemaining;
|
||||
timer = new Timer(interval, () {
|
||||
if(delayRemaining > 0)
|
||||
delayRemaining--;
|
||||
else {
|
||||
auto ev = new Event("click", w);
|
||||
ev.sendDirectly();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
w.addDirectEventListener("mouseup", (Event ev) {
|
||||
if(ev.srcElement !is w)
|
||||
return;
|
||||
if(timer !is null) {
|
||||
timer.destroy();
|
||||
timer = null;
|
||||
}
|
||||
});
|
||||
|
||||
w.addDirectEventListener("mouseleave", (Event ev) {
|
||||
if(ev.srcElement !is w)
|
||||
return;
|
||||
if(timer !is null) {
|
||||
timer.destroy();
|
||||
timer = null;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
enum FrameStyle {
|
||||
risen,
|
||||
sunk
|
||||
|
@ -2537,8 +2585,10 @@ class HorizontalScrollbar : ScrollbarBase {
|
|||
} else version(custom_widgets) {
|
||||
auto vl = new HorizontalLayout(this);
|
||||
auto leftButton = new ArrowButton(ArrowDirection.left, vl);
|
||||
leftButton.setClickRepeat(scrollClickRepeatInterval);
|
||||
thumb = new MouseTrackingWidget(MouseTrackingWidget.Orientation.horizontal, vl);
|
||||
auto rightButton = new ArrowButton(ArrowDirection.right, vl);
|
||||
rightButton.setClickRepeat(scrollClickRepeatInterval);
|
||||
|
||||
leftButton.addEventListener(EventType.triggered, () {
|
||||
informProgramThatUserChangedPosition(position - step());
|
||||
|
@ -2625,8 +2675,10 @@ class VerticalScrollbar : ScrollbarBase {
|
|||
} else version(custom_widgets) {
|
||||
auto vl = new VerticalLayout(this);
|
||||
auto upButton = new ArrowButton(ArrowDirection.up, vl);
|
||||
upButton.setClickRepeat(scrollClickRepeatInterval);
|
||||
thumb = new MouseTrackingWidget(MouseTrackingWidget.Orientation.vertical, vl);
|
||||
auto downButton = new ArrowButton(ArrowDirection.down, vl);
|
||||
downButton.setClickRepeat(scrollClickRepeatInterval);
|
||||
|
||||
upButton.addEventListener(EventType.triggered, () {
|
||||
informProgramThatUserChangedPosition(position - step());
|
||||
|
|
|
@ -13829,14 +13829,19 @@ mixin template ExperimentalTextComponent() {
|
|||
/// ditto
|
||||
void insert(dchar ch) {
|
||||
|
||||
deleteSelection();
|
||||
bool selectionDeleted = false;
|
||||
if(selectionStart !is selectionEnd) {
|
||||
deleteSelection();
|
||||
selectionDeleted = true;
|
||||
}
|
||||
|
||||
if(ch == 127) {
|
||||
delete_();
|
||||
return;
|
||||
}
|
||||
if(ch == 8) {
|
||||
backspace();
|
||||
if(!selectionDeleted)
|
||||
backspace();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue