bevy_symbios_texture 0.9.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
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
//! 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::broadleaf::BroadleafConfig;
use crate::cactus::CactusSkinConfig;
use crate::chain_link::ChainLinkConfig;
use crate::chitin::ChitinConfig;
use crate::cobblestone::CobblestoneConfig;
use crate::concrete::ConcreteConfig;
use crate::corrugated::CorrugatedConfig;
use crate::cracked_earth::CrackedEarthConfig;
use crate::enamel::EnamelConfig;
use crate::encaustic::{EncausticConfig, EncausticPattern};
use crate::fabric::{FabricConfig, WeaveKind};
use crate::flame::FlameConfig;
use crate::flower::FlowerConfig;
use crate::forest_floor::ForestFloorConfig;
use crate::frond::FrondConfig;
use crate::grass::GrassTuftConfig;
use crate::gravel::GravelConfig;
use crate::ground::GroundConfig;
use crate::ice::IceConfig;
use crate::iron_grille::IronGrilleConfig;
use crate::lava::LavaConfig;
use crate::leaf::LeafConfig;
use crate::leaf_sprite::LeafSpriteConfig;
use crate::lichen::LichenConfig;
use crate::log_end::LogEndConfig;
use crate::marble::MarbleConfig;
use crate::metal::{MetalConfig, MetalStyle};
use crate::moss::MossConfig;
use crate::needle::NeedleConfig;
use crate::noise::CellMetric;
use crate::obsidian::ObsidianConfig;
use crate::parquet::{ParquetConfig, ParquetLayout};
use crate::pavers::{PaversConfig, PaversLayout};
use crate::petal::PetalConfig;
use crate::plank::PlankConfig;
use crate::puff::PuffConfig;
use crate::reed::ReedConfig;
use crate::ring::RingConfig;
use crate::rock::RockConfig;
use crate::sand::SandConfig;
use crate::shard::ShardConfig;
use crate::shingle::ShingleConfig;
use crate::snow::SnowConfig;
use crate::snowflake::SnowflakeConfig;
use crate::soft_disc::SoftDiscConfig;
use crate::solar_panel::SolarPanelConfig;
use crate::spark::SparkConfig;
use crate::stained_glass::StainedGlassConfig;
use crate::stucco::StuccoConfig;
use crate::thatch::ThatchConfig;
use crate::truchet::TruchetConfig;
use crate::twig::TwigConfig;
use crate::wainscoting::WainscotingConfig;
use crate::weathering::{Corrosion, CreviceDirt, EdgeWear, Streaks, WeatheringConfig};
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
// ---------------------------------------------------------------------------

// Weathering layer editors — embedded by every generator that can age

impl_config_editor!(
    /// Renders all [`EdgeWear`] parameters inside a collapsing header.
    fn edge_wear_editor, EdgeWear, "Edge Wear" => {
        slider("Amount", amount, 0.0..=1.0),
        color("Substrate Color", color),
        slider("Threshold", threshold, 0.0..=1.0),
        slider("Breakup Scale", breakup_scale, 1.0..=32.0),
        slider("Roughness", roughness, 0.0..=1.0),
        slider("Metallic", metallic, 0.0..=1.0),
    }
);

impl_config_editor!(
    /// Renders all [`Corrosion`] parameters inside a collapsing header.
    fn corrosion_editor, Corrosion, "Corrosion" => {
        slider("Amount", amount, 0.0..=1.0),
        color("Corrosion Color", color),
        slider("Coverage", coverage, 0.0..=1.0),
        slider("Spread", spread, 0.0..=0.25),
        slider("Barrier Scale", barrier_scale, 1.0..=24.0),
        slider("Crust Relief", relief, 0.0..=0.5),
        slider("Roughness", roughness, 0.0..=1.0),
        slider("Metallic", metallic, 0.0..=1.0),
    }
);

impl_config_editor!(
    /// Renders all [`CreviceDirt`] parameters inside a collapsing header.
    fn crevice_dirt_editor, CreviceDirt, "Crevice Dirt" => {
        slider("Amount", amount, 0.0..=1.0),
        color("Grime Color", color),
        slider("Depth", depth, 0.005..=0.25),
        slider("Gravity", gravity, 0.0..=1.0),
        slider("Roughness", roughness, 0.0..=1.0),
        slider("Occlusion", occlusion, 0.0..=1.0),
    }
);

impl_config_editor!(
    /// Renders all [`Streaks`] parameters inside a collapsing header.
    fn streaks_editor, Streaks, "Streaks" => {
        slider("Amount", amount, 0.0..=1.0),
        color("Stain Color", color),
        slider("Density", density, 0.0..=1.0),
        slider("Length", length, 0.0..=1.0),
        slider("Wander", wander, 0.0..=4.0),
        slider("Roughness", roughness, 0.0..=1.0),
    }
);

impl_config_editor!(
    /// Renders all [`WeatheringConfig`] layers inside a collapsing header.
    ///
    /// Every layer defaults to an amount of zero, so an untouched weathering
    /// block leaves the material exactly as the generator drew it.
    fn weathering_config_editor, WeatheringConfig, "Weathering" => {
        u32("Seed", seed),
        nested(edge_wear_editor, edge_wear, "weather_wear"),
        nested(corrosion_editor, corrosion, "weather_corrosion"),
        nested(crevice_dirt_editor, crevice_dirt, "weather_dirt"),
        nested(streaks_editor, streaks, "weather_streaks"),
    }
);

