summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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