diff options
-rw-r--r-- | src/edit.rs | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/src/edit.rs b/src/edit.rs index b5b35ac..0e62267 100644 --- a/src/edit.rs +++ b/src/edit.rs @@ -10,6 +10,7 @@ slint::slint! { import { HorizontalBox, VerticalBox } from "std-widgets.slint"; export global Aux := { + property<int> selected: 0; callback format-rgb-hex(color) -> string; } @@ -22,6 +23,8 @@ slint::slint! { rgb( 0, 0, 0), ]; + property<int> base: 0; + squares := HorizontalBox { width : 100%; height : 20px; @@ -30,11 +33,12 @@ slint::slint! { property <color> current-color : col; width : (squares.width / 8) - 12px; height : (squares.width / 8) - 12px; - border-color : ptouch.has-hover ? #eeeeee : #333333; + border-color : i == (Aux.selected - base) ? #cb4b16 : #839496; border-width : 3px; forward-focus: pval; ptouch := TouchArea { + clicked => { Aux.selected = base + i; } } prect := Rectangle { @@ -46,6 +50,7 @@ slint::slint! { VerticalBox { pdesc := Text { + /* Text will be set through callback from Rust. */ text : i; } Rectangle { @@ -79,6 +84,15 @@ slint::slint! { if (event.text == "q") { user-quit(); } + if (event.text == " ") { + if (event.modifiers.shift) { + debug("select prev"); + color-vbox.select-prev(); + } else { + debug("select next"); + color-vbox.select-next(); + } + } if (event.modifiers.control) { //debug("control was pressed during this event"); } @@ -89,6 +103,19 @@ slint::slint! { color-vbox := VerticalBox { alignment: start; + callback select-prev(); + callback select-next(); + + select-prev () => { + Aux.selected = Aux.selected == 0 ? 15 : Aux.selected - 1; + debug ("selected previous, now", Aux.selected); + } + + select-next () => { + Aux.selected = mod (Aux.selected + 1, 16); + debug ("selected next, now", Aux.selected); + } + status := HorizontalBox { width : 100%; @@ -100,9 +127,11 @@ slint::slint! { } primary-colors := Colors { + base : 0; } secondary-colors := Colors { + base : 8; } } } @@ -142,9 +171,7 @@ impl Edit let gui = GuiEdit::new(); - gui.on_user_quit(move || { - std::process::exit(0); - }); + gui.on_user_quit (move || { std::process::exit(0); }); gui.global::<Aux>().on_format_rgb_hex(|col| { let x = (col.red() as u32) << 2 |