bevy_symbios_texture 0.3.0

Algorithmic texture generator for Bevy.
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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
//! Egui UI helpers for editing texture generator configs.
//!
//! Provides reusable widgets for every texture config type so any application
//! with `bevy_egui` can embed texture parameter controls without duplicating
//! editor code.
//!
//! # Signature convention
//!
//! Every config editor has the form:
//! ```text
//! pub fn xxx_config_editor(ui: &mut egui::Ui, cfg: &mut XxxConfig, id: egui::Id) -> (bool, bool)
//! ```
//!
//! - `id` — used as the collapsing-header id salt; build with `egui::Id::new(x)`
//!   or derive a child ID via `parent.with("label")`.
//! - Returns `(writeback, regen)`:
//!   - `writeback` — any widget changed (including mid-drag). Write the config
//!     back to your resource to prevent slider snap-back.
//!   - `regen` — a value was *committed*: drag ended or a non-drag widget changed.
//!     Only regenerate the texture when this is `true`.
//!
//! # Macro
//! All editor functions are generated by the [`impl_config_editor!`] declarative
//! macro, which maps a concise field description to the correct widget and
//! debouncing semantics.
//!
//! Enabled via the `egui` Cargo feature.

use bevy_egui::egui;

use crate::ashlar::AshlarConfig;
use crate::asphalt::AsphaltConfig;
use crate::bark::BarkConfig;
use crate::brick::BrickConfig;
use crate::cobblestone::CobblestoneConfig;
use crate::concrete::ConcreteConfig;
use crate::corrugated::CorrugatedConfig;
use crate::encaustic::{EncausticConfig, EncausticPattern};
use crate::ground::GroundConfig;
use crate::iron_grille::IronGrilleConfig;
use crate::leaf::LeafConfig;
use crate::marble::MarbleConfig;
use crate::metal::{MetalConfig, MetalStyle};
use crate::pavers::{PaversConfig, PaversLayout};
use crate::plank::PlankConfig;
use crate::rock::RockConfig;
use crate::shingle::ShingleConfig;
use crate::stained_glass::StainedGlassConfig;
use crate::stucco::StuccoConfig;
use crate::thatch::ThatchConfig;
use crate::twig::TwigConfig;
use crate::wainscoting::WainscotingConfig;
use crate::window::WindowConfig;

// ---------------------------------------------------------------------------
// Declarative macro for config editors
// ---------------------------------------------------------------------------

