summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2022-08-18 22:39:39 +0200
committerPhilipp Gesang <phg@phi-gamma.net>2022-08-19 07:24:49 +0200
commit30b5a3c67f640563460dc5d61e11d24721d66a11 (patch)
tree73f28714bdb7b520084f7f006dc3f0228fcf0cea /src
parent6d958759168110e02be8215f7f7cd423fa35b923 (diff)
downloadvtcol-30b5a3c67f640563460dc5d61e11d24721d66a11.tar.gz
edit: make selection on click actually work
Funneled into the ``Edit`` component via globals which seems to be the only (?) way of propagating these things between elements that don’t have one another in scope.
Diffstat (limited to 'src')
-rw-r--r--src/edit.rs34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/edit.rs b/src/edit.rs
index 2192f2c..af91c26 100644
--- a/src/edit.rs
+++ b/src/edit.rs
@@ -11,11 +11,11 @@ slint::slint! {
export global Aux := {
property<int> selected: 0;
+ callback select(int);
callback format-rgb-hex(color) -> string;
callback format-rgb-component(int) -> string;
callback color-of-rgb-component(string, int) -> color;
callback component-of-rgb(string, color) -> int;
- callback selected-color() -> color;
}
Colors := Rectangle {
@@ -42,7 +42,7 @@ slint::slint! {
forward-focus: pval;
ptouch := TouchArea {
- clicked => { Aux.selected = base + i; }
+ clicked => { Aux.select(base + i); }
}
prect := Rectangle {
@@ -104,9 +104,9 @@ slint::slint! {
callback update (color);
update (col) => {
debug("edit > update");
- //red.val = col.red();
- //green.val = col.green();
- //blue.val = col.blue();
+ red.val = Aux.component-of-rgb("r", col);
+ green.val = Aux.component-of-rgb("g", col);
+ blue.val = Aux.component-of-rgb("b", col);
}
VerticalBox {
@@ -127,6 +127,8 @@ slint::slint! {
set-primary (colors) => { primary-colors .colors = colors; }
set-secondary (colors) => { secondary-colors.colors = colors; }
+ callback get-palette-color(int) -> color;
+ callback update-edit <=> edit.update;
callback user-quit();
key-inputs := FocusScope {
@@ -168,6 +170,11 @@ slint::slint! {
}
}
+ get-palette-color (i) => {
+ i < 8 ? primary-colors.colors [i]
+ : secondary-colors.colors [i - 8]
+ }
+
master := VerticalBox {
alignment: start;
@@ -176,17 +183,17 @@ slint::slint! {
callback select-other-row();
select-prev () => {
- Aux.selected = Aux.selected == 0 ? 15 : Aux.selected - 1;
+ Aux.select (Aux.selected == 0 ? 15 : Aux.selected - 1);
debug ("selected previous, now", Aux.selected);
}
select-next () => {
- Aux.selected = mod (Aux.selected + 1, 16);
+ Aux.select (mod (Aux.selected + 1, 16));
debug ("selected next, now", Aux.selected);
}
select-other-row () => {
- Aux.selected = mod (Aux.selected + 8, 16);
+ Aux.select (mod (Aux.selected + 8, 16));
debug ("selected row above/below, now", Aux.selected);
}
@@ -252,6 +259,17 @@ impl Edit
std::process::exit(0);
});
+ {
+ let guiw = gui.as_weak();
+ let npal = pal.len();
+ gui.global::<Aux>().on_select(move |i: i32| {
+ let i = (i as usize % npal) as i32;
+ guiw.unwrap().global::<Aux>().set_selected(i);
+ let col = guiw.unwrap().invoke_get_palette_color(i);
+ guiw.unwrap().invoke_update_edit(col);
+ });
+ }
+
gui.global::<Aux>().on_format_rgb_hex(|col| {
let x = (col.red() as u32) << 2
| (col.green() as u32) << 1