// 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 [`LogEndConfig`] parameters inside a collapsing header.
    fn log_end_config_editor, LogEndConfig, "Log End Config" => {
        u32("Seed", seed),
        slider("Ring Count", ring_count, 4.0..=30.0),
        slider("Ring Warp", ring_warp, 0.0..=1.0),
        slider("Ring Contrast", ring_contrast, 0.5..=4.0),
        slider("Crack Count", crack_count, 0.0..=12.0),
        slider("Bark Width", bark_width, 0.02..=0.2),
        color("Earlywood", color_early),
        color("Latewood", color_late),
        color("Bark", color_bark),
        slider("Normal Strength", normal_strength, 0.5..=6.0),
    }
);

impl_config_editor!(
    /// Renders all [`ChainLinkConfig`] parameters inside a collapsing header.
    fn chain_link_config_editor, ChainLinkConfig, "Chain-Link Config" => {
        u32("Seed", seed),
        slider("Cell Count", cell_count, 4.0..=16.0),
        slider("Wire Radius", wire_radius, 0.02..=0.2),
        slider("Weave Depth", weave_depth, 0.0..=1.0),
        slider("Rust Level", rust_level, 0.0..=1.0),
        color("Wire Color", color_wire),
        color("Rust Color", color_rust),
        slider("Normal Strength", normal_strength, 0.5..=6.0),
    }
);

impl_config_editor!(
    /// Renders all [`LavaConfig`] parameters inside a collapsing header.
    fn lava_config_editor, LavaConfig, "Lava Config" => {
        u32("Seed", seed),
        slider("Plate Scale", plate_scale, 3.0..=12.0),
        slider("Crack Width", crack_width, 0.02..=0.3),
        slider("Glow Falloff", glow_falloff, 0.5..=4.0),
        color("Crust Color", color_crust),
        color("Glow Color", color_glow),
        slider("Emissive Intensity", emissive_intensity, 0.0..=4.0),
        slider("Normal Strength", normal_strength, 0.5..=6.0),
    }
);

impl_config_editor!(
    /// Renders all [`IceConfig`] parameters inside a collapsing header.
    fn ice_config_editor, IceConfig, "Ice Config" => {
        u32("Seed", seed),
        slider("Scale", scale, 1.0..=8.0),
        slider("Crack Density", crack_density, 1.0..=8.0),
        slider("Vein Sharpness", vein_sharpness, 2.0..=12.0),
        slider("Frost Level", frost_level, 0.0..=1.0),
        color("Ice Color", color_ice),
        color("Crack Color", color_crack),
        slider("Normal Strength", normal_strength, 0.0..=4.0),
    }
);

impl_config_editor!(
    /// Renders all [`SnowConfig`] parameters inside a collapsing header.
    fn snow_config_editor, SnowConfig, "Snow Config" => {
        u32("Seed", seed),
        slider("Drift Scale", drift_scale, 1.0..=6.0),
        usize("Drift Octaves", drift_octaves, 2..=6),
        slider("Sparkle Density", sparkle_density, 0.0..=0.5),
        slider("Crust Roughness", crust_roughness, 0.5..=1.0),
        color("Snow Color", color_snow),
        color("Shadow Color", color_shadow),
        slider("Normal Strength", normal_strength, 0.5..=5.0),
    }
);

impl_config_editor!(
    /// Renders all [`SandConfig`] parameters inside a collapsing header.
    fn sand_config_editor, SandConfig, "Sand Config" => {
        u32("Seed", seed),
        slider("Ripple Count", ripple_count, 4.0..=24.0),
        slider("Ripple Warp", ripple_warp, 0.0..=1.5),
        slider("Grain Density", grain_density, 0.0..=0.5),
        slider("Grain Scale", grain_scale, 8.0..=48.0),
        color("Crest Color", color_crest),
        color("Trough Color", color_trough),
        slider("Normal Strength", normal_strength, 0.5..=6.0),
    }
);

impl_config_editor!(
    /// Renders all [`FabricConfig`] parameters inside a collapsing header.
    fn fabric_config_editor, FabricConfig, "Fabric Config" => {
        u32("Seed", seed),
        enum_select("Weave:", weave, [
            ("Plain", WeaveKind::Plain),
            ("Twill", WeaveKind::Twill),
            ("Satin", WeaveKind::Satin),
            ("Basket", WeaveKind::Basket)
        ]),
        slider("Thread Count", thread_count, 8.0..=64.0),
        slider("Thread Width", thread_width, 0.3..=0.98),
        slider("Weave Contrast", weave_contrast, 0.0..=1.0),
        slider("Fuzz", fuzz, 0.0..=1.0),
        color("Warp Color", color_warp),
        color("Weft Color", color_weft),
        nested(weathering_config_editor, weathering, "fabric_weather"),
        slider("Normal Strength", normal_strength, 0.5..=6.0),
    }
);

impl_config_editor!(
    /// Renders all [`FlowerConfig`] parameters inside a collapsing header.
    fn flower_config_editor, FlowerConfig, "Flower Config" => {
        u32("Seed", seed),
        usize("Atlas Rows", variant_rows, 1..=16),
        usize("Atlas Cols", variant_cols, 1..=16),
        usize("Petal Count", petal_count, 4..=12),
        slider("Center Radius", center_radius, 0.05..=0.3),
        color("Center Color", center_color),
        slider("Dot Density", dot_density, 0.0..=1.0),
        slider("Normal Strength", normal_strength, 0.0..=4.0),
        nested(petal_config_editor, petal, "flower_petal"),
    }
);

