GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git
Fix render_widget to draw all_rounded_quads and fix unquoted KDL section identifiers
src/config.rs | 15 +++++++++++++--
src/layout.rs | 3 +++
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/config.rs b/src/config.rs
index 2b32cbe..b831e07 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -679,6 +679,17 @@ fn format_kdl_type(ty: &str) -> String {
}
}
+fn format_kdl_identifier(name: &str) -> String {
+ let is_ident = !name.is_empty()
+ && !name.chars().next().unwrap().is_ascii_digit()
+ && name.chars().all(|c| c.is_ascii_alphanumeric() || matches!(c, '_' | '-' | '+' | '?' | '!' | '@' | '*' | '~' | '|' | '.'));
+ if is_ident {
+ name.to_string()
+ } else {
+ format!("\"{}\"", name.replace('\\', "\\\\").replace('"', "\\\""))
+ }
+}
+
pub fn value_to_kdl(key: &str, val: &serde_json::Value, indent: usize) -> String {
value_to_kdl_with_annotations(key, val, indent, "", &std::collections::HashMap::new())
}
@@ -701,7 +712,7 @@ pub fn value_to_kdl_with_annotations(
serde_json::Value::Object(map) => {
let has_objects = map.values().any(|v| v.is_object());
if has_objects {
- let mut out = format!("{}{} {{\n", indent_str, key);
+ let mut out = format!("{}{} {{\n", indent_str, format_kdl_identifier(key));
for (k, v) in map {
out.push_str(&value_to_kdl_with_annotations(k, v, indent + 1, ¤t_path, annotations));
}
@@ -797,7 +808,7 @@ pub fn json_to_kdl_string_with_annotations(
if let serde_json::Value::Object(map) = val {
for (sec_name, sec_val) in map {
if let serde_json::Value::Object(sec_map) = sec_val {
- out.push_str(&format!("{} {{\n", sec_name));
+ out.push_str(&format!("{} {{\n", format_kdl_identifier(sec_name)));
for (k, v) in sec_map {
out.push_str(&value_to_kdl_with_annotations(k, v, 1, sec_name, annotations));
}
diff --git a/src/layout.rs b/src/layout.rs
index d389f79..ce8db98 100644
--- a/src/layout.rs
+++ b/src/layout.rs
@@ -3334,6 +3334,9 @@ pub fn render_widget<T: Element + 'static>(pc: &mut dyn RenderTarget, w: &mut T,
pc.rect_with_radius_corners(qc, qx, qy, qw, qh, resolved_r, resolved_corners);
}
}
+ for (qx, qy, qw, qh, qr, qc, qcorners) in w.all_rounded_quads(ctx) {
+ pc.rect_with_radius_corners(qc, qx, qy, qw, qh, qr, qcorners);
+ }
let font_opt = w.widget_font();
for (label, font, bounds) in w.text_labels_with_font_and_bounds(ctx) {
let color_f32 = [