tiger_lib/gui/
properties.rs

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
use std::fmt::{Display, Error, Formatter};
use std::hash::Hash;

use strum::VariantNames;
use strum_macros::{Display, FromRepr, IntoStaticStr, VariantNames};
use thiserror::Error;

#[cfg(doc)]
use crate::datatype::Datatype;
use crate::game::GameFlags;
use crate::gui::BuiltinWidget;
#[cfg(doc)]
use crate::gui::GuiBlock;
use crate::item::Item;
use crate::lowercase::Lowercase;

use GuiValidation::*;
use WidgetProperty::*;

/// The various values or blocks or datatype calculations that the gui properties can take.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum GuiValidation {
    /// Accept any value; we don't know.
    UncheckedValue,
    /// A datatype expression; we don't know the specific type.
    DatatypeExpr,
    /// A datatype expression that ends with a promote. Can be any type.
    // TODO: check that it is a singular type, not a collection
    Datacontext,
    /// A datatype expression that returns a collection of some sort.
    // TODO: check that it is indeed a collection
    Datamodel,
    /// "yes", "no", or a [`Datatype::bool`] expression.
    Boolean,
    /// Only a literal "yes" will do.
    Yes,
    /// A `|`-separated list of values from [`ALIGN`].
    Align,
    /// An integer value or a [`Datatype::int32`] expression.
    Integer,
    /// A non-negative integer value or a [`Datatype::uint32`] expression.
    UnsignedInteger,
    /// A numeric value or a [`Datatype::float`] expression.
    Number,
    /// A numeric value or a [`Datatype::float`] or [`Datatype::int32`] expression.
    NumberOrInt32,
    /// A numeric value possibly followed by an `f` or a [`Datatype::float`] expression.
    // TODO: the f is used in vanilla. Check if it's harmless or maybe required.
    NumberF,
    /// A numeric value, possibly followed by a `%` mark, or a [`Datatype::int32`] or
    /// [`Datatype::float`] expression.
    NumberOrPercent,
    /// A block with two numeric values, possibly followed by `%` marks, or a
    /// [`Datatype::CVector2f`] expression.
    TwoNumberOrPercent,
    /// A block with 2 numbers, or a [`Datatype::CVector2f`] expression.
    CVector2f,
    /// A block with 2 integers, or a [`Datatype::CVector2i`] expression.
    CVector2i,
    /// A block with 3 numbers, or a [`Datatype::CVector3f`] expression.
    CVector3f,
    /// A block with 4 numbers, or a [`Datatype::CVector4f`] expression.
    CVector4f,
    /// A block with 4 numbers (RGBA), or a [`Datatype::CVector4f`] expression.
    /// The difference with [`GuiValidation::CVector4f`] is in the error messages.
    Color,
    /// A datatype expression returning a `CString`
    CString,
    /// A key for this item type, or a datatype expression that can be converted to string.
    Item(Item),
    /// A key for this item type, or a datatype expression that can be converted to string.
    /// May be the empty string.
    ItemOrBlank(Item),
    /// One of the strings in the [`BLENDMODES`] array
    Blendmode,
    /// One of the mouse buttons in the array given here.
    MouseButton(&'static [&'static str]),
    /// A `|`-separated list of the mouse buttons in the array given here.
    MouseButtonSet(&'static [&'static str]),
    /// One of the strings in the array given here.
    Choice(&'static [&'static str]),
    /// A `|`-separated list of strings from the array given here.
    ChoiceSet(&'static [&'static str]),
    /// A block containing one widget, or the name of a template containing one widget.
    Widget,
    /// A string containing a localization text format specifier starting with `#`
    Format,
    /// A block containing two textformat names
    FormatOverride,
    /// Some text. May contain datatypes or loca keys, but it's optional.
    RawText,
    /// Some text. May contain datatypes or loca keys.
    Text,
    /// A property that takes a block of other properties. This block may have override blocks in it.
    ComplexProperty,
}

