GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git
Implement button padding in layout and use it in ButtonStrip
src/layout.rs | 50 ++++++++++++++++++++++++++++++++--------
src/widget/input/button_strip.rs | 8 +++----
2 files changed, 45 insertions(+), 13 deletions(-)
diff --git a/src/layout.rs b/src/layout.rs
index 706675e..f2b6360 100644
--- a/src/layout.rs
+++ b/src/layout.rs
@@ -45,7 +45,7 @@ static NESTED_SECTION_LABEL_FONT: RwLock<String> = RwLock::new(String::new());
static PAGINATOR_TAB_MARGIN_X: RwLock<f32> = RwLock::new(5.0);
static PAGINATOR_TAB_MARGIN_Y: RwLock<f32> = RwLock::new(10.0);
static PAGINATOR_TAB_PADDING_X: RwLock<f32> = RwLock::new(10.0);
-static PAGINATOR_TAB_PADDING_Y: RwLock<f32> = RwLock::new(14.0);
+static BUTTON_PADDING: RwLock<f32> = RwLock::new(14.0);
static PLATE_PADDING: RwLock<f32> = RwLock::new(20.0);
static DROPDOWN_HEIGHT: RwLock<f32> = RwLock::new(44.0);
@@ -287,11 +287,19 @@ pub fn reload_config() {
}
}
}
- if let Some(rest) = trimmed.strip_prefix("paginator_tab_padding_y") {
+ if let Some(rest) = trimmed.strip_prefix("button_padding") {
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) = PAGINATOR_TAB_PADDING_Y.write() {
+ if let Ok(mut lock) = BUTTON_PADDING.write() {
+ *lock = val;
+ }
+ }
+ } else if let Some(rest) = trimmed.strip_prefix("paginator_tab_padding_y") {
+ 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) = BUTTON_PADDING.write() {
*lock = val;
}
}
@@ -1053,34 +1061,58 @@ pub fn set_paginator_tab_padding_x(padding: f32) {
}
}
-pub fn paginator_tab_padding_y() -> f32 {
+pub fn button_padding() -> f32 {
use std::sync::Once;
static INIT: Once = Once::new();
INIT.call_once(|| {
if let Some(content) = read_config() {
+ let mut found = false;
for line in content.lines() {
let trimmed = line.trim();
- if let Some(rest) = trimmed.strip_prefix("paginator_tab_padding_y") {
+ if let Some(rest) = trimmed.strip_prefix("button_padding") {
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) = PAGINATOR_TAB_PADDING_Y.write() {
+ if let Ok(mut lock) = BUTTON_PADDING.write() {
*lock = val;
+ found = true;
+ }
+ }
+ }
+ }
+ if !found {
+ for line in content.lines() {
+ let trimmed = line.trim();
+ if let Some(rest) = trimmed.strip_prefix("paginator_tab_padding_y") {
+ 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) = BUTTON_PADDING.write() {
+ *lock = val;
+ }
}
}
}
}
}
});
- *PAGINATOR_TAB_PADDING_Y.read().unwrap()
+ *BUTTON_PADDING.read().unwrap()
}
-pub fn set_paginator_tab_padding_y(padding: f32) {
- if let Ok(mut lock) = PAGINATOR_TAB_PADDING_Y.write() {
+pub fn set_button_padding(padding: f32) {
+ if let Ok(mut lock) = BUTTON_PADDING.write() {
*lock = padding;
}
}
+pub fn paginator_tab_padding_y() -> f32 {
+ button_padding()
+}
+
+pub fn set_paginator_tab_padding_y(padding: f32) {
+ set_button_padding(padding);
+}
+
pub fn textbox_height() -> f32 {
use std::sync::Once;
static INIT: Once = Once::new();
diff --git a/src/widget/input/button_strip.rs b/src/widget/input/button_strip.rs
index 1c856ad..5445ce8 100644
--- a/src/widget/input/button_strip.rs
+++ b/src/widget/input/button_strip.rs
@@ -103,7 +103,7 @@ impl ButtonStrip {
};
let r = self.item_rect(i);
- let padding_y = crate::layout::paginator_tab_padding_y();
+ let padding_y = crate::layout::button_padding();
let y_offset = if has_icon { 2.0 * padding_y + 12.0 } else { 0.0 };
let usable_h = (r.3 - y_offset).max(1.0);
@@ -187,7 +187,7 @@ impl ButtonStrip {
} else {
trimmed
};
- let padding_y = crate::layout::paginator_tab_padding_y();
+ let padding_y = crate::layout::button_padding();
let y_offset = if has_icon { 2.0 * padding_y + 12.0 } else { 0.0 };
let text_w = TextLabel::estimate_width(label_text, 12.0);
(text_w + y_offset).max(1.0)
@@ -331,7 +331,7 @@ impl Element for ButtonStrip {
let page_name = &self.buttons[i];
let trimmed = page_name.trim();
let has_icon = trimmed.find(' ').is_some();
- let padding_y = crate::layout::paginator_tab_padding_y();
+ let padding_y = crate::layout::button_padding();
let y_offset = if has_icon { 2.0 * padding_y + 12.0 } else { 0.0 };
for &(qx, qy, qw, qh, qc) in &self.tab_text_quads[i] {
@@ -369,7 +369,7 @@ impl Element for ButtonStrip {
if !icon.is_empty() {
let icon_font_size = 14.0;
let est_icon_w = TextLabel::estimate_width(icon, icon_font_size);
- let padding_y = crate::layout::paginator_tab_padding_y();
+ let padding_y = crate::layout::button_padding();
let icon_y = r.1 + (padding_y - 2.0).max(0.0);
labels.push(TextLabel {
text: icon.to_string(),