From f131d2102adc53b429a9d4bb8fd9d96a467baa55 Mon Sep 17 00:00:00 2001
From: robertwidfen <126524724+robertwidfen@users.noreply.github.com>
Date: Sat, 16 May 2026 05:47:58 +0200
Subject: [PATCH] feat: select custom color for invalid palette idx
If index in palette is out of range select custom color.
---
README.md | 2 ++
src/main.rs | 10 +++++++---
src/sketch_board.rs | 10 +++-------
3 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/README.md b/README.md
index 40550fb0..83bfb753 100644
--- a/README.md
+++ b/README.md
@@ -58,6 +58,8 @@ All configuration is done either at the config file in `XDG_CONFIG_DIR/.config/s
1, 2, 3, …, 9, 0 — select nth color from the color palette
+If out of range select custom color NEXTRELEASE
+
#### Tool Selection Shortcuts (configurable) 0.20.0
Default single-key shortcuts:
- p: Pointer tool
diff --git a/src/main.rs b/src/main.rs
index 114c599a..6c9df4ea 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -257,11 +257,15 @@ impl Component for App {
.emit(ToolsToolbarInput::SwitchSelectedTool(tool));
}
AppInput::ColorSwitchShortcut(index) => {
+ let palette_len = APP_CONFIG.read().color_palette().palette().len() as u64;
+ let color_button = if index < palette_len {
+ ui::toolbars::ColorButtons::Palette(index)
+ } else {
+ ui::toolbars::ColorButtons::Custom
+ };
self.style_toolbar
.sender()
- .emit(StyleToolbarInput::ColorButtonSelected(
- ui::toolbars::ColorButtons::Palette(index),
- ));
+ .emit(StyleToolbarInput::ColorButtonSelected(color_button));
}
AppInput::ScaleFactorChanged => {
self.sketch_board
diff --git a/src/sketch_board.rs b/src/sketch_board.rs
index 22a828fc..bbada02b 100644
--- a/src/sketch_board.rs
+++ b/src/sketch_board.rs
@@ -895,13 +895,9 @@ impl SketchBoard {
} else {
hotkey_digit - 1
};
- if APP_CONFIG.read().color_palette().palette().len()
- >= (index_digit + 1) as usize
- {
- sender
- .output_sender()
- .emit(SketchBoardOutput::ColorSwitchShortcut(index_digit as u64));
- }
+ sender
+ .output_sender()
+ .emit(SketchBoardOutput::ColorSwitchShortcut(index_digit as u64));
}
}
TextEventMsg::Preedit {