/// All the properties that can be used in gui widgets.
// These need to be in lexical order, for the `TryFrom` implementation to work right.
#[derive(
    Debug, Clone, Copy, PartialEq, Eq, Hash, IntoStaticStr, VariantNames, FromRepr, Display,
)]
#[allow(non_camel_case_types)]
#[strum(serialize_all = "lowercase")] // for "loop"
pub enum WidgetProperty {
    accept_tabs,
    active_item,
    addcolumn,
    addrow,
    align,
    allow_outside,
    alpha,
    alwaystransparent,
    animate_negative_changes,
    animation,
    animation_speed,
    attachto,
    autoresize,
    autoresize_slider,
    autoresizescrollarea,
    autoresizeviewport,
    axis_label,
    background_texture,
    bezier,
    blend_mode,
    bottomtotop,
    button_ignore,
    button_trigger,
    buttontext,
    camera_fov_y_degrees,
    camera_look_at,
    camera_near_far,
    camera_position,
    camera_rotation_pitch_limits,
    camera_translation_limits,
    camera_zoom_limits,
    checked,
    click_modifiers,
    clicksound,
    coat_of_arms,
    coat_of_arms_mask,
    coat_of_arms_slot,
    color,
    colorpicker_reticule_icon,
    constantbuffers,
    cursorcolor,
    datacontext,
    datamodel,
    datamodel_reuse_widgets,
    datamodel_wrap,
    dec_button,
    default_clicksound,
    default_format,
    delay,
    direction,
    disableframe,
    distribute_visual_state,
    down,
    downframe,
    downhoverframe,
    downpressedframe,
    drag_drop_args,
    drag_drop_base_type,
    drag_drop_data,
    drag_drop_id,
    dragdropargs,
    dragdropid,
    draggable_by,
    droptarget,
    duration,
    effect,
    effectname,
    elide,
    enabled,
    end_sound,
    endangle,
    entity_enable_sound,
    entity_instance,
    even_row_widget,
    expand_item,
    expandbutton,
    filter_mouse,
    fittype,
    flipdirection,
    focus_on_visible,
    focuspolicy,
    font,
    fontcolor,
    fontsize,
    fontsize_min,
    fonttintcolor,
    fontweight,
    force_data_properties_update,
    forcedown,
    format_override,
    frame,
    frame_tier,
    framesize,
    from,
    gfx_environment_file,
    gfxtype,
    glow,
    glow_alpha,
    glow_alpha_mask,
    glow_blur_passes,
    glow_generation_rules,
    glow_ignore_inside_pixels,
    glow_radius,
    glow_texture_downscale,
    grayscale,
    grid_entity_name,
    header_height,
    highlightchecked,
    ignore_in_debug_draw,
    ignore_unset_buttons,
    ignoreinvisible,
    inc_button,
    indent,
    index,
    inherit_data_context,
    inherit_visibility,
    inherit_visual_state,
    input_action,
    intersectionmask,
    intersectionmask_texture,
    invert_reticule_color,
    invertprogress,
    item,
    keyframe_editor_lane_container,
    layer,
    layoutanchor,
    layoutpolicy_horizontal,
    layoutpolicy_vertical,
    layoutstretchfactor_horizontal,
    layoutstretchfactor_vertical,
    line_cap,
    line_feather_distance,
    line_type,
    list,
    Loop, // titlecased to avoid collision with builtin loop
    loopinterval,
    margin,
    margin_bottom,
    margin_left,
    margin_right,
    margin_top,
    marker,
    mask,
    mask_uv_scale,
    max,
    max_height,
    max_update_rate,
    max_width,
    maxcharacters,
    maxhorizontalslots,
    maximumsize,
    maxverticalslots,
    min,
    min_dist_from_screen_edge,
    min_height,
    min_width,
    minimumsize,
    mipmaplodbias,
    mirror,
    modal,
    modality,
    modify_texture,
    movable,
    multiline,
    name,
    next,
    noprogresstexture,
    odd_row_widget,
    on_finish,
    on_keyframe_move,
    on_start,
    onalt,
    onchangefinish,
    onchangestart,
    onclick,
    oncolorchanged,
    oncoloredited,
    oncreate,
    onctrl,
    ondatacontextchanged,
    ondefault,
    ondoubleclick,
    oneditingfinished,
    oneditingfinished_with_changes,
    oneditingstart,
    onenter_signal,
    onfocusout,
    onleave_signal,
    onmousehierarchyenter,
    onmousehierarchyleave,
    onpressed,
    onreleased,
    onreturnpressed,
    onrightclick,
    onselectionchanged,
    onshift,
    ontextchanged,
    ontextedited,
    onvaluechanged,
    overframe,
    oversound,
    page,
    pan_position,
    parentanchor,
    password,
    plotpoints,
    points,
    pop_out,
    pop_out_v,
    portrait_context,
    portrait_offset,
    portrait_scale,
    portrait_texture,
    position,
    position_x,
    position_y,
    preferscrollwidgetsize,
    progress_change_to_duration_curve,
    progresstexture,
    pseudo_localization_enabled,
    raw_text,
    raw_tooltip,
    realtime,
    recursive,
    reorder_on_mouse,
    resizable,
    resizeparent,
    restart_on_show,
    restrictparent_min,
    reuse_widgets,
    rightclick_modifiers,
    rightclicksound,
    righttoleft,
    rotate_uv,
    row_height,
    scale,
    scale_mode,
    scissor,
    scrollbar_horizontal,
    scrollbar_vertical,
    scrollbaralign_horizontal,
    scrollbaralign_vertical,
    scrollbarpolicy_horizontal,
    scrollbarpolicy_vertical,
    scrollwidget,
    selectallonfocus,
    selectedindex,
    selectioncolor,
    set_parent_size_to_minimum,
    setitemsizefromcell,
    shaderfile,
    shortcut,
    size,
    skip_initial_animation,
    slider,
    snap_to_pixels,
    soundeffect,
    soundparam,
    spacing,
    spriteborder,
    spriteborder_bottom,
    spriteborder_left,
    spriteborder_right,
    spriteborder_top,
    spritetype,
    stackmode,
    start_sound,
    startangle,
    state,
    step,
    sticky,
    tabfocusroot,
    text,
    text_selectable,
    text_validator,
    texture,
    texture_density,
    timeline_line_direction,
    timeline_line_height,
    timeline_texts,
    timeline_time_points,
    tintcolor,
    to,
    tooltip,
    tooltip_enabled,
    tooltip_horizontalbehavior,
    tooltip_offset,
    tooltip_parentanchor,
    tooltip_type,
    tooltip_verticalbehavior,
    tooltip_visible,
    tooltip_when_disabled,
    tooltip_widgetanchor,
    tooltipwidget,
    track,
    tracknavigation,
    translate_uv,
    trigger_on_create,
    trigger_when,
    upframe,
    uphoverframe,
    uppressedframe,
    url,
    useragent,
    uv_scale,
    value,
    video,
    viewportwidget,
    visible,
    visible_at_creation,
    wheelstep,
    widgetanchor,
    widgetid,
    width,
    wrap_count,
    zoom,
    zoom_max,
    zoom_min,
    zoom_step,
    zoomwidget,
}