/// Generates a public editor function for a config struct.
///
/// # Widget kinds
///
/// | Kind | Widget | Flags |
/// |------|--------|-------|
/// | `slider(label, field, range)` | Debounced slider | wb on change, regen on commit |
/// | `slider_step(label, field, range, step)` | Debounced slider with step | same |
/// | `usize(label, field, range)` | Integer slider, immediate | both on change |
/// | `u32(label, field)` | Drag value, immediate | both on change |
/// | `color(label, field)` | Color picker, immediate | both on change |
/// | `bool(label, field)` | Checkbox, immediate | both on change |
/// | `separator()` | Horizontal rule | — |
/// | `label(text)` | Static text | — |
/// | `enum_select(label, field, [(Label, Value), …])` | Selectable row | both on click |
/// | `nested(editor_fn, field, salt)` | Delegate to sub-editor | merged |
macro_rules! impl_config_editor {
    (
        $(#[doc = $doc:expr])*
        fn $fn_name:ident, $Config:ty, $header:literal =>
        { $( $wname:ident $wargs:tt ),+ $(,)? }
    ) => {
        $(#[doc = $doc])*
        pub fn $fn_name(ui: &mut egui::Ui, cfg: &mut $Config, id: egui::Id) -> (bool, bool) {
            let mut wb = false;
            let mut regen = false;
            egui::CollapsingHeader::new($header)
                .id_salt(id)
                .show(ui, |ui| {
                    $( impl_config_editor!(@widget ui, cfg, id, wb, regen, $wname $wargs); )+
                });
            (wb, regen)
        }
    };

    // --- widget arms --------------------------------------------------------

    (@widget $ui:ident, $cfg:ident, $id:ident, $wb:ident, $regen:ident,
     slider ($label:expr, $field:ident, $range:expr)) => {
        slider_debounced(
            $ui,
            egui::Slider::new(&mut $cfg.$field, $range).text($label),
            &mut $wb,
            &mut $regen,
        );
    };
    (@widget $ui:ident, $cfg:ident, $id:ident, $wb:ident, $regen:ident,
     slider_step ($label:expr, $field:ident, $range:expr, $step:expr)) => {
        slider_debounced(
            $ui,
            egui::Slider::new(&mut $cfg.$field, $range).step_by($step).text($label),
            &mut $wb,
            &mut $regen,
        );
    };
    (@widget $ui:ident, $cfg:ident, $id:ident, $wb:ident, $regen:ident,
     usize ($label:expr, $field:ident, $range:expr)) => {
        usize_instant($ui, &mut $cfg.$field, $range, $label, &mut $wb, &mut $regen);
    };
    (@widget $ui:ident, $cfg:ident, $id:ident, $wb:ident, $regen:ident,
     u32 ($label:expr, $field:ident)) => {
        u32_instant($ui, &mut $cfg.$field, $label, &mut $wb, &mut $regen);
    };
    (@widget $ui:ident, $cfg:ident, $id:ident, $wb:ident, $regen:ident,
     color ($label:expr, $field:ident)) => {
        color_instant($ui, $label, &mut $cfg.$field, &mut $wb, &mut $regen);
    };
    (@widget $ui:ident, $cfg:ident, $id:ident, $wb:ident, $regen:ident,
     bool ($label:expr, $field:ident)) => {
        bool_instant($ui, &mut $cfg.$field, $label, &mut $wb, &mut $regen);
    };
    (@widget $ui:ident, $cfg:ident, $id:ident, $wb:ident, $regen:ident,
     separator ()) => {
        $ui.separator();
    };
    (@widget $ui:ident, $cfg:ident, $id:ident, $wb:ident, $regen:ident,
     label ($text:expr)) => {
        $ui.label($text);
    };
    (@widget $ui:ident, $cfg:ident, $id:ident, $wb:ident, $regen:ident,
     enum_select ($label:expr, $field:ident, [ $(($btn_label:expr, $variant:expr)),+ ])) => {
        $ui.horizontal(|ui| {
            ui.label($label);
            $(
                let selected = $cfg.$field == $variant;
                if ui.selectable_label(selected, $btn_label).clicked() && !selected {
                    $cfg.$field = $variant;
                    $wb = true;
                    $regen = true;
                }
            )+
        });
    };
    (@widget $ui:ident, $cfg:ident, $id:ident, $wb:ident, $regen:ident,
     nested ($editor_fn:ident, $field:ident, $salt:expr)) => {
        let (sub_wb, sub_regen) = $editor_fn($ui, &mut $cfg.$field, $id.with($salt));
        $wb |= sub_wb;
        $regen |= sub_regen;
    };
}

// ---------------------------------------------------------------------------
// Editor implementations — one macro invocation per config type
// ---------------------------------------------------------------------------

// Foliage card editors

impl_config_editor!(
    /// Renders all [`LeafConfig`] parameters inside a collapsing header.
    fn leaf_config_editor, LeafConfig, "Leaf Config" => {
        color("Base Color", color_base),
        color("Edge Color", color_edge),
        slider("Serration", serration_strength, 0.0..=0.5),
        slider("Vein Angle", vein_angle, 1.0..=5.0),
        slider("Vein Count", vein_count, 2.0..=12.0),
        slider("Lobe Count", lobe_count, 0.0..=6.0),
        slider("Lobe Depth", lobe_depth, 0.0..=1.0),
        slider("Micro Detail", micro_detail, 0.0..=1.0),
        slider("Normal Strength", normal_strength, 0.0..=8.0),
        slider("Petiole", petiole_length, 0.0..=0.3),
    }
);

impl_config_editor!(
    /// Renders all [`TwigConfig`] parameters inside a collapsing header,
    /// including an embedded [`leaf_config_editor`] for the twig's leaf appearance.
    fn twig_config_editor, TwigConfig, "Twig Config" => {
        color("Stem Color", stem_color),
        slider("Stem Width", stem_half_width, 0.005..=0.05),
        usize("Leaf Pairs", leaf_pairs, 1..=8),
        slider("Leaf Angle", leaf_angle, 0.0..=std::f64::consts::PI),
        slider("Leaf Scale", leaf_scale, 0.1..=0.6),
        slider("Stem Curve", stem_curve, 0.0..=0.15),
        bool("Sympodial", sympodial),
        nested(leaf_config_editor, leaf, "twig_leaf"),
    }
);

impl_config_editor!(
    /// Renders all [`BarkConfig`] parameters inside a collapsing header.
    fn bark_config_editor, BarkConfig, "Bark Config" => {
        color("Light Color", color_light),
        color("Dark Color", color_dark),
        slider("Scale", scale, 1.0..=12.0),
        slider("Warp H", warp_u, 0.0..=0.5),
        slider("Warp V", warp_v, 0.0..=1.5),
        slider("Normal Strength", normal_strength, 0.0..=8.0),
        usize("Octaves", octaves, 1..=8),
        separator(),
        label("Rhytidome Plates:"),
        slider("Furrow Blend", furrow_multiplier, 0.0..=1.0),
        slider("Plate Width", furrow_scale_u, 0.5..=6.0),
        slider("Plate Length", furrow_scale_v, 0.05..=1.0),
        slider("Plate Shape", furrow_shape, 0.1..=2.0),
    }
);

impl_config_editor!(
    /// Renders all [`WindowConfig`] parameters inside a collapsing header.
    ///
    /// Window is a foliage-card type with alpha masking; upload results with
    /// `map_to_images_card`.
    fn window_config_editor, WindowConfig, "Window Config" => {
        u32("Seed", seed),
        slider("Frame Width", frame_width, 0.0..=0.4),
        usize("Panes X", panes_x, 1..=6),
        usize("Panes Y", panes_y, 1..=6),
        slider("Mullion Thickness", mullion_thickness, 0.0..=0.2),
        slider("Corner Radius", corner_radius, 0.0..=0.4),
        slider("Glass Opacity", glass_opacity, 0.0..=1.0),
        slider("Grime", grime_level, 0.0..=1.0),
        color("Frame Color", color_frame),
        slider("Normal Strength", normal_strength, 0.0..=8.0),
    }
);

// Surface (tileable) texture editors

impl_config_editor!(
    /// Renders all [`GroundConfig`] parameters inside a collapsing header.
    fn ground_config_editor, GroundConfig, "Ground Config" => {
        u32("Seed", seed),
        slider("Macro Scale", macro_scale, 0.5..=8.0),
        usize("Macro Octaves", macro_octaves, 1..=8),
        slider("Micro Scale", micro_scale, 2.0..=20.0),
        usize("Micro Octaves", micro_octaves, 1..=6),
        slider("Micro Weight", micro_weight, 0.0..=1.0),
        color("Color Dry", color_dry),
        color("Color Moist", color_moist),
        slider("Normal Strength", normal_strength, 0.0..=8.0),
    }
);

impl_config_editor!(
    /// Renders all [`RockConfig`] parameters inside a collapsing header.
    fn rock_config_editor, RockConfig, "Rock Config" => {
        u32("Seed", seed),
        slider("Scale", scale, 0.5..=12.0),
        usize("Octaves", octaves, 1..=12),
        slider("Attenuation", attenuation, 0.5..=6.0),
        color("Color Gaps", color_light),
        color("Color Stone", color_dark),
        slider("Normal Strength", normal_strength, 0.0..=8.0),
    }
);

impl_config_editor!(
    /// Renders all [`BrickConfig`] parameters inside a collapsing header.
    fn brick_config_editor, BrickConfig, "Brick Config" => {
        u32("Seed", seed),
        slider_step("Scale (Rows)", scale, 1.0..=16.0, 1.0),
        slider("Row Offset", row_offset, 0.0..=1.0),
        slider("Aspect Ratio", aspect_ratio, 1.0..=4.0),
        slider("Mortar Size", mortar_size, 0.0..=0.4),
        slider("Bevel", bevel, 0.0..=1.0),
        slider("Color Variance", cell_variance, 0.0..=1.0),
        slider("Surface Roughness", roughness, 0.0..=1.0),
        color("Brick Color", color_brick),
        color("Mortar Color", color_mortar),
        slider("Normal Strength", normal_strength, 0.0..=8.0),
    }
);

impl_config_editor!(
    /// Renders all [`PlankConfig`] parameters inside a collapsing header.
    fn plank_config_editor, PlankConfig, "Plank Config" => {
        u32("Seed", seed),
        slider_step("Plank Count", plank_count, 1.0..=16.0, 1.0),
        slider("Grain Scale", grain_scale, 2.0..=32.0),
        slider("Joint Width", joint_width, 0.0..=0.3),
        slider("Stagger", stagger, 0.0..=1.0),
        slider("Knot Density", knot_density, 0.0..=1.0),
        slider("Grain Warp", grain_warp, 0.0..=1.0),
        color("Wood Light", color_wood_light),
        color("Wood Dark", color_wood_dark),
        slider("Normal Strength", normal_strength, 0.0..=8.0),
    }
);

impl_config_editor!(
    /// Renders all [`ShingleConfig`] parameters inside a collapsing header.
    fn shingle_config_editor, ShingleConfig, "Shingle Config" => {
        u32("Seed", seed),
        slider_step("Scale (Rows)", scale, 2.0..=16.0, 1.0),
        slider("Shape (Square→Scallop)", shape_profile, 0.0..=1.0),
        slider("Overlap", overlap, 0.0..=0.8),
        slider("Stagger", stagger, 0.0..=1.0),
        slider("Moss", moss_level, 0.0..=1.0),
        color("Tile Color", color_tile),
        color("Grout Color", color_grout),
        slider("Normal Strength", normal_strength, 0.0..=8.0),
    }
);

impl_config_editor!(
    /// Renders all [`StuccoConfig`] parameters inside a collapsing header.
    fn stucco_config_editor, StuccoConfig, "Stucco Config" => {
        u32("Seed", seed),
        slider("Scale", scale, 1.0..=20.0),
        usize("Octaves", octaves, 1..=10),
        slider("Roughness", roughness, 0.0..=1.0),
        color("Base Color", color_base),
        color("Shadow Color", color_shadow),
        slider("Normal Strength", normal_strength, 0.0..=6.0),
    }
);

impl_config_editor!(
    /// Renders all [`ConcreteConfig`] parameters inside a collapsing header.
    fn concrete_config_editor, ConcreteConfig, "Concrete Config" => {
        u32("Seed", seed),
        slider("Scale", scale, 1.0..=16.0),
        usize("Octaves", octaves, 1..=10),
        slider("Roughness", roughness, 0.0..=1.0),
        slider_step("Formwork Lines", formwork_lines, 0.0..=12.0, 1.0),
        slider("Formwork Depth", formwork_depth, 0.0..=0.5),
        slider("Pit Density", pit_density, 0.0..=0.45),
        color("Base Color", color_base),
        color("Pit Color", color_pit),
        slider("Normal Strength", normal_strength, 0.0..=6.0),
    }
);

impl_config_editor!(
    /// Renders all [`MetalConfig`] parameters inside a collapsing header.
    fn metal_config_editor, MetalConfig, "Metal Config" => {
        u32("Seed", seed),
        enum_select("Style:", style, [
            ("Brushed", MetalStyle::Brushed),
            ("Standing Seam", MetalStyle::StandingSeam)
        ]),
        slider("Scale", scale, 1.0..=16.0),
        slider_step("Seam Count", seam_count, 1.0..=16.0, 1.0),
        slider("Seam Sharpness", seam_sharpness, 0.5..=6.0),
        slider("Brush Stretch", brush_stretch, 1.0..=20.0),
        slider("Roughness", roughness, 0.0..=1.0),
        slider("Metallic", metallic, 0.0..=1.0),
        slider("Rust", rust_level, 0.0..=1.0),
        color("Metal Color", color_metal),
        color("Rust Color", color_rust),
        slider("Normal Strength", normal_strength, 0.0..=6.0),
    }
);

impl_config_editor!(
    /// Renders all [`PaversConfig`] parameters inside a collapsing header.
    fn pavers_config_editor, PaversConfig, "Pavers Config" => {
        u32("Seed", seed),
        enum_select("Layout:", layout, [
            ("Square", PaversLayout::Square),
            ("Hexagonal", PaversLayout::Hexagonal)
        ]),
        slider_step("Scale", scale, 1.0..=16.0, 1.0),
        slider("Aspect Ratio", aspect_ratio, 0.5..=3.0),
        slider("Grout Width", grout_width, 0.0..=0.35),
        slider("Bevel", bevel, 0.0..=1.0),
        slider("Color Variance", cell_variance, 0.0..=0.8),
        slider("Surface Roughness", roughness, 0.0..=1.0),
        color("Stone Color", color_stone),
        color("Grout Color", color_grout),
        slider("Normal Strength", normal_strength, 0.0..=8.0),
    }
);

impl_config_editor!(
    /// Renders all [`AshlarConfig`] parameters inside a collapsing header.
    fn ashlar_config_editor, AshlarConfig, "Ashlar Config" => {
        u32("Seed", seed),
        usize("Rows", rows, 2..=8),
        usize("Cols", cols, 2..=6),
        slider("Mortar Size", mortar_size, 0.005..=0.15),
        slider("Bevel", bevel, 0.0..=1.0),
        slider("Color Variance", cell_variance, 0.0..=1.0),
        slider("Chisel Depth", chisel_depth, 0.0..=1.0),
        slider("Roughness", roughness, 0.0..=1.0),
        color("Stone Color", color_stone),
        color("Mortar Color", color_mortar),
        slider("Normal Strength", normal_strength, 0.0..=8.0),
    }
);

impl_config_editor!(
    /// Renders all [`CobblestoneConfig`] parameters inside a collapsing header.
    fn cobblestone_config_editor, CobblestoneConfig, "Cobblestone Config" => {
        u32("Seed", seed),
        slider("Scale", scale, 2.0..=14.0),
        slider("Gap Width", gap_width, 0.01..=0.3),
        slider("Color Variance", cell_variance, 0.0..=1.0),
        slider("Roundness", roundness, 0.3..=2.5),
        color("Stone Color", color_stone),
        color("Mud Color", color_mud),
        slider("Normal Strength", normal_strength, 0.0..=8.0),
    }
);

impl_config_editor!(
    /// Renders all [`ThatchConfig`] parameters inside a collapsing header.
    fn thatch_config_editor, ThatchConfig, "Thatch Config" => {
        u32("Seed", seed),
        slider("Fibre Density", density, 3.0..=24.0),
        slider("Anisotropy", anisotropy, 2.0..=20.0),
        slider("Warp", warp_strength, 0.0..=0.6),
        slider("Layer Count", layer_count, 2.0..=20.0),
        slider("Layer Shadow", layer_shadow, 0.0..=1.0),
        color("Straw Color", color_straw),
        color("Shadow Color", color_shadow),
        slider("Normal Strength", normal_strength, 0.0..=6.0),
    }
);

impl_config_editor!(
    /// Renders all [`MarbleConfig`] parameters inside a collapsing header.
    fn marble_config_editor, MarbleConfig, "Marble Config" => {
        u32("Seed", seed),
        slider("Scale", scale, 0.5..=10.0),
        usize("Octaves", octaves, 2..=10),
        slider("Warp Strength", warp_strength, 0.0..=2.0),
        slider("Vein Frequency", vein_frequency, 0.5..=10.0),
        slider("Vein Sharpness", vein_sharpness, 0.3..=8.0),
        slider("Roughness", roughness, 0.0..=0.4),
        color("Base Color", color_base),
        color("Vein Color", color_vein),
        slider("Normal Strength", normal_strength, 0.0..=4.0),
    }
);

impl_config_editor!(
    /// Renders all [`CorrugatedConfig`] parameters inside a collapsing header.
    fn corrugated_config_editor, CorrugatedConfig, "Corrugated Metal Config" => {
        u32("Seed", seed),
        slider_step("Ridges", ridges, 2.0..=20.0, 1.0),
        slider("Ridge Depth", ridge_depth, 0.3..=2.5),
        slider("Roughness", roughness, 0.0..=1.0),
        slider("Rust", rust_level, 0.0..=1.0),
        slider("Metallic", metallic, 0.0..=1.0),
        color("Metal Color", color_metal),
        color("Rust Color", color_rust),
        slider("Normal Strength", normal_strength, 0.0..=6.0),
    }
);

impl_config_editor!(
    /// Renders all [`AsphaltConfig`] parameters inside a collapsing header.
    fn asphalt_config_editor, AsphaltConfig, "Asphalt Config" => {
        u32("Seed", seed),
        slider("Scale", scale, 1.0..=14.0),
        slider("Aggregate Density", aggregate_density, 0.02..=0.5),
        slider("Aggregate Scale", aggregate_scale, 4.0..=40.0),
        slider("Roughness", roughness, 0.5..=1.0),
        slider("Stain Level", stain_level, 0.0..=1.0),
        color("Base Color", color_base),
        color("Aggregate Color", color_aggregate),
        slider("Normal Strength", normal_strength, 0.0..=4.0),
    }
);

impl_config_editor!(
    /// Renders all [`WainscotingConfig`] parameters inside a collapsing header.
    fn wainscoting_config_editor, WainscotingConfig, "Wainscoting Config" => {
        u32("Seed", seed),
        usize("Panels X", panels_x, 1..=4),
        usize("Panels Y", panels_y, 1..=4),
        slider("Frame Width", frame_width, 0.05..=0.4),
        slider("Panel Inset", panel_inset, 0.0..=0.2),
        slider("Grain Scale", grain_scale, 4.0..=28.0),
        slider("Grain Warp", grain_warp, 0.0..=1.0),
        color("Wood Light", color_wood_light),
        color("Wood Dark", color_wood_dark),
        slider("Normal Strength", normal_strength, 0.0..=8.0),
    }
);

impl_config_editor!(
    /// Renders all [`StainedGlassConfig`] parameters inside a collapsing header.
    fn stained_glass_config_editor, StainedGlassConfig, "Stained Glass Config" => {
        u32("Seed", seed),
        usize("Cell Count", cell_count, 3..=30),
        slider("Lead Width", lead_width, 0.01..=0.15),
        slider("Saturation", saturation, 0.3..=1.0),
        slider("Glass Roughness", glass_roughness, 0.0..=0.2),
        slider("Grime", grime_level, 0.0..=0.6),
        slider("Normal Strength", normal_strength, 0.0..=4.0),
    }
);

impl_config_editor!(
    /// Renders all [`IronGrilleConfig`] parameters inside a collapsing header.
    fn iron_grille_config_editor, IronGrilleConfig, "Iron Grille Config" => {
        u32("Seed", seed),
        usize("Bars X", bars_x, 1..=12),
        usize("Bars Y", bars_y, 1..=12),
        slider("Bar Width", bar_width, 0.01..=0.25),
        bool("Round Bars", round_bars),
        slider("Rust", rust_level, 0.0..=1.0),
        color("Iron Color", color_iron),
        color("Rust Color", color_rust),
        slider("Normal Strength", normal_strength, 0.0..=6.0),
    }
);

impl_config_editor!(
    /// Renders all [`EncausticConfig`] parameters inside a collapsing header.
    fn encaustic_config_editor, EncausticConfig, "Encaustic Tile Config" => {
        u32("Seed", seed),
        slider_step("Scale", scale, 1.0..=12.0, 1.0),
        enum_select("Pattern:", pattern, [
            ("Checker", EncausticPattern::Checkerboard),
            ("Octagon", EncausticPattern::Octagon),
            ("Diamond", EncausticPattern::Diamond)
        ]),
        slider("Grout Width", grout_width, 0.01..=0.2),
        slider("Glaze Roughness", glaze_roughness, 0.0..=0.15),
        color("Color A", color_a),
        color("Color B", color_b),
        color("Grout Color", color_grout),
        slider("Normal Strength", normal_strength, 0.0..=6.0),
    }
);

// ---------------------------------------------------------------------------
// Shared helpers
// ---------------------------------------------------------------------------

/// Adds a slider with drag-aware debouncing.
///
/// - `writeback` accumulates on any `changed()` (including mid-drag) so the
///   caller can write the value back and prevent visual snap-back.
/// - `regen` accumulates only on `drag_stopped()` or a non-drag change, avoiding
///   unnecessary texture regeneration during continuous slider drags.
pub fn slider_debounced(
    ui: &mut egui::Ui,
    slider: impl egui::Widget,
    writeback: &mut bool,
    regen: &mut bool,
) {
    let r = ui.add(slider);
    *writeback |= r.changed();
    *regen |= r.drag_stopped() || (r.changed() && !r.dragged());
}

/// Horizontal labeled slider for `f32` values. Returns `true` on any change.
pub fn f32_slider(
    ui: &mut egui::Ui,
    val: &mut f32,
    label: &str,
    range: std::ops::RangeInclusive<f32>,
) -> bool {
    ui.horizontal(|ui| {
        ui.label(label);
        ui.add(egui::Slider::new(val, range)).changed()
    })
    .inner
}

/// Horizontal labeled slider for `f64` values. Returns `true` on any change.
pub fn f64_slider(
    ui: &mut egui::Ui,
    val: &mut f64,
    label: &str,
    range: std::ops::RangeInclusive<f64>,
) -> bool {
    ui.horizontal(|ui| {
        ui.label(label);
        ui.add(egui::Slider::new(val, range)).changed()
    })
    .inner
}

/// Horizontal labeled slider for `usize` values. Returns `true` on any change.
pub fn usize_slider(
    ui: &mut egui::Ui,
    val: &mut usize,
    label: &str,
    range: std::ops::RangeInclusive<usize>,
) -> bool {
    ui.horizontal(|ui| {
        ui.label(label);
        ui.add(egui::Slider::new(val, range)).changed()
    })
    .inner
}

/// Horizontal labeled drag value for `u32`. Returns `true` on any change.
pub fn u32_drag(ui: &mut egui::Ui, val: &mut u32, label: &str) -> bool {
    ui.horizontal(|ui| {
        ui.label(label);
        ui.add(egui::DragValue::new(val).speed(1.0)).changed()
    })
    .inner
}

// ---------------------------------------------------------------------------
// Private inline helpers used only within this module
// ---------------------------------------------------------------------------

/// Color picker that immediately sets both writeback and regen flags.
fn color_instant(
    ui: &mut egui::Ui,
    label: &str,
    color: &mut [f32; 3],
    wb: &mut bool,
    regen: &mut bool,
) {
    ui.horizontal(|ui| {
        ui.label(label);
        let r = ui.color_edit_button_rgb(color);
        *wb |= r.changed();
        *regen |= r.changed();
    });
}

/// Checkbox that immediately sets both writeback and regen flags.
fn bool_instant(ui: &mut egui::Ui, val: &mut bool, label: &str, wb: &mut bool, regen: &mut bool) {
    let r = ui.checkbox(val, label);
    *wb |= r.changed();
    *regen |= r.changed();
}

/// Integer usize slider that immediately sets both flags (integer steps are cheap to regen).
fn usize_instant(
    ui: &mut egui::Ui,
    val: &mut usize,
    range: std::ops::RangeInclusive<usize>,
    label: &str,
    wb: &mut bool,
    regen: &mut bool,
) {
    let r = ui.add(egui::Slider::new(val, range).text(label));
    *wb |= r.changed();
    *regen |= r.changed();
}

/// Integer u32 drag that immediately sets both flags.
fn u32_instant(ui: &mut egui::Ui, val: &mut u32, label: &str, wb: &mut bool, regen: &mut bool) {
    ui.horizontal(|ui| {
        ui.label(label);
        let r = ui.add(egui::DragValue::new(val).speed(1.0));
        *wb |= r.changed();
        *regen |= r.changed();
    });
}