From a1f457d71622649a1b1a84c00d200c8f1e315ab4 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Fri, 19 Aug 2022 07:33:22 +0200 Subject: edit: add setter for palette colors --- src/edit.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/edit.rs b/src/edit.rs index af91c26..de0fa80 100644 --- a/src/edit.rs +++ b/src/edit.rs @@ -12,6 +12,7 @@ slint::slint! { export global Aux := { property selected: 0; callback select(int); + callback set-palette-color(int, color); callback format-rgb-hex(color) -> string; callback format-rgb-component(int) -> string; callback color-of-rgb-component(string, int) -> color; @@ -128,6 +129,7 @@ slint::slint! { set-secondary (colors) => { secondary-colors.colors = colors; } callback get-palette-color(int) -> color; + callback set-palette-color(int, color); callback update-edit <=> edit.update; callback user-quit(); @@ -175,6 +177,14 @@ slint::slint! { : secondary-colors.colors [i - 8] } + set-palette-color (i, col) => { + if (i < 8) { + primary-colors.colors [i] = col; + } else { + secondary-colors.colors [i - 8] = col; + } + } + master := VerticalBox { alignment: start; @@ -270,6 +280,15 @@ impl Edit }); } + { + let guiw = gui.as_weak(); + let npal = pal.len(); + gui.global::().on_set_palette_color(move |i, col| { + let i = (i as usize % npal) as i32; + guiw.unwrap().invoke_set_palette_color(i, col); + }); + } + gui.global::().on_format_rgb_hex(|col| { let x = (col.red() as u32) << 2 | (col.green() as u32) << 1 -- cgit v1.2.3