#[derive(Error, Debug)]
pub enum TryWidgetPropertyError {
    #[error("widget property `{0}` not found")]
    NotFound(String),
}

impl<'a> TryFrom<&Lowercase<'a>> for WidgetProperty {
    type Error = TryWidgetPropertyError;

    fn try_from(s: &Lowercase<'a>) -> Result<Self, Self::Error> {
        match WidgetProperty::VARIANTS.binary_search(&s.as_str()) {
            // unwrap is safe here because of how VARIANTS is constructed
            Ok(i) => Ok(WidgetProperty::from_repr(i).unwrap()),
            Err(_) => Err(TryWidgetPropertyError::NotFound(s.to_string())),
        }
    }
}

const LAYOUT_POLICIES: &[&str] = &["expanding", "fixed", "growing", "preferred", "shrinking"];

pub const BLENDMODES: &[&str] =
    &["add", "alphamultiply", "colordodge", "darken", "mask", "multiply", "normal", "overlay"];

// TODO: warn about contradicting alignments (left|right or top|vcenter)
// TODO: is nobaseline only for text widgets?
pub const ALIGN: &[&str] =
    &["left", "right", "top", "bottom", "center", "hcenter", "vcenter", "nobaseline"];

impl GuiValidation {
    /// Get the validation logic for a specific widget property
    pub fn from_property(property: WidgetProperty) -> Self {
        #[allow(clippy::match_same_arms)] // keep it alphabetic
        match property {
            accept_tabs => Boolean,
            active_item => Widget,
            addcolumn => NumberOrPercent,
            addrow => NumberOrPercent,
            align => Align,
            allow_outside => Boolean,
            alpha => Number,
            alwaystransparent => Boolean,
            animate_negative_changes => Boolean,
            animation => ComplexProperty,
            animation_speed => CVector2f,
            attachto => ComplexProperty,
            autoresize => Boolean,
            autoresize_slider => Boolean,
            autoresizescrollarea => Boolean,
            autoresizeviewport => Boolean,
            axis_label => Widget,
            background_texture => Item(Item::File),
            bezier => CVector4f,
            blend_mode => Blendmode,
            bottomtotop => Boolean,
            button_ignore => MouseButton(&["both", "none", "left", "right"]),
            button_trigger => UncheckedValue, // only example is "none"
            buttontext => Widget,
            camera_fov_y_degrees => Integer,
            camera_look_at => CVector3f,
            camera_near_far => CVector2f,
            camera_position => CVector3f,
            camera_rotation_pitch_limits => CVector2f,
            camera_translation_limits => CVector3f,
            camera_zoom_limits => CVector2f,
            checked => Boolean,
            click_modifiers => ComplexProperty,
            clicksound => ItemOrBlank(Item::Sound),
            coat_of_arms => Item(Item::File),
            coat_of_arms_mask => Item(Item::File),
            coat_of_arms_slot => CVector4f,
            color => Color,
            colorpicker_reticule_icon => Widget,
            constantbuffers => DatatypeExpr,
            cursorcolor => Color,
            datacontext => Datacontext,
            datamodel => Datamodel,
            datamodel_reuse_widgets => Boolean,
            datamodel_wrap => Integer,
            dec_button => Widget,
            default_clicksound => ItemOrBlank(Item::Sound),
            default_format => Format,
            delay => Number,
            direction => Choice(&["horizontal", "vertical"]),
            disableframe => Integer,
            distribute_visual_state => Boolean,
            down => Boolean,
            downframe => Integer,
            downhoverframe => Integer,
            downpressedframe => Integer,
            drag_drop_args => CString,
            drag_drop_base_type => Choice(&["icon", "coat_of_arms_icon"]),
            drag_drop_data => Datacontext,
            drag_drop_id => UncheckedValue, // TODO what are the options?
            dragdropargs => RawText,
            dragdropid => RawText,
            draggable_by => MouseButtonSet(&["left", "right", "middle"]),
            droptarget => Boolean,
            duration => Number,
            effect => DatatypeExpr,
            effectname => UncheckedValue, // TODO validate effect names
            elide => Choice(&["right", "middle", "left"]),
            enabled => Boolean,
            end_sound => ComplexProperty,
            endangle => NumberOrInt32,
            entity_enable_sound => Boolean,
            entity_instance => Item(Item::Entity),
            even_row_widget => Widget,
            expand_item => Widget,
            expandbutton => Widget,
            filter_mouse => MouseButtonSet(&["all", "none", "left", "right", "wheel"]),
            fittype => Choice(&["center", "centercrop", "fill", "end", "start"]),
            flipdirection => Boolean,
            focus_on_visible => Boolean,
            focuspolicy => Choice(&["click", "all", "none"]),
            font => Item(Item::Font),
            fontcolor => Color,
            fontsize => Integer,
            fontsize_min => Integer,
            fonttintcolor => Color,
            fontweight => UncheckedValue, // TODO: what are the options?
            force_data_properties_update => Boolean,
            forcedown => DatatypeExpr,
            format_override => FormatOverride,
            frame => Integer,
            frame_tier => Integer,
            framesize => CVector2i,
            from => CVector2f,
            gfx_environment_file => Item(Item::File),
            gfxtype => UncheckedValue, // TODO: what are the options?
            glow => ComplexProperty,
            glow_alpha => Number,
            glow_alpha_mask => Integer,
            glow_blur_passes => Integer,
            glow_generation_rules => ComplexProperty,
            glow_ignore_inside_pixels => Boolean,
            glow_radius => Integer,
            glow_texture_downscale => NumberF,
            grayscale => Boolean,
            grid_entity_name => Item(Item::Entity),
            header_height => Integer,
            highlightchecked => Boolean,
            ignore_in_debug_draw => Boolean,
            ignore_unset_buttons => MouseButtonSet(&["right", "middle", "left"]), // middle and left are guesses
            ignoreinvisible => Boolean,
            inc_button => Widget,
            indent => Integer,
            index => Integer,
            inherit_data_context => Boolean,
            inherit_visibility => Choice(&["yes", "no", "hidden"]),
            inherit_visual_state => Boolean,
            input_action => Item(Item::Shortcut),
            intersectionmask => Boolean,
            intersectionmask_texture => Item(Item::File),
            invert_reticule_color => Boolean,
            invertprogress => Boolean,
            item => Widget,
            keyframe_editor_lane_container => Widget,
            layer => Item(Item::GuiLayer),
            layoutanchor => UncheckedValue, // TODO: only example is "bottomleft"
            layoutpolicy_horizontal => ChoiceSet(LAYOUT_POLICIES),
            layoutpolicy_vertical => ChoiceSet(LAYOUT_POLICIES),
            layoutstretchfactor_horizontal => NumberOrInt32,
            layoutstretchfactor_vertical => NumberOrInt32,
            line_cap => Boolean,
            line_feather_distance => Integer,
            line_type => UncheckedValue, // TODO: only example is "nodeline"
            list => Widget,
            Loop => Boolean,
            loopinterval => Number,
            margin => TwoNumberOrPercent,
            margin_bottom => NumberOrInt32,
            margin_left => NumberOrInt32,
            margin_right => NumberOrInt32,
            margin_top => NumberOrInt32,
            marker => Widget,
            mask => Item(Item::File),
            mask_uv_scale => CVector2f,
            max => NumberOrInt32,
            max_height => Integer,
            max_update_rate => Integer,
            max_width => Integer,
            maxcharacters => UnsignedInteger,
            maxhorizontalslots => Integer,
            maximumsize => TwoNumberOrPercent,
            maxverticalslots => Integer,
            min => NumberOrInt32,
            min_dist_from_screen_edge => Integer,
            min_height => Integer,
            min_width => Integer,
            minimumsize => TwoNumberOrPercent,
            mipmaplodbias => Integer,
            mirror => ChoiceSet(&["horizontal", "vertical"]),
            modal => Boolean,
            modality => UncheckedValue, // TODO: only example is "all"
            modify_texture => ComplexProperty,
            movable => Boolean,
            multiline => Boolean,
            name => UncheckedValue,
            next => UncheckedValue, // TODO: choices are states in the same widget
            noprogresstexture => Item(Item::File),
            odd_row_widget => Widget,
            on_finish => DatatypeExpr,
            on_keyframe_move => DatatypeExpr,
            on_start => DatatypeExpr,
            onalt => DatatypeExpr,
            onchangefinish => DatatypeExpr,
            onchangestart => DatatypeExpr,
            onclick => DatatypeExpr,
            oncolorchanged => DatatypeExpr,
            oncoloredited => DatatypeExpr,
            oncreate => DatatypeExpr,
            onctrl => DatatypeExpr,
            ondatacontextchanged => DatatypeExpr,
            ondefault => DatatypeExpr,
            ondoubleclick => DatatypeExpr,
            oneditingfinished => DatatypeExpr,
            oneditingfinished_with_changes => DatatypeExpr,
            oneditingstart => DatatypeExpr,
            onenter_signal => DatatypeExpr,
            onfocusout => DatatypeExpr,
            onleave_signal => DatatypeExpr,
            onmousehierarchyenter => DatatypeExpr,
            onmousehierarchyleave => DatatypeExpr,
            onpressed => DatatypeExpr,
            onreleased => DatatypeExpr,
            onreturnpressed => DatatypeExpr,
            onrightclick => DatatypeExpr,
            onselectionchanged => DatatypeExpr,
            onshift => DatatypeExpr,
            ontextchanged => DatatypeExpr,
            ontextedited => DatatypeExpr,
            onvaluechanged => DatatypeExpr,
            overframe => Integer,
            oversound => ItemOrBlank(Item::Sound),
            page => Integer,
            pan_position => CVector2f,
            parentanchor => Align,
            password => Boolean,
            plotpoints => DatatypeExpr,
            points => DatatypeExpr,
            pop_out => Boolean,
            pop_out_v => NumberOrInt32,
            portrait_context => DatatypeExpr,
            portrait_offset => CVector2f,
            portrait_scale => CVector2f,
            portrait_texture => Item(Item::File),
            position => TwoNumberOrPercent,
            position_x => Integer,
            position_y => Integer,
            preferscrollwidgetsize => Boolean,
            progress_change_to_duration_curve => CVector4f,
            progresstexture => Item(Item::File),
            pseudo_localization_enabled => Boolean,
            raw_text => RawText,
            raw_tooltip => RawText,
            realtime => Boolean,
            recursive => Yes,
            reorder_on_mouse => UncheckedValue, // TODO: only example is "presstop"
            resizable => Boolean,
            resizeparent => Boolean,
            restart_on_show => Boolean,
            restrictparent_min => Boolean,
            reuse_widgets => Boolean,
            rightclick_modifiers => ComplexProperty,
            rightclicksound => ItemOrBlank(Item::Sound),
            righttoleft => Boolean,
            rotate_uv => Number,
            row_height => Integer,
            scale => Number,
            scale_mode => UncheckedValue, // TODO: only example is "fixedwidth"
            scissor => Boolean,
            scrollbar_horizontal => Widget,
            scrollbar_vertical => Widget,
            scrollbaralign_horizontal => Choice(&["top", "bottom"]),
            scrollbaralign_vertical => Choice(&["left", "right"]),
            scrollbarpolicy_horizontal => Choice(&["as_needed", "always_off", "always_on"]), // TODO: always_on is a guess
            scrollbarpolicy_vertical => Choice(&["as_needed", "always_off", "always_on"]),
            scrollwidget => Widget,
            selectallonfocus => Boolean,
            selectedindex => CVector2i,
            selectioncolor => Color,
            set_parent_size_to_minimum => Boolean,
            setitemsizefromcell => Boolean,
            shaderfile => ItemOrBlank(Item::File),
            shortcut => Item(Item::Shortcut),
            size => TwoNumberOrPercent,
            skip_initial_animation => Boolean,
            slider => Widget,
            snap_to_pixels => Boolean,
            soundeffect => Item(Item::Sound),
            soundparam => ComplexProperty,
            spacing => NumberF,
            spriteborder => CVector2f,
            spriteborder_bottom => Integer,
            spriteborder_left => Integer,
            spriteborder_right => Integer,
            spriteborder_top => Integer,
            spritetype => UncheckedValue, // TODO
            stackmode => UncheckedValue,  // TODO only example is "top"
            start_sound => ComplexProperty,
            startangle => NumberOrInt32,
            state => ComplexProperty,
            step => NumberOrInt32,
            sticky => Boolean,
            tabfocusroot => Boolean,
            text => Text,
            text_selectable => Boolean,
            text_validator => DatatypeExpr,
            texture => Item(Item::File),
            texture_density => Number,
            timeline_line_direction => UncheckedValue, // TODO only example is "up"
            timeline_line_height => Integer,
            timeline_texts => Widget,
            timeline_time_points => Integer,
            tintcolor => Color,
            to => CVector2f,
            tooltip => Text,
            tooltip_enabled => Boolean,
            tooltip_horizontalbehavior => Choice(&["mirror", "slide", "flip"]),
            tooltip_offset => TwoNumberOrPercent,
            tooltip_parentanchor => Align,
            tooltip_type => Choice(&["mouse", "widget"]),
            tooltip_verticalbehavior => Choice(&["mirror", "slide", "flip"]),
            tooltip_visible => Boolean,
            tooltip_when_disabled => Text,
            tooltip_widgetanchor => Align,
            tooltipwidget => Widget,
            track => Widget,
            tracknavigation => UncheckedValue, // TODO only example is "direct"
            translate_uv => CVector2f,
            trigger_on_create => Boolean,
            trigger_when => Boolean,
            upframe => Integer,
            uphoverframe => Integer,
            uppressedframe => Integer,
            url => RawText,
            useragent => UncheckedValue,
            uv_scale => CVector2f,
            value => NumberOrInt32,
            video => Item(Item::File),
            viewportwidget => Widget,
            visible => Boolean,
            visible_at_creation => Boolean,
            wheelstep => NumberOrInt32,
            widgetanchor => Align,
            widgetid => UncheckedValue,
            width => Number,
            wrap_count => Number,
            zoom => Number,
            zoom_max => Number,
            zoom_min => Number,
            zoom_step => Number,
            zoomwidget => Widget,
        }
    }
}

