GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git
cce-ui: add support for toggle corner radius and plate opacity/corner radius layout parameters
src/layout.rs | 120 ++++++++++++++++++++++++++++++++++++++++++
src/widget/container/plate.rs | 18 ++++++-
src/widget/input/checkbox.rs | 14 +++++
3 files changed, 150 insertions(+), 2 deletions(-)
diff --git a/src/layout.rs b/src/layout.rs
index a8eb1f1..f42d9d3 100644
--- a/src/layout.rs
+++ b/src/layout.rs
@@ -58,6 +58,11 @@ static SPINBOX_CORNER_RADIUS: RwLock<f32> = RwLock::new(4.0);
static TEXTBOX_CORNER_RADIUS: RwLock<f32> = RwLock::new(4.0);
static FONT_SELECTOR_CORNER_RADIUS: RwLock<f32> = RwLock::new(4.0);
static DROPDOWN_CORNER_RADIUS: RwLock<f32> = RwLock::new(4.0);
+static TOGGLE_CORNER_RADIUS: RwLock<f32> = RwLock::new(4.0);
+static PLATE_CORNER_RADIUS: RwLock<f32> = RwLock::new(12.0);
+static PLATE_OPACITY: RwLock<f32> = RwLock::new(1.0);
+
+
/// Standard line height multiplier for text layout in cce-ui.
pub const TEXT_LINE_HEIGHT_MULTIPLIER: f32 = 1.4;
@@ -191,7 +196,36 @@ pub fn reload_config() {
}
}
}
+ if let Some(rest) = trimmed.strip_prefix("toggle_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) = TOGGLE_CORNER_RADIUS.write() {
+ *lock = val;
+ }
+ }
+ }
+ if let Some(rest) = trimmed.strip_prefix("plate_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) = PLATE_CORNER_RADIUS.write() {
+ *lock = val;
+ }
+ }
+ }
+ if let Some(rest) = trimmed.strip_prefix("plate_opacity") {
+ 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) = PLATE_OPACITY.write() {
+ *lock = val;
+ }
+ }
+ }
+
if let Some(rest) = trimmed.strip_prefix("toggle_height") {
+
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>() {
@@ -663,6 +697,92 @@ pub fn set_toggle_height(height: f32) {
}
}
+pub fn toggle_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("toggle_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) = TOGGLE_CORNER_RADIUS.write() {
+ *lock = val;
+ }
+ }
+ }
+ }
+ }
+ });
+ *TOGGLE_CORNER_RADIUS.read().unwrap()
+}
+
+pub fn set_toggle_corner_radius(radius: f32) {
+ if let Ok(mut lock) = TOGGLE_CORNER_RADIUS.write() {
+ *lock = radius;
+ }
+}
+
+pub fn plate_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("plate_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) = PLATE_CORNER_RADIUS.write() {
+ *lock = val;
+ }
+ }
+ }
+ }
+ }
+ });
+ *PLATE_CORNER_RADIUS.read().unwrap()
+}
+
+pub fn set_plate_corner_radius(radius: f32) {
+ if let Ok(mut lock) = PLATE_CORNER_RADIUS.write() {
+ *lock = radius;
+ }
+}
+
+pub fn plate_opacity() -> 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("plate_opacity") {
+ 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) = PLATE_OPACITY.write() {
+ *lock = val;
+ }
+ }
+ }
+ }
+ }
+ });
+ *PLATE_OPACITY.read().unwrap()
+}
+
+pub fn set_plate_opacity(opacity: f32) {
+ if let Ok(mut lock) = PLATE_OPACITY.write() {
+ *lock = opacity;
+ }
+}
+
+
+
pub fn color_selector_height() -> f32 {
use std::sync::Once;
static INIT: Once = Once::new();
diff --git a/src/widget/container/plate.rs b/src/widget/container/plate.rs
index 5b67de7..3696d1c 100644
--- a/src/widget/container/plate.rs
+++ b/src/widget/container/plate.rs
@@ -100,9 +100,20 @@ impl Element for Plate {
}
fn is_plate(&self) -> bool { true }
- fn rounded_corners(&self) -> (bool, bool, bool, bool) { (true, true, true, true) }
+ fn rounded_corners(&self) -> (bool, bool, bool, bool) {
+ let r = crate::layout::plate_corner_radius();
+ if r > 0.0 {
+ (true, true, true, true)
+ } else {
+ (false, false, false, false)
+ }
+ }
+ fn corner_radius(&self) -> f32 {
+ crate::layout::plate_corner_radius()
+ }
fn highlight_quad(&self, _ctx: &UiContext) -> Option<(f32, f32, f32, f32, [f32; 4])>{ None }
+
fn solid_border(&self) -> Option<([f32; 4], f32)> {
if self.selected {
Some((colors::active_theme().primary_accent, 1.5))
@@ -146,7 +157,9 @@ impl Element for Plate {
} else {
colors::page_low_color()
};
+ c[3] *= crate::layout::plate_opacity();
c[3] *= self.network_opacity;
+
if self.blur {
c[3] = -c[3].abs();
}
@@ -172,7 +185,8 @@ impl Element for Plate {
return false;
}
- let r = 12.0f32.min(w * 0.5).min(h * 0.5);
+ let r = crate::layout::plate_corner_radius().min(w * 0.5).min(h * 0.5);
+
if r <= 0.1 {
return true;
}
diff --git a/src/widget/input/checkbox.rs b/src/widget/input/checkbox.rs
index 2811093..0081881 100644
--- a/src/widget/input/checkbox.rs
+++ b/src/widget/input/checkbox.rs
@@ -291,7 +291,21 @@ impl Element for Toggle {
fn take_click(&mut self) -> bool {
if self.just_toggled { self.just_toggled = false; true } else { false }
}
+
+ fn rounded_corners(&self) -> (bool, bool, bool, bool) {
+ let r = crate::layout::toggle_corner_radius();
+ if r > 0.0 {
+ (true, true, true, true)
+ } else {
+ (false, false, false, false)
+ }
+ }
+
+ fn corner_radius(&self) -> f32 {
+ crate::layout::toggle_corner_radius()
+ }
}
+
impl Control for Checkbox {}
impl Control for Toggle {}