git.lucas.co / cce-ui
GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git

commit6ac5c2f28812c2834cdb05f8403006033d29b54d
parent51e06d901f
authorLucas Galante <[email protected]>
date2026-07-07 08:50
refactor: resolve bundled font/icon dirs via helpers, not hardcoded paths

Add fonts_dir()/icons_dir() helpers ($CCE_FONTS_DIR / $CCE_ICONS_DIR with
$HOME-based fallbacks) and route the remaining hardcoded /home/lsgalante font
and cce-icons SVG paths through them (text_box font db, keybinds remove icon).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

 src/lib.rs                           | 26 +++++++++++++++++++-------
 src/widget/input/keybinds_control.rs |  3 ++-
 src/widget/input/text_box.rs         |  2 +-
 3 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/src/lib.rs b/src/lib.rs
index 9eea1e6..7570de0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -20,15 +20,27 @@ pub const SHADER: &str = include_str!("shader.wgsl");
 pub static IS_VERTICAL: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
 pub static BAR_THICKNESS: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(24);
 
-pub fn create_font_system() -> glyphon::FontSystem {
-    let mut db = glyphon::cosmic_text::fontdb::Database::new();
-    // Font directory: $CCE_FONTS_DIR if set, else ~/Dropbox/Fonts. Resolving via
-    // $HOME keeps the existing location while dropping the hardcoded username.
-    let fonts_dir = std::env::var("CCE_FONTS_DIR").unwrap_or_else(|_| {
+/// Directory bundled fonts are loaded from: `$CCE_FONTS_DIR`, else `~/Dropbox/Fonts`.
+/// Resolving via `$HOME` keeps the existing location without a hardcoded username.
+pub fn fonts_dir() -> String {
+    std::env::var("CCE_FONTS_DIR").unwrap_or_else(|_| {
         let home = std::env::var("HOME").unwrap_or_default();
         format!("{home}/Dropbox/Fonts")
-    });
-    db.load_fonts_dir(&fonts_dir);
+    })
+}
+
+/// Directory the bundled cce-icons SVGs are loaded from: `$CCE_ICONS_DIR`, else
+/// `~/Dropbox/cce/cce-icons/svg`.
+pub fn icons_dir() -> String {
+    std::env::var("CCE_ICONS_DIR").unwrap_or_else(|_| {
+        let home = std::env::var("HOME").unwrap_or_default();
+        format!("{home}/Dropbox/cce/cce-icons/svg")
+    })
+}
+
+pub fn create_font_system() -> glyphon::FontSystem {
+    let mut db = glyphon::cosmic_text::fontdb::Database::new();
+    db.load_fonts_dir(fonts_dir());
     if std::env::var("CCE_LOAD_SYSTEM_FONTS").is_ok() {
         db.load_system_fonts();
     }
diff --git a/src/widget/input/keybinds_control.rs b/src/widget/input/keybinds_control.rs
index 78690c8..266d121 100644
--- a/src/widget/input/keybinds_control.rs
+++ b/src/widget/input/keybinds_control.rs
@@ -16,7 +16,8 @@ impl KeybindRow {
         let key_input = TextBox::new(binding).with_placeholder("e.g. super+shift+q");
         let cmd_input = TextBox::new(command).with_placeholder("e.g. close");
         
-        let remove_svg = Svg::from_file("/home/lsgalante/Dropbox/cce/cce-icons/svg/x.svg", 0.0, 0.0, 14.0, 14.0);
+        let remove_icon = format!("{}/x.svg", crate::icons_dir());
+        let remove_svg = Svg::from_file(&remove_icon, 0.0, 0.0, 14.0, 14.0);
         let mut remove_button = Button::new(0.0, 0.0, 0.0, 0.0);
         if let Some(svg) = remove_svg {
             remove_button = remove_button.with_svg(svg);
diff --git a/src/widget/input/text_box.rs b/src/widget/input/text_box.rs
index fb48c3f..7dfb674 100644
--- a/src/widget/input/text_box.rs
+++ b/src/widget/input/text_box.rs
@@ -7,7 +7,7 @@ pub fn get_font_db() -> &'static resvg::usvg::fontdb::Database {
     FONT_DB.get_or_init(|| {
         let mut db = resvg::usvg::fontdb::Database::new();
         db.load_system_fonts();
-        db.load_fonts_dir("/home/lsgalante/Dropbox/Fonts");
+        db.load_fonts_dir(crate::fonts_dir());
         db
     })
 }