impl WidgetProperty {
    /// Return which games support a given widget property
    // LAST UPDATED CK3 VERSION 1.9.2.1
    // LAST UPDATED VIC3 VERSION 1.3.6
    // LAST UPDATED IMPERATOR VERSION 2.0.3
    // TODO: verify rightclicksound property for Vic3 and Imperator
    pub fn to_game_flags(self) -> GameFlags {
        #[allow(clippy::match_same_arms)] // alphabetic is better
        match self {
            animate_negative_changes | autoresize_slider | click_modifiers => {
                GameFlags::Ck3 | GameFlags::Vic3
            }

            coat_of_arms | coat_of_arms_mask => GameFlags::Ck3,

            coat_of_arms_slot | colorpicker_reticule_icon => GameFlags::Ck3 | GameFlags::Vic3,

            drag_drop_args | drag_drop_base_type | drag_drop_id => GameFlags::Ck3,

            drag_drop_data
            | focus_on_visible
            | force_data_properties_update
            | grid_entity_name
            | ignore_in_debug_draw
            | ignore_unset_buttons
            | index => GameFlags::Ck3 | GameFlags::Vic3,

            input_action => GameFlags::Vic3,

            invert_reticule_color | keyframe_editor_lane_container | Loop => {
                GameFlags::Ck3 | GameFlags::Vic3
            }

            max_height => GameFlags::Ck3,

            max_update_rate | min_dist_from_screen_edge => GameFlags::Ck3 | GameFlags::Vic3,

            min_height => GameFlags::Ck3,

            on_keyframe_move
            | onalt
            | ondefault
            | ondoubleclick
            | oneditingfinished_with_changes
            | oneditingstart
            | onfocusout
            | onshift
            | progress_change_to_duration_curve
            | pseudo_localization_enabled
            | raw_text
            | raw_tooltip
            | restart_on_show
            | rightclick_modifiers
            | selectallonfocus
            | skip_initial_animation
            | timeline_line_direction
            | timeline_line_height
            | timeline_texts
            | timeline_time_points => GameFlags::Ck3 | GameFlags::Vic3,

            tooltip_enabled => GameFlags::Vic3 | GameFlags::Imperator,
            tooltip_visible | tooltip_when_disabled => GameFlags::Ck3,
            video => GameFlags::Ck3 | GameFlags::Vic3,

            onctrl => GameFlags::Vic3,
            wrap_count => GameFlags::Vic3,

            frame_tier | ondatacontextchanged | dragdropid | dragdropargs | forcedown | url
            | bottomtotop | onleave_signal | onenter_signal => GameFlags::Imperator,

            _ => GameFlags::all(),
        }
    }
}

