137 lines
3.2 KiB
Markdown
137 lines
3.2 KiB
Markdown
# MCALC Agent Guidelines
|
|
|
|
## Project Overview
|
|
|
|
A simple Dioxus calculator application. Uses Dioxus 0.7 for UI with static CSS styling.
|
|
|
|
## Build Commands
|
|
|
|
```bash
|
|
# Development
|
|
cargo run # Run desktop app (default feature)
|
|
cargo run --features web # Run web version
|
|
|
|
# Build
|
|
cargo build # Debug build
|
|
cargo build --release # Release build
|
|
|
|
# Testing
|
|
cargo test # Run all tests
|
|
cargo test <test_name> # Run specific test
|
|
|
|
# Linting & Formatting
|
|
cargo fmt # Format code
|
|
cargo fmt -- --check # Check formatting without changes
|
|
cargo clippy # Run linter
|
|
cargo clippy -- -D warnings # Lint with deny warnings
|
|
```
|
|
|
|
## Code Style
|
|
|
|
### Formatting
|
|
- Use `cargo fmt` with default rustfmt settings
|
|
- 4-space indentation
|
|
- Maximum line length: 100 characters
|
|
|
|
### Naming Conventions
|
|
- Components: PascalCase (e.g., `Calculator`, `DisplayArea`)
|
|
- Functions/Methods: snake_case (e.g., `calculate_result`, `input_digit`)
|
|
- Signals: snake_case with `_` suffix convention (e.g., `first_num`, `operator`)
|
|
- Types/Enums: PascalCase
|
|
|
|
### Imports
|
|
- Group 1: `use dioxus::prelude::*` (Dioxus core)
|
|
- Group 2: `use crate::` (local modules)
|
|
- Standard library imports last
|
|
|
|
### Components (Dioxus 0.7)
|
|
- Prefix with `#[allow(non_snake_case)]` if needed
|
|
- Props must be owned values (use `String` not `&str`)
|
|
- Use `Signal<T>` for reactive state
|
|
- Components return `Element`
|
|
|
|
```rust
|
|
#[component]
|
|
fn MyComponent(mut value: Signal<String>) -> Element {
|
|
rsx! { div { "{value}" } }
|
|
}
|
|
```
|
|
|
|
### State Management
|
|
- Use `use_signal(|| initial_value)` for local state
|
|
- Use `.write()` for mutable access, `.read()` for references
|
|
- Prefer `*signal.write() = value` over `signal.set(value)` for direct mutation
|
|
|
|
### Error Handling
|
|
- Prefer early returns with `return` or `?` operator
|
|
- Use `Result<T, E>` for fallible operations
|
|
- Silent failures acceptable for user input parsing (graceful degradation)
|
|
|
|
### CSS Guidelines
|
|
- CSS files in `/assets/main.css`
|
|
- Use CSS custom properties (variables) for theming
|
|
- Follow BYTEMALTE design system colors when applicable
|
|
- Class naming: kebab-case (e.g., `btn-number`, `display-area`)
|
|
|
|
## File Structure
|
|
|
|
```
|
|
src/
|
|
main.rs # App entry point
|
|
ui.rs # UI components
|
|
logic.rs # Business logic
|
|
assets/
|
|
main.css # Global styles
|
|
public/ # Static assets served at root
|
|
```
|
|
|
|
## Design System (BYTEMALTE)
|
|
|
|
When modifying CSS, follow these conventions:
|
|
|
|
| Element | Border Radius |
|
|
|---------|---------------|
|
|
| Buttons | 8px |
|
|
| Cards | 16px |
|
|
| Inputs | 8px |
|
|
|
|
Colors:
|
|
- Primary: `#8888FF`
|
|
- Secondary: `#3DDC84`
|
|
- Background: `#0F172A`
|
|
- Surface: `#1E293B`
|
|
- Error: `#EF4444`
|
|
|
|
---
|
|
|
|
## Dioxus 0.7 Reference
|
|
|
|
### Components
|
|
```rust
|
|
#[component]
|
|
fn App() -> Element {
|
|
let mut count = use_signal(|| 0);
|
|
rsx! {
|
|
button { onclick: move |_| *count.write() += 1, "{count}" }
|
|
}
|
|
}
|
|
```
|
|
|
|
### Signals
|
|
```rust
|
|
let mut value = use_signal(|| String::new());
|
|
value(); // clone value
|
|
value.read(); // &T reference
|
|
value.write(); // &mut T
|
|
```
|
|
|
|
### RSX Patterns
|
|
```rust
|
|
rsx! {
|
|
div {
|
|
for item in items { span { "{item}" } }
|
|
if condition { p { "Shown" } }
|
|
}
|
|
}
|
|
```
|