GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git
Add textbox_corner_radius layout setting and TextBox styling
src/layout.rs | 38 ++++++++++++++++++++++++++++++++++++++
src/widget/input/text_box.rs | 13 +++++++++++++
2 files changed, 51 insertions(+)
diff --git a/src/layout.rs b/src/layout.rs
index 58c32d1..ad5de8d 100644
--- a/src/layout.rs
+++ b/src/layout.rs
@@ -54,6 +54,7 @@ static NESTED_SECTION_LABEL_ALIGNMENT: RwLock<u8> = RwLock::new(0);
static LABEL_MARGIN: RwLock<f32> = RwLock::new(6.0);
static BUTTON_CORNER_RADIUS: RwLock<f32> = RwLock::new(4.0);
static SPINBOX_CORNER_RADIUS: RwLock<f32> = RwLock::new(4.0);
+static TEXTBOX_CORNER_RADIUS: RwLock<f32> = RwLock::new(4.0);
/// Standard line height multiplier for text layout in cce-ui.
pub const TEXT_LINE_HEIGHT_MULTIPLIER: f32 = 1.4;
@@ -155,6 +156,15 @@ pub fn reload_config() {
}
}
}
+ if let Some(rest) = trimmed.strip_prefix("textbox_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) = TEXTBOX_CORNER_RADIUS.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();
@@ -929,6 +939,34 @@ pub fn set_spinbox_corner_radius(radius: f32) {
}
}
+pub fn textbox_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("textbox_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) = TEXTBOX_CORNER_RADIUS.write() {
+ *lock = val;
+ }
+ }
+ }
+ }
+ }
+ });
+ *TEXTBOX_CORNER_RADIUS.read().unwrap()
+}
+
+pub fn set_textbox_corner_radius(radius: f32) {
+ if let Ok(mut lock) = TEXTBOX_CORNER_RADIUS.write() {
+ *lock = radius;
+ }
+}
+
pub fn color_selector_preview_margin() -> f32 {
use std::sync::Once;
static INIT: Once = Once::new();
diff --git a/src/widget/input/text_box.rs b/src/widget/input/text_box.rs
index 089a4a5..eb328ac 100644
--- a/src/widget/input/text_box.rs
+++ b/src/widget/input/text_box.rs
@@ -372,6 +372,19 @@ impl Element for TextBox {
Some(crate::layout::textbox_height())
}
+ fn rounded_corners(&self) -> (bool, bool, bool, bool) {
+ let r = crate::layout::textbox_corner_radius();
+ if r > 0.0 {
+ (true, true, true, true)
+ } else {
+ (false, false, false, false)
+ }
+ }
+
+ fn corner_radius(&self) -> f32 {
+ crate::layout::textbox_corner_radius()
+ }
+
fn rect(&self) -> (f32, f32, f32, f32) { (self.base.x, self.base.y, self.base.w, self.base.h) }
fn set_rect(&mut self, x: f32, y: f32, w: f32, h: f32) {
let final_w = if let Some(explicit_w) = self.width {