GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git
Support style.control.button.font mapping and button layout font resolution
src/layout.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++
src/widget/input/button.rs | 2 +-
2 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/src/layout.rs b/src/layout.rs
index 1b39ecc..c6e6081 100644
--- a/src/layout.rs
+++ b/src/layout.rs
@@ -70,6 +70,7 @@ fn flatten_json_to_flat_props(val: &serde_json::Value, prefix: &str, flat_props:
"style.control.button.padding" => "button_padding",
"style.control.button.height" => "button_height",
"style.control.button.corner_radius" => "button_corner_radius",
+ "style.control.button.font" => "button_font",
"style.list.corner_radius" | "style.data.list.corner_radius" => "list_corner_radius",
"style.control.textbox.corner_radius" | "style.textbox.corner_radius" | "style.data.textbox.corner_radius" => "textbox_corner_radius",
"style.control.dropdown.color" => "dropdown_color",
@@ -249,6 +250,7 @@ static STATUSBAR_FONT_CACHED: RwLock<Option<(String, f32)>> = RwLock::new(None);
static SECTION_LABEL_FONT: RwLock<String> = RwLock::new(String::new());
static NESTED_SECTION_LABEL_FONT: RwLock<String> = RwLock::new(String::new());
static BREADCRUMB_FONT: RwLock<String> = RwLock::new(String::new());
+static BUTTON_FONT: RwLock<String> = RwLock::new(String::new());
static PAGINATOR_TAB_PADDING_X: RwLock<f32> = RwLock::new(10.0);
static BUTTON_PADDING: RwLock<f32> = RwLock::new(14.0);
@@ -735,6 +737,14 @@ pub fn reload_config() {
*lock = font;
}
}
+ if let Some(rest) = trimmed.strip_prefix("button_font") {
+ let rest = rest.trim_start_matches(|c: char| c == ' ' || c == '=');
+ let rest = mod_rest(rest);
+ let font = rest.trim().to_string();
+ if let Ok(mut lock) = BUTTON_FONT.write() {
+ *lock = font;
+ }
+ }
if let Some(rest) = trimmed.strip_prefix("color_selector_preview_corner_radius") {
let rest = rest.trim_start_matches(|c: char| c == ' ' || c == '=' || c == '"');
let val_str = rest.trim_end_matches('"').trim();
@@ -2407,6 +2417,44 @@ pub fn set_breadcrumb_font(font: &str) {
}
}
+pub fn button_font() -> String {
+ use std::sync::Once;
+ static INIT: Once = Once::new();
+ INIT.call_once(|| {
+ let mut font = "Outfit".to_string();
+ if let Some(content) = read_config() {
+ for line in content.lines() {
+ let trimmed = line.trim();
+ if let Some(rest) = trimmed.strip_prefix("button_font") {
+ let rest = rest.trim_start_matches(|c: char| c == ' ' || c == '=');
+ let rest = rest.trim();
+ let val_str = if rest.starts_with('"') && rest.ends_with('"') && rest.len() >= 2 {
+ &rest[1..rest.len() - 1]
+ } else {
+ rest
+ };
+ font = val_str.trim().to_string();
+ }
+ }
+ }
+ if let Ok(mut lock) = BUTTON_FONT.write() {
+ *lock = font;
+ }
+ });
+ let lock = BUTTON_FONT.read().unwrap();
+ if lock.is_empty() {
+ "Outfit".to_string()
+ } else {
+ lock.clone()
+ }
+}
+
+pub fn set_button_font(font: &str) {
+ if let Ok(mut lock) = BUTTON_FONT.write() {
+ *lock = font.to_string();
+ }
+}
+
pub fn color_selector_preview_corner_radius() -> f32 {
lazy_init_style_registry();
get_style_registry().read().unwrap().get_float("color_selector_preview_corner_radius").unwrap_or(4.0)
diff --git a/src/widget/input/button.rs b/src/widget/input/button.rs
index 22fddff..f239790 100644
--- a/src/widget/input/button.rs
+++ b/src/widget/input/button.rs
@@ -346,7 +346,7 @@ impl Element for Button {
if self.kind == ButtonKind::ListRow {
Some(crate::layout::list_font())
} else {
- Some(crate::layout::control_label_font())
+ Some(crate::layout::button_font())
}
}