impl_config_editor!(
    /// Renders all [`FlameConfig`] parameters inside a collapsing header.
    fn flame_config_editor, FlameConfig, "Flame Config" => {
        u32("Seed", seed),
        usize("Atlas Rows", variant_rows, 1..=16),
        usize("Atlas Cols", variant_cols, 1..=16),
        slider("Elongation", elongation, 1.0..=3.0),
        slider("Turbulence", turbulence, 0.0..=1.5),
        slider("Lean Jitter", lean_jitter, 0.0..=0.5),
        slider("Falloff", falloff, 0.5..=4.0),
        color("Core Color", color_core),
        color("Mid Color", color_mid),
        color("Tip Color", color_tip),
        slider("Normal Strength", normal_strength, 0.0..=4.0),
    }
);

impl_config_editor!(
    /// Renders all [`LeafSpriteConfig`] parameters inside a collapsing header.
    fn leaf_sprite_config_editor, LeafSpriteConfig, "Leaf Sprite Config" => {
        u32("Seed", seed),
        usize("Atlas Rows", variant_rows, 1..=16),
        usize("Atlas Cols", variant_cols, 1..=16),
        slider("Shape Jitter", shape_jitter, 0.0..=1.0),
        slider("Tint Jitter", tint_jitter, 0.0..=1.0),
        nested(leaf_config_editor, leaf, "leaf_sprite_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),
        usize("Warp Octaves", warp_octaves, 1..=6),
        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),
        nested(weathering_config_editor, weathering, "rock_weather"),
        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),
        nested(weathering_config_editor, weathering, "brick_weather"),
        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),
        nested(weathering_config_editor, weathering, "shingle_weather"),
        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),
        nested(weathering_config_editor, weathering, "stucco_weather"),
        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),
        nested(weathering_config_editor, weathering, "concrete_weather"),
        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),
            ("Hammered", MetalStyle::Hammered),
            ("Diamond Plate", MetalStyle::DiamondPlate),
            ("Riveted", MetalStyle::Riveted),
            ("Perforated", MetalStyle::Perforated)
        ]),
        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("Rivet Size", rivet_size, 0.05..=0.9),
        slider("Hole Size", hole_size, 0.05..=0.9),
        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),
        nested(weathering_config_editor, weathering, "metal_weather"),
        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),
        nested(weathering_config_editor, weathering, "pavers_weather"),
        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),
        nested(weathering_config_editor, weathering, "ashlar_weather"),
        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),
        nested(weathering_config_editor, weathering, "cobblestone_weather"),
        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),
        nested(weathering_config_editor, weathering, "thatch_weather"),
        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),
        usize("Warp Octaves", warp_octaves, 1..=6),
        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),
        nested(weathering_config_editor, weathering, "marble_weather"),
        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),
        nested(weathering_config_editor, weathering, "corrugated_weather"),
        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),
        nested(weathering_config_editor, weathering, "asphalt_weather"),
        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),
        nested(weathering_config_editor, weathering, "wainscoting_weather"),
        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),
        nested(weathering_config_editor, weathering, "encaustic_weather"),
        slider("Normal Strength", normal_strength, 0.0..=6.0),
    }
);

// Sprite atlas editors

impl_config_editor!(
    /// Renders all [`SoftDiscConfig`] parameters inside a collapsing header.
    fn soft_disc_config_editor, SoftDiscConfig, "Soft Disc Config" => {
        u32("Seed", seed),
        usize("Variant Rows", variant_rows, 1..=16),
        usize("Variant Cols", variant_cols, 1..=16),
        color("Core Color", color_core),
        color("Halo Color", color_halo),
        slider("Core Radius", core_radius, 0.0..=0.9),
        slider("Falloff", falloff, 0.3..=8.0),
        slider("Ellipticity", ellipticity, 0.0..=0.6),
        slider("Scale Jitter", scale_jitter, 0.0..=0.5),
        slider("Normal Strength", normal_strength, 0.0..=4.0),
    }
);

impl_config_editor!(
    /// Renders all [`SparkConfig`] parameters inside a collapsing header.
    fn spark_config_editor, SparkConfig, "Spark Config" => {
        u32("Seed", seed),
        usize("Variant Rows", variant_rows, 1..=16),
        usize("Variant Cols", variant_cols, 1..=16),
        usize("Points", points, 2..=12),
        color("Core Color", color_core),
        color("Tip Color", color_tip),
        slider("Core Radius", core_radius, 0.02..=0.5),
        slider("Arm Sharpness", arm_sharpness, 0.5..=10.0),
        slider("Falloff", falloff, 0.5..=6.0),
        slider("Length Jitter", length_jitter, 0.0..=0.8),
        slider("Normal Strength", normal_strength, 0.0..=4.0),
    }
);

