vv9k / epick

Color picker for creating harmonic color palettes that works on Linux, Windows, macOS and web.
GNU General Public License v3.0
101 stars 2 forks source link

Shortcut key to set picked color to the one under cursor #18

Closed crumblingstatue closed 3 years ago

crumblingstatue commented 3 years ago

I couldn't find any such key.

I would like something to the effect of

if ctx.input().key_pressed(egui::Key::P) {
    self.picker.set_cur_color(self.display_picker.as_ref().unwrap().get_color_under_cursor().unwrap());
}
vv9k commented 3 years ago

Thanks for the idea! I do agree something like this would improve usability. I'm thinking how to handle platforms where the display picker is unsupported like WASM. I guess the shortcut would only work when there is a display picker and otherwise it would be a nop.

crumblingstatue commented 3 years ago

Here is a cleaner implementation

diff --git a/src/app/mod.rs b/src/app/mod.rs
index af82d59..87f4c0b 100644
--- a/src/app/mod.rs
+++ b/src/app/mod.rs
@@ -656,6 +656,9 @@ impl App {
     ) {
         if let Some(picker) = self.display_picker.clone() {
             if let Ok(color) = picker.get_color_under_cursor() {
+                if ui.ctx().input().key_pressed(egui::Key::P) {
+                    self.picker.set_cur_color(color);
+                }
                 ui.horizontal(|mut ui| {
                     ui.label("Color at cursor: ");
                     self.color_box_label_side(&color, vec2(25., 25.), &mut ui, tex_allocator);
vv9k commented 3 years ago

Yes, that is the way. It would have to be handled inside of the platform specific code handle_zoom_picker.

crumblingstatue commented 3 years ago

Another usability idea: Use key_down instead of key_pressed, so the user can hold down the picker key to continuously change the color. It makes precision picking easier.

vv9k commented 3 years ago

I wonder if key_down can be differentiated from key_pressed, then it could perhaps set a color immediately on key_pressed and spawn a zoomed picker on key_down showing the area around the mouse. On release it would save the color to saved colors.

crumblingstatue commented 3 years ago

That's an interesting idea!

crumblingstatue commented 3 years ago

Thank you, it's working well!