/// The container type of a [`GuiBlock`], which determines which properties are accepted.
/// Can be either a [`BuiltinWidget`] or a [`WidgetProperty`] of the [`GuiValidation::ComplexProperty`] type.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum PropertyContainer {
    // The widget's ultimate base type.
    BuiltinWidget(BuiltinWidget),
    // A property that can hold other properties.
    ComplexProperty(WidgetProperty),
    // A property that can hold a widget.
    WidgetProperty(WidgetProperty),
}

impl From<BuiltinWidget> for PropertyContainer {
    fn from(w: BuiltinWidget) -> Self {
        PropertyContainer::BuiltinWidget(w)
    }
}

#[derive(Debug, Error, Copy, Clone, PartialEq, Eq, Hash)]
pub enum WidgetPropertyContainerError {
    #[error("property `{0}` cannot be a container")]
    WrongPropertyKind(WidgetProperty),
}

impl TryFrom<WidgetProperty> for PropertyContainer {
    type Error = WidgetPropertyContainerError;
    fn try_from(prop: WidgetProperty) -> Result<Self, Self::Error> {
        let validation = GuiValidation::from_property(prop);
        if validation == GuiValidation::ComplexProperty {
            Ok(PropertyContainer::ComplexProperty(prop))
        } else if validation == GuiValidation::Widget {
            Ok(PropertyContainer::WidgetProperty(prop))
        } else {
            Err(WidgetPropertyContainerError::WrongPropertyKind(prop))
        }
    }
}

impl Display for PropertyContainer {
    fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
        match self {
            PropertyContainer::BuiltinWidget(builtin) => write!(f, "builtin widget {builtin}"),
            PropertyContainer::ComplexProperty(prop) => write!(f, "complex property {prop}"),
            PropertyContainer::WidgetProperty(prop) => write!(f, "widget property {prop}"),
        }
    }
}