impl_config_editor!(
    /// Renders all [`SnowflakeConfig`] parameters inside a collapsing header.
    fn snowflake_config_editor, SnowflakeConfig, "Snowflake Config" => {
        u32("Seed", seed),
        usize("Variant Rows", variant_rows, 1..=16),
        usize("Variant Cols", variant_cols, 1..=16),
        usize("Arms", arms, 3..=8),
        color("Color", color),
        slider("Core Radius", core_radius, 0.0..=0.4),
        slider("Arm Width", arm_width, 0.01..=0.12),
        usize("Branch Pairs", branch_pairs, 0..=5),
        slider("Branch Angle", branch_angle, 0.3..=1.4),
        slider("Branch Scale", branch_scale, 0.1..=1.0),
        slider("Softness", softness, 0.005..=0.08),
        slider("Normal Strength", normal_strength, 0.0..=4.0),
    }
);

impl_config_editor!(
    /// Renders all [`PuffConfig`] parameters inside a collapsing header.
    fn puff_config_editor, PuffConfig, "Puff Config" => {
        u32("Seed", seed),
        usize("Variant Rows", variant_rows, 1..=16),
        usize("Variant Cols", variant_cols, 1..=16),
        color("Base Color", color_base),
        color("Shadow Color", color_shadow),
        slider("Noise Scale", noise_scale, 1.0..=8.0),
        usize("Octaves", octaves, 1..=8),
        slider("Warp", warp, 0.0..=1.5),
        slider("Density", density, 0.0..=1.0),
        slider("Edge Falloff", edge_falloff, 0.5..=6.0),
        slider("Contrast", contrast, 0.5..=4.0),
        slider("Normal Strength", normal_strength, 0.0..=4.0),
    }
);

impl_config_editor!(
    /// Renders all [`RingConfig`] parameters inside a collapsing header.
    fn ring_config_editor, RingConfig, "Ring Config" => {
        u32("Seed", seed),
        usize("Variant Rows", variant_rows, 1..=16),
        usize("Variant Cols", variant_cols, 1..=16),
        color("Color", color),
        slider("Radius", radius, 0.1..=0.9),
        slider("Thickness", thickness, 0.01..=0.5),
        slider("Falloff", falloff, 0.5..=6.0),
        slider("Waviness", waviness, 0.0..=0.3),
        usize("Wave Count", wave_count, 2..=16),
        slider("Radius Jitter", radius_jitter, 0.0..=0.4),
        slider("Normal Strength", normal_strength, 0.0..=4.0),
    }
);

impl_config_editor!(
    /// Renders all [`CactusSkinConfig`] parameters inside a collapsing header.
    fn cactus_config_editor, CactusSkinConfig, "Cactus Skin Config" => {
        u32("Seed", seed),
        usize("Rib Count", rib_count, 3..=40),
        usize("Areole Rows", areole_rows, 2..=40),
        slider("Rib Depth", rib_depth, 0.0..=1.0),
        slider("Rib Sharpness", rib_sharpness, 0.3..=3.0),
        color("Skin Color", color_skin),
        color("Valley Color", color_valley),
        color("Areole Color", color_areole),
        color("Spine Color", color_spine),
        slider("Areole Size", areole_size, 0.005..=0.08),
        slider("Spine Reach", spine_reach, 1.0..=6.0),
        usize("Spine Count", spine_count, 0..=24),
        slider("Waxiness", waxiness, 0.0..=1.0),
        slider("Normal Strength", normal_strength, 0.0..=4.0),
    }
);

impl_config_editor!(
    /// Renders all [`FrondConfig`] parameters inside a collapsing header.
    fn frond_config_editor, FrondConfig, "Frond Config" => {
        u32("Seed", seed),
        usize("Variant Rows", variant_rows, 1..=16),
        usize("Variant Cols", variant_cols, 1..=16),
        color("Base Color", color_base),
        color("Edge Color", color_edge),
        slider("Width", width, 0.04..=0.3),
        slider("Tip Taper", tip_taper, 0.4..=3.0),
        slider("Midrib Width", midrib_width, 0.05..=0.5),
        slider("Vein Count", vein_count, 0.0..=20.0),
        slider("Lobe Count", lobe_count, 0.0..=12.0),
        slider("Lobe Depth", lobe_depth, 0.0..=0.6),
        slider("Normal Strength", normal_strength, 0.0..=4.0),
    }
);

impl_config_editor!(
    /// Renders all [`GrassTuftConfig`] parameters inside a collapsing header.
    fn grass_config_editor, GrassTuftConfig, "Grass Tuft Config" => {
        u32("Seed", seed),
        usize("Variant Rows", variant_rows, 1..=16),
        usize("Variant Cols", variant_cols, 1..=16),
        usize("Blade Count", blade_count, 1..=24),
        color("Base Color", color_base),
        color("Tip Color", color_tip),
        color("Dry Color", color_dry),
        slider("Blade Width", blade_width, 0.01..=0.12),
        slider("Blade Taper", blade_taper, 0.5..=4.0),
        slider("Height Min", height_min, 0.2..=1.0),
        slider("Height Max", height_max, 0.2..=1.0),
        slider("Fan Spread", fan_spread, 0.0..=0.5),
        slider("Curve", curve, 0.0..=0.5),
        slider("Base Spread", base_spread, 0.0..=0.4),
        slider("Dry Fraction", dry_fraction, 0.0..=1.0),
        slider("Normal Strength", normal_strength, 0.0..=4.0),
    }
);

