From 30b5a3c67f640563460dc5d61e11d24721d66a11 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 18 Aug 2022 22:39:39 +0200 Subject: edit: make selection on click actually work MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/edit.rs | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'src') 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 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::().on_select(move |i: i32| { + let i = (i as usize % npal) as i32; + guiw.unwrap().global::().set_selected(i); + let col = guiw.unwrap().invoke_get_palette_color(i); + guiw.unwrap().invoke_update_edit(col); + }); + } + gui.global::().on_format_rgb_hex(|col| { let x = (col.red() as u32) << 2 | (col.green() as u32) << 1 -- cgit v1.2.3