summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2022-08-18 06:12:37 +0200
committerPhilipp Gesang <phg@phi-gamma.net>2022-08-18 06:12:37 +0200
commit0cf6a01681e750ab4ddd0ca65787ff6d2f41083c (patch)
treebf5cc81e4edfa026d805a11e73d96f1eaf287820 /src
parent49231b55aaa746543fa3d6e6ff95e1839e156fa5 (diff)
downloadvtcol-0cf6a01681e750ab4ddd0ca65787ff6d2f41083c.tar.gz
edit: abstract out the color views
Diffstat (limited to 'src')
-rw-r--r--src/edit.rs173
1 files changed, 77 insertions, 96 deletions
diff --git a/src/edit.rs b/src/edit.rs
index f43dcbd..b5b35ac 100644
--- a/src/edit.rs
+++ b/src/edit.rs
@@ -13,120 +13,97 @@ slint::slint! {
callback format-rgb-hex(color) -> string;
}
- GuiEdit := Window {
- property scheme-name <=> name.text;
+ Colors := Rectangle {
+ width : 100%;
+ border-width : 2px;
+ background: @linear-gradient(90deg, #002b36 0%, #073642 100%);
- property <[color]> primary: [
+ property <[color]> colors: [
rgb( 0, 0, 0),
];
- property <[color]> secondary: [
- rgb(255, 255, 255),
- ];
+ squares := HorizontalBox {
+ width : 100%;
+ height : 20px;
- VerticalBox {
- alignment: start;
+ for col[i] in colors : psquare := Rectangle {
+ property <color> current-color : col;
+ width : (squares.width / 8) - 12px;
+ height : (squares.width / 8) - 12px;
+ border-color : ptouch.has-hover ? #eeeeee : #333333;
+ border-width : 3px;
+ forward-focus: pval;
- status := HorizontalBox {
- width : 100%;
+ ptouch := TouchArea {
+ }
- name := Text {
- text : "<unnamed>";
- color : #a0a0a0;
- font-weight : 700;
+ prect := Rectangle {
+ y : 3px;
+ x : 3px;
+ width : psquare.width - 6px;
+ height : psquare.height - 6px;
+ background : current-color;
+
+ VerticalBox {
+ pdesc := Text {
+ text : i;
+ }
+ Rectangle {
+ background : ptouch.has-hover ? #ffffff77 : #cccccc33;
+ pval := TextInput {
+ text : Aux.format-rgb-hex(current-color);
+ font-size : 9pt;
+ }
+ }
+ Rectangle { }
+ }
}
}
+ }
+ }
- primary-colors := Rectangle {
- width : 100%;
- background : #aaaaaa;
- border-width : 2px;
+ GuiEdit := Window {
+ property scheme-name <=> name.text;
- squares-primary := HorizontalBox {
- width : 100%;
- height : 20px;
+ callback set-primary ([color]);
+ callback set-secondary ([color]);
- for col[i] in primary : psquare := Rectangle {
- property <color> current-color : col;
- width : (squares-primary.width / 8) - 12px;
- height : (squares-primary.width / 8) - 12px;
- border-color : ptouch.has-hover ? #eeeeee : #333333;
- border-width : 3px;
+ set-primary (colors) => { primary-colors .colors = colors; }
+ set-secondary (colors) => { secondary-colors.colors = colors; }
- ptouch := TouchArea {
- }
+ callback user-quit();
- prect := Rectangle {
- forward-focus: pval;
- y : 3px;
- x : 3px;
- width : psquare.width - 6px;
- height : psquare.height - 6px;
- background : current-color;
-
- VerticalBox {
- pdesc := Text {
- text : i;
- }
- Rectangle {
- background : ptouch.has-hover ? #ffffff77 : #cccccc33;
- pval := TextInput {
- text : Aux.format-rgb-hex(current-color);
- font-size : 9pt;
- }
- }
- Rectangle { }
- }
- }
- }
+ key-inputs := FocusScope {
+ key-pressed(event) => {
+ debug("input: got", event.text, "shift?", event.modifiers.shift);
+ if (event.text == "q") {
+ user-quit();
+ }
+ if (event.modifiers.control) {
+ //debug("control was pressed during this event");
}
+ accept
}
+ }
- secondary-colors := Rectangle {
- width : 100%;
- background : #bbbbbb;
- border-width : 2px;
-
- squares-secondary := HorizontalBox {
- width : 100%;
- height : 20px;
-
- for col[i] in secondary : ssquare := Rectangle {
- property <color> current-color : col;
- property <int> i2 : i + 8;
- width : (squares-secondary.width / 8) - 12px;
- height : (squares-secondary.width / 8) - 12px;
- border-color : stouch.has-hover ? #eeeeee : #333333;
- border-width : 3px;
- forward-focus: sval;
-
- stouch := TouchArea {
- }
+ color-vbox := VerticalBox {
+ alignment: start;
- srect := Rectangle {
- y : 3px;
- x : 3px;
- width : ssquare.width - 6px;
- height : ssquare.height - 6px;
- background : current-color;
-
- VerticalBox {
- sdesc := Text {
- text : i;
- }
- Rectangle {
- background : stouch.has-hover ? #ffffff77 : #cccccc33;
- sval := TextInput {
- text : Aux.format-rgb-hex(current-color);
- font-size : 9pt;
- }
- }
- Rectangle { }
- }
- }
- }
+ status := HorizontalBox {
+ width : 100%;
+
+ name := Text {
+ text : "<unnamed>";
+ color : #a0a0a0;
+ font-weight : 700;
}
}
+
+ primary-colors := Colors {
+ }
+
+ secondary-colors := Colors {
+ }
}
}
}
@@ -165,6 +142,10 @@ impl Edit
let gui = GuiEdit::new();
+ gui.on_user_quit(move || {
+ std::process::exit(0);
+ });
+
gui.global::<Aux>().on_format_rgb_hex(|col| {
let x = (col.red() as u32) << 2
| (col.green() as u32) << 1
@@ -176,8 +157,8 @@ impl Edit
gui.set_scheme_name(name.into());
}
- gui.set_primary(primary.into());
- gui.set_secondary(secondary.into());
+ gui.invoke_set_primary(primary.into());
+ gui.invoke_set_secondary(secondary.into());
gui.run();