impl_config_editor!(
    /// Renders all [`MossConfig`] parameters inside a collapsing header.
    fn moss_config_editor, MossConfig, "Moss Config" => {
        u32("Seed", seed),
        slider("Cushion Scale", cushion_scale, 0.5..=16.0),
        usize("Cushion Octaves", cushion_octaves, 1..=10),
        slider("Filament Scale", filament_scale, 4.0..=64.0),
        usize("Filament Octaves", filament_octaves, 1..=10),
        slider("Filament Weight", filament_weight, 0.0..=1.0),
        color("Deep Color", color_deep),
        color("Tip Color", color_tip),
        color("Dry Color", color_dry),
        slider("Dry Patches", dry_patches, 0.0..=1.0),
        slider("Dry Scale", dry_scale, 0.5..=12.0),
        slider("Cushion Depth", cushion_depth, 0.0..=1.0),
        slider("Normal Strength", normal_strength, 0.0..=4.0),
    }
);

impl_config_editor!(
    /// Renders all [`LichenConfig`] parameters inside a collapsing header.
    fn lichen_config_editor, LichenConfig, "Lichen Config" => {
        u32("Seed", seed),
        slider("Patch Scale", patch_scale, 0.5..=16.0),
        usize("Patch Octaves", patch_octaves, 1..=10),
        slider("Coverage", coverage, 0.0..=1.0),
        slider("Rim Width", rim_width, 0.0..=0.4),
        slider("Species Scale", species_scale, 0.3..=8.0),
        color("Rock Color", color_rock),
        color("Lichen Color A", color_lichen_a),
        color("Lichen Color B", color_lichen_b),
        color("Rim Color", color_rim),
        slider("Grain Scale", grain_scale, 4.0..=80.0),
        slider("Grain Strength", grain_strength, 0.0..=1.0),
        slider("Relief", relief, 0.0..=1.0),
        slider("Normal Strength", normal_strength, 0.0..=4.0),
    }
);

impl_config_editor!(
    /// Renders all [`ReedConfig`] parameters inside a collapsing header.
    fn reed_config_editor, ReedConfig, "Reed Config" => {
        u32("Seed", seed),
        usize("Variant Rows", variant_rows, 1..=16),
        usize("Variant Cols", variant_cols, 1..=16),
        usize("Blade Count", blade_count, 1..=12),
        color("Base Color", color_base),
        color("Tip Color", color_tip),
        color("Catkin Color", color_catkin),
        slider("Blade Width", blade_width, 0.008..=0.08),
        slider("Height Min", height_min, 0.3..=1.0),
        slider("Height Max", height_max, 0.3..=1.0),
        slider("Lean", lean, 0.0..=0.3),
        slider("Tip Fraction", tip_fraction, 0.05..=0.8),
        slider("Catkin Share", catkin_share, 0.0..=1.0),
        slider("Catkin Length", catkin_length, 0.0..=0.4),
        slider("Catkin Width", catkin_width, 0.005..=0.06),
        slider("Normal Strength", normal_strength, 0.0..=4.0),
    }
);

impl_config_editor!(
    /// Renders all [`NeedleConfig`] parameters inside a collapsing header.
    fn needle_config_editor, NeedleConfig, "Needle Config" => {
        u32("Seed", seed),
        usize("Variant Rows", variant_rows, 1..=16),
        usize("Variant Cols", variant_cols, 1..=16),
        usize("Pair Count", pair_count, 1..=24),
        color("Base Color", color_base),
        color("Tip Color", color_tip),
        color("Shoot Color", color_shoot),
        slider("Needle Angle", needle_angle, 5.0..=85.0),
        slider("Needle Length", needle_length, 0.05..=0.6),
        slider("Needle Width", needle_width, 0.002..=0.03),
        slider("Length Taper", length_taper, 0.0..=1.0),
        slider("Shoot Length", shoot_length, 0.2..=1.0),
        slider("Shoot Width", shoot_width, 0.002..=0.04),
        slider("Normal Strength", normal_strength, 0.0..=4.0),
    }
);

impl_config_editor!(
    /// Renders all [`BroadleafConfig`] parameters inside a collapsing header.
    fn broadleaf_config_editor, BroadleafConfig, "Broadleaf Config" => {
        u32("Seed", seed),
        usize("Variant Rows", variant_rows, 1..=16),
        usize("Variant Cols", variant_cols, 1..=16),
        color("Base Color", color_base),
        color("Edge Color", color_edge),
        slider_step("Lobe Count", lobe_count, 1.0..=9.0, 1.0),
        slider("Lobe Depth", lobe_depth, 0.0..=0.8),
        slider("Fan Angle", fan_angle, 30.0..=110.0),
        slider("Radius", radius, 0.3..=1.0),
        slider("Base Notch", base_notch, 0.0..=0.5),
        slider("Vein Width", vein_width, 0.01..=0.2),
        slider("Petiole Length", petiole_length, 0.0..=0.3),
        slider("Normal Strength", normal_strength, 0.0..=4.0),
    }
);

