diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..329bc00 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,164 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Project Overview + +This is a Slint UI component library inspired by shadcn/ui, implementing a comprehensive set of reusable UI components with theme support (light/dark mode), smooth animations, and a modern design system. The project is written in Rust with Slint for the UI layer. + +## Build and Development Commands + +### Building and Running +```bash +# Build and run the application +cargo run + +# Build in release mode +cargo run --release + +# Build only (without running) +cargo build + +# Clean build artifacts +cargo clean +``` + +### Development Workflow +- The build process uses `slint-build` (configured in `build.rs`) to compile `.slint` files +- Entry point: `ui/demo.slint` (specified in `build.rs:2`) +- Rust entry point: `src/main.rs` +- Changes to `.slint` files require a rebuild to take effect + +## Architecture + +### Project Structure + +``` +ui/ +├── demo.slint # Main application entry point +├── appwindow.slint # Basic window component (not used in demo) +├── components/ # Reusable UI components +│ ├── badge.slint +│ ├── button.slint +│ ├── card.slint +│ ├── dialog.slint +│ ├── input.slint +│ ├── item.slint +│ ├── sidebar.slint +│ └── toast.slint +├── theme/ # Design system +│ ├── colors.slint # Color palettes (light/dark) +│ ├── spacing.slint # Spacing and sizing system +│ ├── theme.slint # Global theme manager +│ └── typography.slint # Font system +└── utils/ + └── animations.slint # Animation utilities + +src/ +└── main.rs # Rust application logic +``` + +### Theme System + +The theme system is centralized through a global `Theme` singleton (`ui/theme/theme.slint`): + +- **Theme Manager**: `Theme` global provides reactive theme state + - `Theme.is-dark-mode`: Boolean controlling current theme + - `Theme.colors`: Reactive color palette that switches between light/dark + - `Theme.toggle-theme()`: Callback to switch themes + +- **Color Palettes**: Defined in `ui/theme/colors.slint` + - `LightColors.palette`: Light mode colors (shadcn zinc theme) + - `DarkColors.palette`: Dark mode colors + - All colors follow the `ColorPalette` struct with semantic naming (primary, secondary, destructive, muted, etc.) + +- **Design Tokens**: + - `Typography`: Font sizes, weights, and line heights + - `SpacingSystem`: Consistent spacing scale and border radii + - `Animations`: Duration and easing presets + +### Component Architecture + +All components follow shadcn/ui design patterns: + +1. **Variant-based styling**: Components accept `variant` property (e.g., "default", "destructive", "outline", "secondary", "ghost") +2. **Size variants**: Most components support `size` property ("sm", "md", "lg") +3. **State management**: Visual states (hover, pressed, disabled) use Slint's `states` blocks with sm transitions +4. **Theming**: All components reference `Theme.colors` for reactive theme switching + +### Rust-Slint Integration + +The Rust code (`src/main.rs`) handles: + +- **Component instantiation**: `Demo::new()` creates the UI +- **Callback handlers**: Rust implements callbacks defined in Slint (e.g., `on_add_task`, `on_show_toast`) +- **State management**: Complex state like toast notifications managed via `VecModel` and `ModelRc` +- **Timers**: Auto-dismiss functionality for toasts using `slint::Timer::single_shot()` + +Key pattern: Use weak references (`ui.as_weak()`) in callbacks to avoid circular references. + +## Component Development Guidelines + +### Creating New Components + +1. Create `.slint` file in `ui/components/` +2. Import theme system: `import { Theme, Typography, SpacingSystem } from "../theme/theme.slint";` +3. Define component with: + - Public properties (`in property`, `in-out property`) + - Callbacks for interactions + - Private properties for computed values + - Main container with theme-aware styling + - State blocks for interactive feedback + +4. Use consistent patterns: + - Border radius: `SpacingSystem.radius.md` + - Spacing: `SpacingSystem.spacing.s2`, `s3`, `s4`, etc. + - Colors: Always reference `Theme.colors.*` + - Animations: Use `Animations.durations.*` and `Animations.ease-*` + +### Visual Feedback Pattern + +Components use overlay rectangles for hover/press states (see `ui/components/button.slint:59-78`): +- `hover-overlay`: Light overlay (#ffffff15) on hover +- `press-overlay`: Dark overlay (#00000040) on press +- Animate with `Animations.durations.fast` for smooth transitions + +### Adding Rust Callbacks + +1. Define callback in Slint: `callback my-action(string);` +2. Implement in Rust: + ```rust + let ui_weak = ui.as_weak(); + ui.on_my_action(move |param| { + let ui = ui_weak.unwrap(); + // Handle action + }); + ``` + +## Design System Values + +### Color Semantic Naming +- `background` / `foreground`: Base colors +- `primary` / `primary-foreground`: Primary actions +- `secondary` / `secondary-foreground`: Secondary actions +- `destructive` / `destructive-foreground`: Dangerous actions +- `muted` / `muted-foreground`: Subtle/disabled states +- `border`, `input`, `ring`: UI element colors + +### Spacing Scale +- `s1` through `s12`: Incremental spacing (s1 = 4px, s2 = 8px, etc.) +- `radius`: Border radius variants (sm, md, lg, full) + +### Typography Scale +- Sizes: `xs`, `sm`, `base`, `lg`, `xl`, `2xl`, `3xl` +- Weights: `normal`, `medium`, `semibold`, `bold` + +## Current Demo Application + +The demo (`ui/demo.slint`) showcases a task manager with three views: +- **Tasks**: Add/manage tasks with cards, badges, and toasts +- **Components**: Visual showcase of all component variants +- **Settings**: Theme toggle and app information + +The sidebar navigation uses a collapsible pattern with icon + label layout. + diff --git a/Cargo.lock b/Cargo.lock index 15d7d33..196dc11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,96 +18,6 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "366ffbaa4442f4684d91e2cd7c5ea7c4ed8add41959a31447066e279e432b618" -[[package]] -name = "accesskit" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf203f9d3bd8f29f98833d1fbef628df18f759248a547e7e01cfbf63cda36a99" - -[[package]] -name = "accesskit_atspi_common" -version = "0.14.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "890d241cf51fc784f0ac5ac34dfc847421f8d39da6c7c91a0fcc987db62a8267" -dependencies = [ - "accesskit", - "accesskit_consumer", - "atspi-common", - "serde", - "thiserror 1.0.69", - "zvariant", -] - -[[package]] -name = "accesskit_consumer" -version = "0.31.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db81010a6895d8707f9072e6ce98070579b43b717193d2614014abd5cb17dd43" -dependencies = [ - "accesskit", - "hashbrown 0.15.5", -] - -[[package]] -name = "accesskit_macos" -version = "0.22.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0089e5c0ac0ca281e13ea374773898d9354cc28d15af9f0f7394d44a495b575" -dependencies = [ - "accesskit", - "accesskit_consumer", - "hashbrown 0.15.5", - "objc2 0.5.2", - "objc2-app-kit 0.2.2", - "objc2-foundation 0.2.2", -] - -[[package]] -name = "accesskit_unix" -version = "0.17.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301e55b39cfc15d9c48943ce5f572204a551646700d0e8efa424585f94fec528" -dependencies = [ - "accesskit", - "accesskit_atspi_common", - "async-channel", - "async-executor", - "async-task", - "atspi", - "futures-lite", - "futures-util", - "serde", - "zbus", -] - -[[package]] -name = "accesskit_windows" -version = "0.29.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2d63dd5041e49c363d83f5419a896ecb074d309c414036f616dc0b04faca971" -dependencies = [ - "accesskit", - "accesskit_consumer", - "hashbrown 0.15.5", - "static_assertions", - "windows 0.61.3", - "windows-core 0.61.2", -] - -[[package]] -name = "accesskit_winit" -version = "0.29.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8cfabe59d0eaca7412bfb1f70198dd31e3b0496fee7e15b066f9c36a1a140a0" -dependencies = [ - "accesskit", - "accesskit_macos", - "accesskit_unix", - "accesskit_windows", - "raw-window-handle", - "winit", -] - [[package]] name = "adler2" version = "2.0.1" @@ -383,56 +293,6 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" -[[package]] -name = "atspi" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c83247582e7508838caf5f316c00791eee0e15c0bf743e6880585b867e16815c" -dependencies = [ - "atspi-common", - "atspi-connection", - "atspi-proxies", -] - -[[package]] -name = "atspi-common" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33dfc05e7cdf90988a197803bf24f5788f94f7c94a69efa95683e8ffe76cfdfb" -dependencies = [ - "enumflags2", - "serde", - "static_assertions", - "zbus", - "zbus-lockstep", - "zbus-lockstep-macros", - "zbus_names", - "zvariant", -] - -[[package]] -name = "atspi-connection" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4193d51303d8332304056ae0004714256b46b6635a5c556109b319c0d3784938" -dependencies = [ - "atspi-common", - "atspi-proxies", - "futures-lite", - "zbus", -] - -[[package]] -name = "atspi-proxies" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2eebcb9e7e76f26d0bcfd6f0295e1cd1e6f33bedbc5698a971db8dc43d7751c" -dependencies = [ - "atspi-common", - "serde", - "zbus", -] - [[package]] name = "auto_enums" version = "0.8.7" @@ -638,12 +498,6 @@ dependencies = [ "syn", ] -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - [[package]] name = "byteorder-lite" version = "0.1.0" @@ -765,7 +619,7 @@ dependencies = [ "js-sys", "num-traits", "wasm-bindgen", - "windows-link 0.2.1", + "windows-link", ] [[package]] @@ -943,56 +797,6 @@ version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7704b5fdd17b18ae31c4c1da5a2e0305a2bf17b5249300a9ee9ed7b72114c636" -[[package]] -name = "cpp" -version = "0.5.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36bcac3d8234c1fb813358e83d1bb6b0290a3d2b3b5efc6b88bfeaf9d8eec17" -dependencies = [ - "cpp_macros", -] - -[[package]] -name = "cpp_build" -version = "0.5.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27f8638c97fbd79cc6fc80b616e0e74b49bac21014faed590bbc89b7e2676c90" -dependencies = [ - "cc", - "cpp_common", - "lazy_static", - "proc-macro2", - "regex", - "syn", - "unicode-xid", -] - -[[package]] -name = "cpp_common" -version = "0.5.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25fcfea2ee05889597d35e986c2ad0169694320ae5cc8f6d2640a4bb8a884560" -dependencies = [ - "lazy_static", - "proc-macro2", - "syn", -] - -[[package]] -name = "cpp_macros" -version = "0.5.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d156158fe86e274820f5a53bc9edb0885a6e7113909497aa8d883b69dd171871" -dependencies = [ - "aho-corasick", - "byteorder", - "cpp_common", - "lazy_static", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "crc32fast" version = "1.5.0" @@ -1641,7 +1445,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8" dependencies = [ "rustix 1.1.3", - "windows-link 0.2.1", + "windows-link", ] [[package]] @@ -1849,7 +1653,6 @@ version = "1.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8fd06c00fbdac3dd490cf5c10da7daad3820d775060a19ea277d8ab944a160b" dependencies = [ - "bytemuck", "calloop 0.14.3", "drm", "gbm", @@ -1858,31 +1661,11 @@ dependencies = [ "i-slint-core", "i-slint-renderer-femtovg", "input", - "memmap2", "nix", "raw-window-handle", "xkbcommon", ] -[[package]] -name = "i-slint-backend-qt" -version = "1.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c946891ff0bfa95a5944c7cfc18828b8e123edea1168301f1e1b5505aa82933e" -dependencies = [ - "const-field-offset", - "cpp", - "cpp_build", - "i-slint-common", - "i-slint-core", - "i-slint-core-macros", - "lyon_path", - "pin-project", - "pin-weak", - "qttypes", - "vtable", -] - [[package]] name = "i-slint-backend-selector" version = "1.14.1" @@ -1891,7 +1674,6 @@ checksum = "e138660c634d6bbdf98bb2d0cfa487cda28e032e133a2a2c974f1cc494198765" dependencies = [ "cfg-if", "i-slint-backend-linuxkms", - "i-slint-backend-qt", "i-slint-backend-winit", "i-slint-common", "i-slint-core", @@ -1904,9 +1686,6 @@ version = "1.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69bf9167fb1165942ef1f034e039645b60b07b23c0c76069cb83595f979243a4" dependencies = [ - "accesskit", - "accesskit_winit", - "bytemuck", "cfg-if", "cfg_aliases", "copypasta", @@ -1919,13 +1698,11 @@ dependencies = [ "i-slint-core-macros", "i-slint-renderer-femtovg", "i-slint-renderer-skia", - "imgref", "lyon_path", "muda", "objc2-app-kit 0.3.2", "pin-weak", "raw-window-handle", - "rgb", "scoped-tls-hkt", "scopeguard", "softbuffer", @@ -1986,14 +1763,12 @@ checksum = "dc140f1218cfc4451b9e8753306c42afbcaf0386cc888e53664c1a5f5330ae19" dependencies = [ "auto_enums", "bitflags 2.10.0", - "bytemuck", "cfg-if", "chrono", "clru", "const-field-offset", "derive_more", "euclid", - "fontdue", "i-slint-common", "i-slint-core-macros", "image", @@ -2013,7 +1788,6 @@ dependencies = [ "rgb", "scoped-tls-hkt", "scopeguard", - "skrifa", "slab", "strum", "sys-locale", @@ -2434,12 +2208,6 @@ dependencies = [ "smallvec", ] -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - [[package]] name = "lebe" version = "0.5.3" @@ -2469,7 +2237,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" dependencies = [ "cfg-if", - "windows-link 0.2.1", + "windows-link", ] [[package]] @@ -3473,17 +3241,6 @@ dependencies = [ "bytemuck", ] -[[package]] -name = "qttypes" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7edf5b38c97ad8900ad2a8418ee44b4adceaa866a4a3405e2f1c909871d7ebd" -dependencies = [ - "cpp", - "cpp_build", - "semver", -] - [[package]] name = "quick-error" version = "2.0.1" @@ -3497,7 +3254,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b66c2058c55a409d601666cffe35f04333cf1013010882cec174a7467cd4e21c" dependencies = [ "memchr", - "serde", ] [[package]] @@ -4020,7 +3776,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c35c4bdca2c42c69b21ceb416aa4ba76c3f54df30e9ce85dcad0742229422a6" dependencies = [ "const-field-offset", - "i-slint-backend-qt", "i-slint-backend-selector", "i-slint-core", "i-slint-core-macros", @@ -4208,12 +3963,6 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - [[package]] name = "strict-num" version = "0.1.1" @@ -4699,9 +4448,9 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" [[package]] name = "uuid" -version = "1.19.0" +version = "1.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e054861b4bd027cd373e18e8d8d8e6548085000e41290d95ce0c373a654b4a" +checksum = "ee48d38b119b0cd71fe4141b30f5ba9c7c5d9f4e7a3a8b4a674e4b6ef789976f" dependencies = [ "js-sys", "serde_core", @@ -5028,38 +4777,16 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows" -version = "0.61.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893" -dependencies = [ - "windows-collections 0.2.0", - "windows-core 0.61.2", - "windows-future 0.2.1", - "windows-link 0.1.3", - "windows-numerics 0.2.0", -] - [[package]] name = "windows" version = "0.62.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "527fadee13e0c05939a6a05d5bd6eec6cd2e3dbd648b9f8e447c6518133d8580" dependencies = [ - "windows-collections 0.3.2", + "windows-collections", "windows-core 0.62.2", - "windows-future 0.3.2", - "windows-numerics 0.3.1", -] - -[[package]] -name = "windows-collections" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8" -dependencies = [ - "windows-core 0.61.2", + "windows-future", + "windows-numerics", ] [[package]] @@ -5084,19 +4811,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-core" -version = "0.61.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" -dependencies = [ - "windows-implement 0.60.2", - "windows-interface 0.59.3", - "windows-link 0.1.3", - "windows-result 0.3.4", - "windows-strings 0.4.2", -] - [[package]] name = "windows-core" version = "0.62.2" @@ -5105,22 +4819,11 @@ checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" dependencies = [ "windows-implement 0.60.2", "windows-interface 0.59.3", - "windows-link 0.2.1", + "windows-link", "windows-result 0.4.1", "windows-strings 0.5.1", ] -[[package]] -name = "windows-future" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e" -dependencies = [ - "windows-core 0.61.2", - "windows-link 0.1.3", - "windows-threading 0.1.0", -] - [[package]] name = "windows-future" version = "0.3.2" @@ -5128,8 +4831,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1d6f90251fe18a279739e78025bd6ddc52a7e22f921070ccdc67dde84c605cb" dependencies = [ "windows-core 0.62.2", - "windows-link 0.2.1", - "windows-threading 0.2.1", + "windows-link", + "windows-threading", ] [[package]] @@ -5176,28 +4879,12 @@ dependencies = [ "syn", ] -[[package]] -name = "windows-link" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" - [[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" -[[package]] -name = "windows-numerics" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1" -dependencies = [ - "windows-core 0.61.2", - "windows-link 0.1.3", -] - [[package]] name = "windows-numerics" version = "0.3.1" @@ -5205,7 +4892,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e2e40844ac143cdb44aead537bbf727de9b044e107a0f1220392177d15b0f26" dependencies = [ "windows-core 0.62.2", - "windows-link 0.2.1", + "windows-link", ] [[package]] @@ -5217,22 +4904,13 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-result" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" -dependencies = [ - "windows-link 0.1.3", -] - [[package]] name = "windows-result" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" dependencies = [ - "windows-link 0.2.1", + "windows-link", ] [[package]] @@ -5245,22 +4923,13 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-strings" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" -dependencies = [ - "windows-link 0.1.3", -] - [[package]] name = "windows-strings" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" dependencies = [ - "windows-link 0.2.1", + "windows-link", ] [[package]] @@ -5314,7 +4983,7 @@ version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" dependencies = [ - "windows-link 0.2.1", + "windows-link", ] [[package]] @@ -5369,7 +5038,7 @@ version = "0.53.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" dependencies = [ - "windows-link 0.2.1", + "windows-link", "windows_aarch64_gnullvm 0.53.1", "windows_aarch64_msvc 0.53.1", "windows_i686_gnu 0.53.1", @@ -5380,22 +5049,13 @@ dependencies = [ "windows_x86_64_msvc 0.53.1", ] -[[package]] -name = "windows-threading" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b66463ad2e0ea3bbf808b7f1d371311c80e115c0b71d60efc142cafbcfb057a6" -dependencies = [ - "windows-link 0.1.3", -] - [[package]] name = "windows-threading" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37" dependencies = [ - "windows-link 0.2.1", + "windows-link", ] [[package]] @@ -5845,30 +5505,6 @@ dependencies = [ "zvariant", ] -[[package]] -name = "zbus-lockstep" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6998de05217a084b7578728a9443d04ea4cd80f2a0839b8d78770b76ccd45863" -dependencies = [ - "zbus_xml", - "zvariant", -] - -[[package]] -name = "zbus-lockstep-macros" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10da05367f3a7b7553c8cdf8fa91aee6b64afebe32b51c95177957efc47ca3a0" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "zbus-lockstep", - "zbus_xml", - "zvariant", -] - [[package]] name = "zbus_macros" version = "5.13.2" @@ -5895,18 +5531,6 @@ dependencies = [ "zvariant", ] -[[package]] -name = "zbus_xml" -version = "5.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "441a0064125265655bccc3a6af6bef56814d9277ac83fce48b1cd7e160b80eac" -dependencies = [ - "quick-xml", - "serde", - "zbus_names", - "zvariant", -] - [[package]] name = "zeno" version = "0.3.3" diff --git a/Cargo.toml b/Cargo.toml index 8f50d99..6a99692 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,14 @@ version = "0.0.1" edition = "2024" [dependencies] -slint = { version = "1.14" } +slint = { version = "1.14", default-features = false, features = ["backend-winit", "renderer-femtovg", "compat-1-2"] } [build-dependencies] slint-build = "1.14" + + +[profile.release] +opt-level = 'z' # 优化代码体积 +lto = true # 开启链接时优化 +codegen-units = 1 # 牺牲编译速度换取更好的代码质量 +strip = true # 自动移除调试符号 \ No newline at end of file diff --git a/ui/components/button.slint b/ui/components/button.slint index 87f8977..dad2c95 100644 --- a/ui/components/button.slint +++ b/ui/components/button.slint @@ -10,7 +10,7 @@ export component Button { in property variant: "default"; // default | destructive | outline | secondary | ghost in property size: "md"; // sm | md | lg in property disabled: false; - + // Callbacks callback clicked(); @@ -48,42 +48,20 @@ export component Button { border-radius: SpacingSystem.radius.md; border-width: variant == "outline" ? 1px : 0px; border-color: Theme.colors.border; - + // Smooth transitions - animate background { - duration: Animations.durations.fast; - easing: Animations.ease-in-out; + animate background { + duration: Animations.durations.fast; + easing: Animations.ease-in-out; } - - // Hover overlay - light mask - hover-overlay := Rectangle { - background: Colors.transparent; - border-radius: SpacingSystem.radius.md; - - animate background { - duration: Animations.durations.fast; - easing: Animations.ease-in-out; - } - } - - // Press overlay - darker mask - press-overlay := Rectangle { - background: Colors.transparent; - border-radius: SpacingSystem.radius.md; - - animate background { - duration: 100ms; - easing: Animations.ease-out; - } - } - + // Content layout HorizontalLayout { padding-left: btn-padding-x; padding-right: btn-padding-x; spacing: SpacingSystem.spacing.s2; alignment: center; - + // Button text Text { text: root.text; @@ -94,32 +72,39 @@ export component Button { horizontal-alignment: center; } } - + // Touch interaction area touch := TouchArea { enabled: !disabled; - + clicked => { root.clicked(); } } - - // States for visual feedback with color overlays - states [ - pressed when touch.pressed && !disabled: { - press-overlay.background: #00000040; // Dark overlay for press + + // Combined overlay for both hover and press effects + overlay := Rectangle { + width: 100%; + height: 100%; + border-radius: SpacingSystem.radius.md; + + // 直接根据状态设置背景色,不使用 states 块 + background: { + if disabled { + Colors.transparent + } else if touch.pressed { + #00000030 // 按压时深色 + } else if touch.has-hover { + #ffffff10 // 悬停时浅色 + } else { + Colors.transparent + } + }; + + animate background { + duration: 200ms; + easing: ease-in-out; } - hovered when touch.has-hover && !disabled && !touch.pressed: { - hover-overlay.background: #ffffff15; // Light overlay for hover - } - normal when !disabled: { - hover-overlay.background: Colors.transparent; - press-overlay.background: Colors.transparent; - } - disabled-state when disabled: { - hover-overlay.background: Colors.transparent; - press-overlay.background: Colors.transparent; - } - ] + } } } diff --git a/ui/demo.slint b/ui/demo.slint index 388e637..91ee63e 100644 --- a/ui/demo.slint +++ b/ui/demo.slint @@ -14,12 +14,12 @@ import { ToastContainer, ToastMessage } from "components/toast.slint"; export component Demo inherits Window { title: "Slint Shadcn UI - Task Manager Demo"; background: Theme.colors.background; - - // Window size settings - now resizable + + // Window size settings - reduced for lower memory usage min-width: 800px; min-height: 600px; - preferred-width: 1400px; - preferred-height: 900px; + preferred-width: 1000px; + preferred-height: 700px; // Application state in-out property new-task-title: ""; @@ -95,25 +95,27 @@ export component Demo inherits Window { Sidebar { items: nav-items; collapsed: sidebar-collapsed; - + item-clicked(index) => { if index == 0 { current-view = "tasks"; } else if index == 1 { current-view = "components"; } else if index == 2 { current-view = "settings"; } } - + toggle-collapsed => { sidebar-collapsed = !sidebar-collapsed; } } - - // Main content area - fixed height + + // Main content area Rectangle { background: Theme.colors.background; - + horizontal-stretch: 1; + vertical-stretch: 1; + Flickable { width: 100%; - height: parent.height; + height: 100%; viewport-height: content-layout.preferred-height; content-layout := VerticalLayout {