mirror of https://github.com/adamdruppe/arsd.git
make the color picker a bit less bad on linux
This commit is contained in:
parent
b0b0b09d32
commit
6bbc91f90b
33
minigui.d
33
minigui.d
|
@ -9563,6 +9563,23 @@ class DataViewerWidget : Widget {
|
||||||
+/
|
+/
|
||||||
alias LabeledLineEdit = Labeled!LineEdit;
|
alias LabeledLineEdit = Labeled!LineEdit;
|
||||||
|
|
||||||
|
private int widthThatWouldFitChildLabels(Widget w) {
|
||||||
|
if(w is null)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int max;
|
||||||
|
|
||||||
|
if(auto label = cast(TextLabel) w) {
|
||||||
|
return label.TextLabel.flexBasisWidth() + label.paddingLeft() + label.paddingRight();
|
||||||
|
} else {
|
||||||
|
foreach(child; w.children) {
|
||||||
|
max = mymax(max, widthThatWouldFitChildLabels(child));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
/++
|
/++
|
||||||
History:
|
History:
|
||||||
Added May 19, 2021
|
Added May 19, 2021
|
||||||
|
@ -9589,13 +9606,23 @@ class Labeled(T) : Widget {
|
||||||
auto hl = new L(this);
|
auto hl = new L(this);
|
||||||
if(horizontal) {
|
if(horizontal) {
|
||||||
static class SpecialTextLabel : TextLabel {
|
static class SpecialTextLabel : TextLabel {
|
||||||
this(string label, TextAlignment alignment, Widget parent) {
|
Widget outerParent;
|
||||||
|
|
||||||
|
this(string label, TextAlignment alignment, Widget outerParent, Widget parent) {
|
||||||
|
this.outerParent = outerParent;
|
||||||
super(label, alignment, parent);
|
super(label, alignment, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
override int paddingTop() { return 6; }
|
override int flexBasisWidth() {
|
||||||
|
return widthThatWouldFitChildLabels(outerParent);
|
||||||
|
}
|
||||||
|
|
||||||
|
override int paddingRight() { return 6; }
|
||||||
|
override int paddingLeft() { return 9; }
|
||||||
|
|
||||||
|
override int paddingTop() { return 3; }
|
||||||
}
|
}
|
||||||
this.label = new SpecialTextLabel(label, alignment, hl);
|
this.label = new SpecialTextLabel(label, alignment, parent, hl);
|
||||||
} else
|
} else
|
||||||
this.label = new TextLabel(label, alignment, hl);
|
this.label = new TextLabel(label, alignment, hl);
|
||||||
this.lineEdit = new T(hl);
|
this.lineEdit = new T(hl);
|
||||||
|
|
|
@ -112,21 +112,12 @@ class ColorPickerDialog : Dialog {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto hs = new HorizontalSlider(0, 1000, 50, t);
|
||||||
|
|
||||||
auto hr = new HorizontalLayout(t);
|
auto hr = new HorizontalLayout(t);
|
||||||
|
|
||||||
auto vlRgb = new class VerticalLayout {
|
auto vlRgb = new VerticalLayout(180, hr);
|
||||||
this() {
|
auto vlHsl = new VerticalLayout(180, hr);
|
||||||
super(hr);
|
|
||||||
}
|
|
||||||
override int maxWidth() { return 150; };
|
|
||||||
};
|
|
||||||
|
|
||||||
auto vlHsl = new class VerticalLayout {
|
|
||||||
this() {
|
|
||||||
super(hr);
|
|
||||||
}
|
|
||||||
override int maxWidth() { return 150; };
|
|
||||||
};
|
|
||||||
|
|
||||||
h = new LabeledLineEdit("Hue:", TextAlignment.Right, vlHsl);
|
h = new LabeledLineEdit("Hue:", TextAlignment.Right, vlHsl);
|
||||||
s = new LabeledLineEdit("Saturation:", TextAlignment.Right, vlHsl);
|
s = new LabeledLineEdit("Saturation:", TextAlignment.Right, vlHsl);
|
||||||
|
@ -142,6 +133,8 @@ class ColorPickerDialog : Dialog {
|
||||||
import std.conv;
|
import std.conv;
|
||||||
import std.format;
|
import std.format;
|
||||||
|
|
||||||
|
double[3] lastHsl;
|
||||||
|
|
||||||
void updateCurrent() {
|
void updateCurrent() {
|
||||||
r.content = to!string(current.r);
|
r.content = to!string(current.r);
|
||||||
g.content = to!string(current.g);
|
g.content = to!string(current.g);
|
||||||
|
@ -149,12 +142,18 @@ class ColorPickerDialog : Dialog {
|
||||||
a.content = to!string(current.a);
|
a.content = to!string(current.a);
|
||||||
|
|
||||||
auto hsl = current.toHsl;
|
auto hsl = current.toHsl;
|
||||||
|
if(hsl[2] == 0.0 || hsl[2] == 1.0) {
|
||||||
|
hsl[0 .. 2] = lastHsl[0 .. 2];
|
||||||
|
}
|
||||||
|
|
||||||
h.content = format("%0.2f", hsl[0]);
|
h.content = format("%0.3f", hsl[0]);
|
||||||
s.content = format("%0.2f", hsl[1]);
|
s.content = format("%0.3f", hsl[1]);
|
||||||
l.content = format("%0.2f", hsl[2]);
|
l.content = format("%0.3f", hsl[2]);
|
||||||
|
|
||||||
|
hs.setPosition(cast(int) (hsl[2] * 1000));
|
||||||
|
|
||||||
css.content = current.toCssString();
|
css.content = current.toCssString();
|
||||||
|
lastHsl = hsl;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCurrent();
|
updateCurrent();
|
||||||
|
@ -180,6 +179,18 @@ class ColorPickerDialog : Dialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hs.addEventListener((ChangeEvent!int ce) {
|
||||||
|
// this should only change l, not hs
|
||||||
|
auto ch = h.content;
|
||||||
|
auto cs = s.content;
|
||||||
|
l.content = to!string(ce.value / 1000.0);
|
||||||
|
convertFromHsl();
|
||||||
|
|
||||||
|
h.content = ch;
|
||||||
|
s.content = cs;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
h.addEventListener("change", &convertFromHsl);
|
h.addEventListener("change", &convertFromHsl);
|
||||||
s.addEventListener("change", &convertFromHsl);
|
s.addEventListener("change", &convertFromHsl);
|
||||||
l.addEventListener("change", &convertFromHsl);
|
l.addEventListener("change", &convertFromHsl);
|
||||||
|
@ -190,26 +201,38 @@ class ColorPickerDialog : Dialog {
|
||||||
});
|
});
|
||||||
|
|
||||||
void helper(MouseEventBase event) {
|
void helper(MouseEventBase event) {
|
||||||
auto h = cast(double) event.clientX / hslImage.width * 360.0;
|
try {
|
||||||
auto s = 1.0 - (cast(double) event.clientY / hslImage.height * 1.0);
|
// this should ONLY actually change hue and saturation
|
||||||
auto l = this.l.content.to!double;
|
|
||||||
|
|
||||||
current = Color.fromHsl(h, s, l);
|
auto h = cast(double) event.clientX / hslImage.width * 360.0;
|
||||||
current.a = a.content.to!ubyte;
|
auto s = 1.0 - (cast(double) event.clientY / hslImage.height * 1.0);
|
||||||
|
auto oldl = this.l.content;
|
||||||
|
auto oldhsp = hs.position;
|
||||||
|
auto l = this.l.content.to!double;
|
||||||
|
|
||||||
updateCurrent();
|
current = Color.fromHsl(h, s, l);
|
||||||
|
// import std.stdio; writeln(current.toHsl, " ", h, " ", s, " ", l);
|
||||||
|
current.a = a.content.to!ubyte;
|
||||||
|
|
||||||
auto e2 = new Event("change", this);
|
updateCurrent();
|
||||||
e2.dispatch();
|
|
||||||
|
this.l.content = oldl;
|
||||||
|
hs.setPosition(oldhsp);
|
||||||
|
|
||||||
|
auto e2 = new Event("change", this);
|
||||||
|
e2.dispatch();
|
||||||
|
} catch(Exception e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hslImage !is null)
|
if(hslImage !is null)
|
||||||
wid.addEventListener((MouseDownEvent ev) { helper(ev); });
|
wid.addEventListener((MouseDownEvent ev) { helper(ev); });
|
||||||
|
|
||||||
if(hslImage !is null)
|
if(hslImage !is null)
|
||||||
wid.addEventListener((MouseMoveEvent event) {
|
wid.addEventListener((MouseMoveEvent event) {
|
||||||
if(event.state & ModifierState.leftButtonDown)
|
if(event.state & ModifierState.leftButtonDown)
|
||||||
helper(event);
|
helper(event);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.addEventListener((KeyDownEvent event) {
|
this.addEventListener((KeyDownEvent event) {
|
||||||
if(event.key == Key.Enter || event.key == Key.PadEnter)
|
if(event.key == Key.Enter || event.key == Key.PadEnter)
|
||||||
|
|
Loading…
Reference in New Issue