impl_config_editor!(
    /// Renders all [`PetalConfig`] parameters inside a collapsing header.
    fn petal_config_editor, PetalConfig, "Petal Config" => {
        u32("Seed", seed),
        usize("Variant Rows", variant_rows, 1..=16),
        usize("Variant Cols", variant_cols, 1..=16),
        color("Base Color", color_base),
        color("Edge Color", color_edge),
        color("Throat Color", color_throat),
        slider("Length", length, 0.4..=1.0),
        slider("Width", width, 0.15..=0.95),
        slider("Peak", peak, 0.3..=0.9),
        slider("Tip Notch", tip_notch, 0.0..=0.25),
        slider("Curl", curl, 0.0..=1.0),
        slider("Asymmetry", asymmetry, 0.0..=0.4),
        slider("Normal Strength", normal_strength, 0.0..=4.0),
    }
);

impl_config_editor!(
    /// Renders all [`ShardConfig`] parameters inside a collapsing header.
    fn shard_config_editor, ShardConfig, "Shard Config" => {
        u32("Seed", seed),
        usize("Variant Rows", variant_rows, 1..=16),
        usize("Variant Cols", variant_cols, 1..=16),
        color("Base Color", color_base),
        color("Edge Color", color_edge),
        usize("Sides", sides, 3..=9),
        slider("Irregularity", irregularity, 0.0..=0.9),
        slider("Edge Band", edge_band, 0.02..=0.5),
        slider("Grain", grain, 0.0..=1.0),
        slider("Normal Strength", normal_strength, 0.0..=6.0),
    }
);

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

// Terrain and catalogue editors added in 0.8

impl_config_editor!(
    /// Renders all [`CrackedEarthConfig`] parameters inside a collapsing header.
    fn cracked_earth_config_editor, CrackedEarthConfig, "Cracked Earth Config" => {
        u32("Seed", seed),
        slider("Plates", scale, 2.0..=20.0),
        slider("Jitter", jitter, 0.0..=1.0),
        slider("Crack Width", crack_width, 0.001..=0.03),
        slider("Crack Depth", crack_depth, 0.0..=1.5),
        slider("Curl", curl, 0.0..=0.8),
        slider("Curl Reach", curl_reach, 0.005..=0.12),
        slider("Plate Variance", plate_variance, 0.0..=0.4),
        slider("Grain Scale", grain_scale, 4.0..=64.0),
        slider("Grain Strength", grain_strength, 0.0..=0.5),
        color("Plate Color", color_plate),
        color("Crack Color", color_crack),
        slider("Normal Strength", normal_strength, 0.5..=6.0),
    }
);

impl_config_editor!(
    /// Renders all [`GravelConfig`] parameters inside a collapsing header.
    fn gravel_config_editor, GravelConfig, "Gravel Config" => {
        u32("Seed", seed),
        enum_select("Stone Shape:", metric, [
            ("Rounded", CellMetric::Euclidean),
            ("Diamond", CellMetric::Manhattan),
            ("Angular", CellMetric::Chebyshev)
        ]),
        slider("Stones", scale, 4.0..=64.0),
        slider("Jitter", jitter, 0.0..=1.0),
        slider("Roundness", roundness, 0.2..=4.0),
        slider("Size Variance", size_variance, 0.0..=1.0),
        slider("Tint Variance", cell_variance, 0.0..=0.5),
        slider("Fines", fines_level, 0.0..=1.0),
        slider("Grain Scale", grain_scale, 8.0..=128.0),
        color("Stone Color", color_stone),
        color("Shadow Color", color_dark),
        color("Fines Color", color_fines),
        slider("Normal Strength", normal_strength, 0.5..=6.0),
    }
);

impl_config_editor!(
    /// Renders all [`ForestFloorConfig`] parameters inside a collapsing header.
    fn forest_floor_config_editor, ForestFloorConfig, "Forest Floor Config" => {
        u32("Seed", seed),
        slider("Litter Scale", litter_scale, 2.0..=24.0),
        usize("Layers", layers, 1..=4),
        slider("Coverage", coverage, 0.0..=1.0),
        slider("Leaf Length", leaf_length, 0.3..=2.5),
        slider("Leaf Width", leaf_width, 0.1..=1.0),
        slider("Leaf Thickness", leaf_thickness, 0.0..=1.0),
        slider("Midrib", midrib, 0.0..=1.0),
        slider("Humus Scale", humus_scale, 2.0..=48.0),
        color("Humus Color", color_humus),
        color("Fresh Leaf", color_leaf),
        color("Old Leaf", color_leaf_old),
        slider("Normal Strength", normal_strength, 0.5..=6.0),
    }
);

impl_config_editor!(
    /// Renders all [`EnamelConfig`] parameters inside a collapsing header.
    fn enamel_config_editor, EnamelConfig, "Enamel Config" => {
        u32("Seed", seed),
        color("Glaze Color", color),
        color("Body Color", color_body),
        slider("Gloss", gloss_roughness, 0.0..=1.0),
        slider("Metallic", metallic, 0.0..=1.0),
        slider("Crackle", crackle, 0.0..=1.0),
        slider("Crackle Scale", crackle_scale, 4.0..=64.0),
        slider("Crackle Width", crackle_width, 0.0005..=0.02),
        slider("Orange Peel", orange_peel, 0.0..=0.4),
        slider("Peel Scale", orange_peel_scale, 4.0..=80.0),
        nested(weathering_config_editor, weathering, "enamel_weather"),
        slider("Normal Strength", normal_strength, 0.1..=6.0),
    }
);

