GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git
Add color_selector_corner_radius setting and implement it on ColorSelector widget
src/layout.rs | 38 ++++++++++++++++++++++++++++++++++++++
src/widget/input/color_selector.rs | 13 +++++++++++++
2 files changed, 51 insertions(+)
diff --git a/src/layout.rs b/src/layout.rs
index ad5de8d..54cc42f 100644
--- a/src/layout.rs
+++ b/src/layout.rs
@@ -37,6 +37,7 @@ static TOGGLE_HEIGHT: RwLock<f32> = RwLock::new(44.0);
static COLOR_SELECTOR_FONT: RwLock<String> = RwLock::new(String::new());
static COLOR_SELECTOR_PREVIEW_CORNER_RADIUS: RwLock<f32> = RwLock::new(4.0);
static COLOR_SELECTOR_PREVIEW_MARGIN: RwLock<f32> = RwLock::new(0.0);
+static COLOR_SELECTOR_CORNER_RADIUS: RwLock<f32> = RwLock::new(4.0);
static MENUBAR_FONT: RwLock<String> = RwLock::new(String::new());
static MENUBAR_FONT_CACHED: RwLock<Option<(String, f32)>> = RwLock::new(None);
static SECTION_LABEL_FONT: RwLock<String> = RwLock::new(String::new());
@@ -250,6 +251,15 @@ pub fn reload_config() {
}
}
}
+ if let Some(rest) = trimmed.strip_prefix("color_selector_corner_radius") {
+ let rest = rest.trim_start_matches(|c: char| c == ' ' || c == '=' || c == '"');
+ let val_str = rest.trim_end_matches('"').trim();
+ if let Ok(val) = val_str.parse::<f32>() {
+ if let Ok(mut lock) = COLOR_SELECTOR_CORNER_RADIUS.write() {
+ *lock = val;
+ }
+ }
+ }
if let Some(rest) = trimmed.strip_prefix("color_selector_preview_margin") {
let rest = rest.trim_start_matches(|c: char| c == ' ' || c == '=' || c == '"');
let val_str = rest.trim_end_matches('"').trim();
@@ -883,6 +893,34 @@ pub fn set_color_selector_preview_corner_radius(radius: f32) {
}
}
+pub fn color_selector_corner_radius() -> f32 {
+ use std::sync::Once;
+ static INIT: Once = Once::new();
+ INIT.call_once(|| {
+ if let Some(content) = read_config() {
+ for line in content.lines() {
+ let trimmed = line.trim();
+ if let Some(rest) = trimmed.strip_prefix("color_selector_corner_radius") {
+ let rest = rest.trim_start_matches(|c: char| c == ' ' || c == '=' || c == '"');
+ let val_str = rest.trim_end_matches('"').trim();
+ if let Ok(val) = val_str.parse::<f32>() {
+ if let Ok(mut lock) = COLOR_SELECTOR_CORNER_RADIUS.write() {
+ *lock = val;
+ }
+ }
+ }
+ }
+ }
+ });
+ *COLOR_SELECTOR_CORNER_RADIUS.read().unwrap()
+}
+
+pub fn set_color_selector_corner_radius(radius: f32) {
+ if let Ok(mut lock) = COLOR_SELECTOR_CORNER_RADIUS.write() {
+ *lock = radius;
+ }
+}
+
pub fn button_corner_radius() -> f32 {
use std::sync::Once;
static INIT: Once = Once::new();
diff --git a/src/widget/input/color_selector.rs b/src/widget/input/color_selector.rs
index fd3bfc3..fc4084b 100644
--- a/src/widget/input/color_selector.rs
+++ b/src/widget/input/color_selector.rs
@@ -143,6 +143,19 @@ impl Element for ColorSelector {
Some(crate::layout::color_selector_height())
}
+ fn rounded_corners(&self) -> (bool, bool, bool, bool) {
+ let r = crate::layout::color_selector_corner_radius();
+ if r > 0.0 {
+ (true, true, true, true)
+ } else {
+ (false, false, false, false)
+ }
+ }
+
+ fn corner_radius(&self) -> f32 {
+ crate::layout::color_selector_corner_radius()
+ }
+
fn widget_font(&self) -> Option<String> {
Some(self.font_family.clone())
}