GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git
feat: add progressbar height KDL configuration support
src/layout.rs | 30 ++++++++++++++++++++++++++++++
src/widget/display/progress_bar.rs | 4 ++++
2 files changed, 34 insertions(+)
diff --git a/src/layout.rs b/src/layout.rs
index ca5b5f6..09e018c 100644
--- a/src/layout.rs
+++ b/src/layout.rs
@@ -89,6 +89,7 @@ fn flatten_json_to_flat_props(val: &serde_json::Value, prefix: &str, flat_props:
"style.label.font" => "label_font",
"style.control.slider.height" => "slider_height",
"style.control.slider.corner_radius" => "slider_corner_radius",
+ "style.control.progressbar.height" => "progressbar_height",
"style.control.scrollbar.width" => "scrollbar_width",
"style.control.spinbox.height" => "spinbox_height",
"style.control.spinbox.button_padding" => "spinbox_button_padding",
@@ -235,6 +236,7 @@ static COLOR_SELECTOR_HEIGHT: RwLock<f32> = RwLock::new(22.0);
static TEXTBOX_HEIGHT: RwLock<f32> = RwLock::new(44.0);
static FONT_SELECTOR_HEIGHT: RwLock<f32> = RwLock::new(44.0);
static SLIDER_HEIGHT: RwLock<f32> = RwLock::new(28.0);
+static PROGRESSBAR_HEIGHT: RwLock<f32> = RwLock::new(24.0);
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);
@@ -3386,6 +3388,34 @@ pub fn set_slider_height(height: f32) {
}
}
+pub fn progressbar_height() -> 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("progressbar_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>() {
+ if let Ok(mut lock) = PROGRESSBAR_HEIGHT.write() {
+ *lock = val;
+ }
+ }
+ }
+ }
+ }
+ });
+ *PROGRESSBAR_HEIGHT.read().unwrap()
+}
+
+pub fn set_progressbar_height(height: f32) {
+ if let Ok(mut lock) = PROGRESSBAR_HEIGHT.write() {
+ *lock = height;
+ }
+}
+
pub trait RenderTarget {
fn rect(&mut self, color: [f32; 4], x: f32, y: f32, w: f32, h: f32);
diff --git a/src/widget/display/progress_bar.rs b/src/widget/display/progress_bar.rs
index 62331d5..1337de2 100644
--- a/src/widget/display/progress_bar.rs
+++ b/src/widget/display/progress_bar.rs
@@ -30,6 +30,10 @@ impl Element for ProgressBar {
self.base.h = h + self.base.label_offset();
}
+ fn preferred_height(&self) -> Option<f32> {
+ Some(crate::layout::progressbar_height())
+ }
+
fn highlight_quad(&self, _ctx: &UiContext) -> Option<(f32, f32, f32, f32, [f32; 4])>{ None }
fn color(&self) -> [f32; 4] { colors::progress_bg() }