impl_config_editor!(
    /// Renders all [`ObsidianConfig`] parameters inside a collapsing header.
    fn obsidian_config_editor, ObsidianConfig, "Obsidian Config" => {
        u32("Seed", seed),
        color("Body Color", color),
        color("Sheen Color", color_sheen),
        slider_step("Band Cycles U", band_cycles_u, 0.0..=24.0, 1.0),
        slider_step("Band Cycles V", band_cycles_v, 0.0..=24.0, 1.0),
        slider("Band Warp", band_warp, 0.0..=1.0),
        slider("Warp Scale", band_warp_scale, 0.5..=12.0),
        slider("Band Sharpness", band_sharpness, 0.0..=1.0),
        slider("Band Contrast", band_contrast, 0.0..=1.0),
        slider("Gloss", gloss_roughness, 0.0..=1.0),
        slider("Metallic", metallic, 0.0..=1.0),
        slider("Relief", relief, 0.0..=0.5),
        nested(weathering_config_editor, weathering, "obsidian_weather"),
        slider("Normal Strength", normal_strength, 0.1..=6.0),
    }
);

impl_config_editor!(
    /// Renders all [`ChitinConfig`] parameters inside a collapsing header.
    fn chitin_config_editor, ChitinConfig, "Chitin Config" => {
        u32("Seed", seed),
        slider("Plates", scale, 2.0..=24.0),
        slider("Jitter", jitter, 0.0..=1.0),
        slider("Softness", softness, 2.0..=200.0),
        slider("Plate Fill", plate_fill, 0.05..=1.0),
        slider("Plate Relief", plate_relief, 0.0..=1.5),
        slider("Seam Width", seam_width, 0.0005..=0.05),
        slider("Seam Depth", seam_depth, 0.0..=1.0),
        slider("Iridescence", iridescence, 0.0..=0.6),
        color("Shell Color", color),
        color("Deep Color", color_deep),
        slider("Gloss", gloss_roughness, 0.0..=1.0),
        slider("Metallic", metallic, 0.0..=1.0),
        slider("Pit Scale", pit_scale, 6.0..=96.0),
        nested(weathering_config_editor, weathering, "chitin_weather"),
        slider("Normal Strength", normal_strength, 0.1..=6.0),
    }
);

impl_config_editor!(
    /// Renders all [`SolarPanelConfig`] parameters inside a collapsing header.
    fn solar_panel_config_editor, SolarPanelConfig, "Solar Panel Config" => {
        u32("Seed", seed),
        slider_step("Cells X", cells_x, 1.0..=16.0, 1.0),
        slider_step("Cells Y", cells_y, 1.0..=16.0, 1.0),
        slider("Cell Gap", cell_gap, 0.0..=0.4),
        slider("Corner Cut", corner_cut, 0.0..=0.5),
        slider_step("Busbars", busbars, 0.0..=8.0, 1.0),
        slider("Busbar Width", busbar_width, 0.0..=0.2),
        slider_step("Fingers", fingers, 0.0..=60.0, 1.0),
        slider("Finger Width", finger_width, 0.0..=0.1),
        color("Silicon Color", color_cell),
        color("Backing Color", color_backing),
        color("Wire Color", color_wire),
        slider("Cell Variance", cell_variance, 0.0..=0.5),
        slider("Crystal Mottle", crystal_mottle, 0.0..=1.0),
        slider("Crystal Scale", crystal_scale, 4.0..=64.0),
        slider("Glass Gloss", glass_roughness, 0.0..=1.0),
        nested(weathering_config_editor, weathering, "solar_weather"),
        slider("Normal Strength", normal_strength, 0.1..=6.0),
    }
);

impl_config_editor!(
    /// Renders all [`ParquetConfig`] parameters inside a collapsing header.
    fn parquet_config_editor, ParquetConfig, "Parquet Config" => {
        u32("Seed", seed),
        enum_select("Layout:", layout, [
            ("Herringbone", ParquetLayout::Herringbone),
            ("Basket", ParquetLayout::Basket),
            ("Brick", ParquetLayout::Brick)
        ]),
        slider("Boards", scale, 2.0..=32.0),
        slider("Aspect", aspect, 1.0..=12.0),
        slider("Joint Width", joint_width, 0.0..=0.3),
        slider("Joint Depth", joint_depth, 0.0..=1.5),
        slider_step("Grain Lines", grain_lines, 1.0..=32.0, 1.0),
        slider("Grain Contrast", grain_contrast, 0.0..=1.0),
        slider("Grain Warp", grain_warp, 0.0..=1.0),
        slider("Board Variance", board_variance, 0.0..=0.5),
        color("Wood Color", color_wood),
        color("Grain Color", color_grain),
        color("Joint Color", color_joint),
        slider("Gloss", gloss_roughness, 0.0..=1.0),
        nested(weathering_config_editor, weathering, "parquet_weather"),
        slider("Normal Strength", normal_strength, 0.1..=6.0),
    }
);

impl_config_editor!(
    /// Renders all [`TruchetConfig`] parameters inside a collapsing header.
    fn truchet_config_editor, TruchetConfig, "Truchet Config" => {
        u32("Seed", seed),
        slider("Tiles", scale, 1.0..=32.0),
        slider("Trace Width", trace_width, 0.01..=0.45),
        slider("Trace Relief", trace_relief, 0.0..=1.5),
        slider("Density", density, 0.0..=1.0),
        color("Panel Color", color_panel),
        color("Trace Color", color_trace),
        color("Glow Color", color_glow),
        slider("Glow", emissive_intensity, 0.0..=4.0),
        slider("Panel Roughness", panel_roughness, 0.0..=1.0),
        slider("Trace Roughness", trace_roughness, 0.0..=1.0),
        slider("Trace Metallic", trace_metallic, 0.0..=1.0),
        slider("Mottle Scale", mottle_scale, 2.0..=48.0),
        nested(weathering_config_editor, weathering, "truchet_weather"),
        slider("Normal Strength", normal_strength, 0.1..=6.0),
    }
);

