bevy-ui-builders 0.1.1

Declarative UI builders for Bevy with consistent styling and interaction handling
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
# Bevy UI Builders

[![Crates.io](https://img.shields.io/crates/v/bevy-ui-builders)](https://crates.io/crates/bevy-ui-builders)
[![Documentation](https://docs.rs/bevy-ui-builders/badge.svg)](https://docs.rs/bevy-ui-builders)
[![License](https://img.shields.io/crates/l/bevy-ui-builders)](LICENSE-MIT)

## Before using bevy-ui-builders

```rust
commands.spawn((
    Button,
    Node {
        width: Val::Px(200.0),
        height: Val::Px(65.0),
        justify_content: JustifyContent::Center,
        align_items: AlignItems::Center,
        border: UiRect::all(Val::Px(2.0)),
        margin: UiRect::all(Val::Px(10.0)),
        padding: UiRect::all(Val::Px(10.0)),
        ..default()
    },
    BackgroundColor(Color::srgb(0.15, 0.15, 0.15)),
    BorderColor(Color::BLACK),
)).with_children(|parent| {
    parent.spawn((
        Text::new("Click Me"),
        TextFont {
            font_size: 40.0,
            ..default()
        },
        TextColor(Color::srgb(0.9, 0.9, 0.9)),
    ));
});

// Plus 30+ more lines for hover system...
```

## After using bevy-ui-builders

```rust
// AFTER: With bevy-ui-builders (3 lines!)
use bevy_ui_builders::*;

ButtonBuilder::new("Click Me")
    .style(ButtonStyle::Primary)
    .build(parent);
```

**That's it!** Hover effects, styling, and interaction handling included.

## Production Use

These builders are used in **[Living Worlds](https://github.com/noahsabaj/livingworlds)**, a Steam game.

- **336+ uses** across 72 files
- Reduces repetitive UI code
- Familiar Rust builder pattern

## Quick Start

Add to your `Cargo.toml`:

```toml
[dependencies]
bevy = "0.16"
bevy-ui-builders = "0.1"
```

Add the plugin:

```rust
use bevy::prelude::*;
use bevy_ui_builders::UiBuilderPlugin;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(UiBuilderPlugin)
        .run();
}
```

## Complete Builder Catalog

### 1. ButtonBuilder - Styled Interactive Buttons

```rust
// Simple button
ButtonBuilder::new("Click Me").build(parent);

// Styled button with size
ButtonBuilder::new("Submit")
    .style(ButtonStyle::Primary)  // Primary, Secondary, Success, Danger, Warning, Ghost
    .size(ButtonSize::Large)       // Small, Medium, Large, XLarge
    .with_marker(SubmitButton)     // Add your own marker component
    .build(parent);

// Convenience functions
primary_button("Save").build(parent);
danger_button("Delete").build(parent);
ghost_button("Cancel").build(parent);
```

### 2. DialogBuilder - Modal Dialogs with Overlays

```rust
// Confirmation dialog
DialogBuilder::new(DialogType::Confirmation)
    .title("Delete Item?")
    .body("This action cannot be undone.")
    .danger_button("Delete")
    .cancel_button("Cancel")
    .dismissible(false)  // Can't click outside to close
    .z_index(1000)      // Layer above other UI
    .build(commands);

// Preset dialogs
use bevy_ui_builders::dialog::presets;
presets::error(commands, "File not found!");
presets::unsaved_changes(commands);
```

### 3. TextInputBuilder - Advanced Text Inputs

```rust
// Text input with validation
TextInputBuilder::new()
    .with_placeholder("Enter email...")
    .with_filter(InputFilter::Email)     // Email validation
    .with_max_length(100)
    .with_focus_group(FocusGroupId::LoginForm)  // Focus management
    .with_clear_button()                 // X button to clear
    .with_marker(EmailInput)
    .build(parent);

// Numeric input
text_input()
    .numeric_only()      // Only allows 0-9
    .with_value("0")
    .build(parent);
```

### 4. FormBuilder - Complete Forms with Validation

```rust
FormBuilder::new()
    .title("User Registration")
    .field(FieldType::Text, "username", "Username")
    .field(FieldType::Email, "email", "Email Address")
    .field(FieldType::Password, "password", "Password")
    .field(FieldType::Checkbox, "terms", "I accept the terms")
    .validation("username", ValidationRule::Required)
    .validation("username", ValidationRule::MinLength(3))
    .validation("email", ValidationRule::Required)
    .validation("email", ValidationRule::Email)
    .submit_button("Register")
    .cancel_button("Cancel")
    .build(parent);
```

### 5. SliderBuilder - Value Sliders with Formatting

```rust
// Percentage slider
SliderBuilder::new(0.5, 0.0..=1.0)
    .width(Val::Px(200.0))
    .with_label(ValueFormat::Percentage)  // Shows "50%"
    .with_marker(VolumeSlider)
    .build(parent);

// Custom format
slider(75.0, 0.0..=100.0)
    .with_label(ValueFormat::Custom(|v| format!("{:.0}°C", v)))
    .build(parent);
```

### 6. ProgressBarBuilder - Progress Indicators

```rust
// Basic progress bar
ProgressBarBuilder::new(0.75)  // 75% complete
    .style(ProgressBarStyle::Thick)
    .with_label()  // Shows "75%"
    .animated()    // Smooth transitions
    .build(parent);

// Custom styled
progress(loading_progress)
    .fill_color(Color::srgb(0.2, 0.8, 0.2))
    .track_color(Color::srgb(0.1, 0.1, 0.1))
    .with_label_text("Loading assets...")
    .build(parent);
```

### 7. PanelBuilder - Flexible Container Panels

```rust
// Card panel with title
PanelBuilder::new()
    .style(PanelStyle::Card)
    .width(Val::Px(400.0))
    .padding(UiRect::all(Val::Px(24.0)))
    .with_title("Settings")
    .build_with_children(parent, |panel| {
        // Add any children here
        LabelBuilder::new("Audio Settings").build(panel);
        SeparatorBuilder::new().build(panel);
        // More UI...
    });

// Transparent overlay panel
panel()
    .style(PanelStyle::Transparent)
    .position_type(PositionType::Absolute)
    .build(parent);
```

### 8. LabelBuilder - Consistent Text Labels

```rust
// Styled labels
LabelBuilder::new("Welcome!")
    .style(LabelStyle::Title)    // Title, Heading, Body, Caption
    .text_align(JustifyContent::Center)
    .margin(UiRect::bottom(Val::Px(20.0)))
    .build(parent);

// Status labels
label("Error: File not found")
    .style(LabelStyle::Error)    // Error, Success, Warning, Muted
    .build(parent);
```

### 9. SeparatorBuilder - Visual Dividers

```rust
// Horizontal separator
SeparatorBuilder::new()
    .style(SeparatorStyle::Dashed)
    .margin(UiRect::vertical(Val::Px(20.0)))
    .build(parent);

// Vertical divider
separator_vertical()
    .style(SeparatorStyle::Thick)
    .length(Val::Percent(80.0))
    .build(parent);
```

## Cleanup

Generic cleanup system:

```rust
// Before: 15 lines of cleanup per UI system
fn cleanup_menu(mut commands: Commands, query: Query<Entity, With<MenuRoot>>) {
    for entity in &query {
        commands.entity(entity).despawn();
    }
}

// After: One line, works for ANY component!
app.add_systems(OnExit(GameState::Menu), despawn_ui_entities::<MenuRoot>);
```

## Complete Example

```rust
use bevy::prelude::*;
use bevy_ui_builders::*;

#[derive(Component)]
struct LoginForm;

#[derive(Component)]
struct SubmitButton;

fn setup_ui(mut commands: Commands) {
    // Create a login form
    commands.spawn(Camera2d);

    commands
        .spawn((Node::default(), LoginForm))
        .with_children(|parent| {
            PanelBuilder::new()
                .style(PanelStyle::Card)
                .width(Val::Px(400.0))
                .padding(UiRect::all(Val::Px(32.0)))
                .with_title("Login")
                .build_with_children(parent, |panel| {
                    // Username input
                    LabelBuilder::new("Username")
                        .style(LabelStyle::Body)
                        .margin(UiRect::bottom(Val::Px(8.0)))
                        .build(panel);

                    TextInputBuilder::new()
                        .with_placeholder("Enter username...")
                        .with_focus_group(FocusGroupId::Custom(1))
                        .build(panel);

                    // Add spacing
                    SeparatorBuilder::new()
                        .style(SeparatorStyle::Invisible)
                        .margin(UiRect::vertical(Val::Px(16.0)))
                        .build(panel);

                    // Password input
                    LabelBuilder::new("Password")
                        .style(LabelStyle::Body)
                        .margin(UiRect::bottom(Val::Px(8.0)))
                        .build(panel);

                    TextInputBuilder::new()
                        .with_placeholder("Enter password...")
                        .with_focus_group(FocusGroupId::Custom(1))
                        .build(panel);

                    // Buttons
                    SeparatorBuilder::new()
                        .style(SeparatorStyle::Invisible)
                        .margin(UiRect::vertical(Val::Px(24.0)))
                        .build(panel);

                    ButtonBuilder::new("Login")
                        .style(ButtonStyle::Primary)
                        .size(ButtonSize::Large)
                        .with_marker(SubmitButton)
                        .build(panel);
                });
        });
}
```

## Feature Flags

Control which builders are included:

```toml
# Include everything (default)
bevy-ui-builders = "0.1"

# Or pick specific builders
bevy-ui-builders = { version = "0.1", default-features = false, features = ["button", "dialog"] }
```

Available features:
- `button` - ButtonBuilder
- `dialog` - DialogBuilder
- `text_input` - TextInputBuilder
- `form` - FormBuilder
- `slider` - SliderBuilder
- `progress` - ProgressBarBuilder
- `panel` - PanelBuilder
- `label` - LabelBuilder
- `separator` - SeparatorBuilder

## Why Choose bevy-ui-builders?

### We Fill The Gap

| Crate | Problem |
|-------|---------|
| `bevy_ui_builder` | Too basic, no text inputs or forms |
| `sickle_ui` | Complex macro system, steep learning curve |
| `bevy_dioxus` | Requires React/web knowledge |
| `bevy_egui` | Immediate mode, not native Bevy |
| **bevy-ui-builders** | **Just right!** Simple, powerful, pure Bevy |

### Unique Features

- **Automatic cleanup system** - Generic `despawn_ui_entities<T>`
- **Consistent styling** - Centralized colors and dimensions
- **Rich text inputs** - Filtering, validation, focus management
- **Type-safe markers** - Add your own components to any builder
- **Gateway architecture** - Clean module boundaries

## Bevy Version Support

| bevy-ui-builders | Bevy |
|-----------------|------|
| 0.1             | 0.16 |

## License

Dual-licensed under either:

- MIT license ([LICENSE-MIT]LICENSE-MIT)
- Apache License, Version 2.0 ([LICENSE-APACHE]LICENSE-APACHE)

at your option.

## Contributing

Contributions welcome! Please check [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, coding standards, and how to submit pull requests.

## Credits

Created by [Noah Sabaj](https://github.com/noahsabaj), the creator of [bevy-plugin-builder](https://github.com/noahsabaj/bevy-plugin-builder).

---

## The Bottom Line

```rust
// From 45 lines to 3. That's the power of builders.
ButtonBuilder::new("Play Game")
    .style(ButtonStyle::Primary)
    .build(parent);
```

## Complete Project Structure

```
bevy-ui-builders/
├── Cargo.toml              # Package manifest
├── README.md               # Public documentation
├── CLAUDE.md               # THIS FILE - AI assistant instructions
├── examples/               # Coming soon!
│   └── (examples will be added in v0.2.0)
└── src/
    ├── lib.rs              # Main library entry point
    ├── button/             # ButtonBuilder module
    │   ├── mod.rs          # Gateway (exports only)
    │   ├── builder.rs      # ButtonBuilder implementation
    │   ├── plugin.rs       # ButtonPlugin
    │   ├── systems.rs      # Button interaction systems
    │   └── types.rs        # Component types (StyledButton, etc.)
    ├── slider/             # SliderBuilder module
    │   ├── mod.rs          # Gateway
    │   ├── builder.rs      # SliderBuilder implementation
    │   ├── plugin.rs       # SliderPlugin
    │   ├── systems.rs      # Slider drag systems
    │   └── types.rs        # Slider, SliderHandle, SliderTrack
    ├── form/               # FormBuilder module
    │   ├── mod.rs          # Gateway
    │   ├── builder.rs      # FormBuilder implementation
    │   ├── field.rs        # Form field implementations
    │   └── types.rs        # FieldType, ValidationRule
    ├── dialog/             # DialogBuilder module
    │   ├── mod.rs          # Gateway
    │   ├── builder.rs      # DialogBuilder implementation
    │   ├── plugin.rs       # DialogPlugin
    │   ├── systems.rs      # Dialog interaction (ESC, overlay clicks)
    │   └── types.rs        # DialogOverlay, DialogType, button markers
    ├── text_input/         # TextInputBuilder module
    │   ├── mod.rs          # Gateway
    │   ├── builder.rs      # TextInputBuilder implementation
    │   ├── plugin.rs       # TextInputPlugin
    │   ├── systems.rs      # Focus management, validation
    │   └── types.rs        # InputFilter, TextInputFocus, etc.
    ├── progress/           # ProgressBarBuilder module
    │   ├── mod.rs          # Gateway
    │   ├── builder.rs      # ProgressBarBuilder implementation
    │   ├── plugin.rs       # ProgressBarPlugin
    │   ├── systems.rs      # Progress bar update systems
    │   └── types.rs        # ProgressBar, ProgressBarStyle
    ├── label/              # LabelBuilder module
    │   ├── mod.rs          # Gateway
    │   ├── builder.rs      # LabelBuilder implementation
    │   └── types.rs        # Label, LabelStyle
    ├── panel/              # PanelBuilder module
    │   ├── mod.rs          # Gateway
    │   ├── builder.rs      # PanelBuilder implementation
    │   └── types.rs        # Panel, PanelStyle
    ├── separator/          # SeparatorBuilder module
    │   ├── mod.rs          # Gateway
    │   ├── builder.rs      # SeparatorBuilder implementation
    │   └── types.rs        # Separator, SeparatorStyle, Orientation
    ├── styles/             # Centralized styling
    │   ├── mod.rs          # Gateway (exports colors & dimensions)
    │   ├── colors.rs       # Color constants (PRIMARY, SECONDARY, etc.)
    │   └── dimensions.rs   # Size constants (FONT_SIZE_*, PADDING_*, etc.)
    ├── systems/            # Shared systems
    │   ├── mod.rs          # Gateway
    │   ├── cleanup.rs      # Generic despawn_entities<T> system
    │   ├── hover.rs        # HoverPlugin for button effects
    │   └── interaction.rs  # Generic interaction handling
    └── utils/              # Utilities
        ├── mod.rs          # Gateway
        └── intrinsic.rs    # Intrinsic sizing utilities

Total: 48 Rust files across 13 modules
```