/// Renders the editor for whichever generator `cfg` currently wraps.
///
/// Returns the same `(changed, regen)` pair as the per-config editors.
/// [`TextureConfig::None`](crate::material::TextureConfig::None) renders
/// nothing.  The match is exhaustive, so a registry row without an editor
/// fails compilation here — keeping the egui surface in sync with the
/// generator roster.
pub fn texture_config_editor(
    ui: &mut egui::Ui,
    cfg: &mut crate::material::TextureConfig,
    id: egui::Id,
) -> (bool, bool) {
    use crate::material::TextureConfig as TC;
    match cfg {
        TC::None => (false, false),
        TC::Leaf(c) => leaf_config_editor(ui, c, id),
        TC::Twig(c) => twig_config_editor(ui, c, id),
        TC::Bark(c) => bark_config_editor(ui, c, id),
        TC::Window(c) => window_config_editor(ui, c, id),
        TC::StainedGlass(c) => stained_glass_config_editor(ui, c, id),
        TC::IronGrille(c) => iron_grille_config_editor(ui, c, id),
        TC::Ground(c) => ground_config_editor(ui, c, id),
        TC::Rock(c) => rock_config_editor(ui, c, id),
        TC::Brick(c) => brick_config_editor(ui, c, id),
        TC::Plank(c) => plank_config_editor(ui, c, id),
        TC::Shingle(c) => shingle_config_editor(ui, c, id),
        TC::Stucco(c) => stucco_config_editor(ui, c, id),
        TC::Concrete(c) => concrete_config_editor(ui, c, id),
        TC::Metal(c) => metal_config_editor(ui, c, id),
        TC::Pavers(c) => pavers_config_editor(ui, c, id),
        TC::Ashlar(c) => ashlar_config_editor(ui, c, id),
        TC::Cobblestone(c) => cobblestone_config_editor(ui, c, id),
        TC::Thatch(c) => thatch_config_editor(ui, c, id),
        TC::Marble(c) => marble_config_editor(ui, c, id),
        TC::Corrugated(c) => corrugated_config_editor(ui, c, id),
        TC::Asphalt(c) => asphalt_config_editor(ui, c, id),
        TC::Wainscoting(c) => wainscoting_config_editor(ui, c, id),
        TC::Encaustic(c) => encaustic_config_editor(ui, c, id),
        TC::SoftDisc(c) => soft_disc_config_editor(ui, c, id),
        TC::Spark(c) => spark_config_editor(ui, c, id),
        TC::Snowflake(c) => snowflake_config_editor(ui, c, id),
        TC::Puff(c) => puff_config_editor(ui, c, id),
        TC::Ring(c) => ring_config_editor(ui, c, id),
        TC::Petal(c) => petal_config_editor(ui, c, id),
        TC::Shard(c) => shard_config_editor(ui, c, id),
        TC::LeafSprite(c) => leaf_sprite_config_editor(ui, c, id),
        TC::Flame(c) => flame_config_editor(ui, c, id),
        TC::Flower(c) => flower_config_editor(ui, c, id),
        TC::GrassTuft(c) => grass_config_editor(ui, c, id),
        TC::Frond(c) => frond_config_editor(ui, c, id),
        TC::CactusSkin(c) => cactus_config_editor(ui, c, id),
        TC::Moss(c) => moss_config_editor(ui, c, id),
        TC::Lichen(c) => lichen_config_editor(ui, c, id),
        TC::Reed(c) => reed_config_editor(ui, c, id),
        TC::Needle(c) => needle_config_editor(ui, c, id),
        TC::Broadleaf(c) => broadleaf_config_editor(ui, c, id),
        TC::Fabric(c) => fabric_config_editor(ui, c, id),
        TC::Sand(c) => sand_config_editor(ui, c, id),
        TC::Snow(c) => snow_config_editor(ui, c, id),
        TC::Ice(c) => ice_config_editor(ui, c, id),
        TC::Lava(c) => lava_config_editor(ui, c, id),
        TC::ChainLink(c) => chain_link_config_editor(ui, c, id),
        TC::LogEnd(c) => log_end_config_editor(ui, c, id),
        TC::CrackedEarth(c) => cracked_earth_config_editor(ui, c, id),
        TC::Gravel(c) => gravel_config_editor(ui, c, id),
        TC::ForestFloor(c) => forest_floor_config_editor(ui, c, id),
        TC::Enamel(c) => enamel_config_editor(ui, c, id),
        TC::Obsidian(c) => obsidian_config_editor(ui, c, id),
        TC::Chitin(c) => chitin_config_editor(ui, c, id),
        TC::SolarPanel(c) => solar_panel_config_editor(ui, c, id),
        TC::Parquet(c) => parquet_config_editor(ui, c, id),
        TC::Truchet(c) => truchet_config_editor(ui, c, id),
    }
}

/// 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();
    });
}