-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwillowui.go
More file actions
2107 lines (1586 loc) · 80.7 KB
/
willowui.go
File metadata and controls
2107 lines (1586 loc) · 80.7 KB
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
package willowui
import (
_ "embed"
"fmt"
"io/fs"
"os"
"path/filepath"
"runtime"
"github.com/devthicket/willowui/internal/colorutil"
"github.com/devthicket/willowui/internal/core"
"github.com/devthicket/willowui/internal/dev"
"github.com/devthicket/willowui/internal/markup"
"github.com/devthicket/willowui/internal/reactive"
"github.com/devthicket/willowui/internal/render"
"github.com/devthicket/willowui/internal/sg"
"github.com/devthicket/willowui/internal/template"
"github.com/devthicket/willowui/internal/theme"
"github.com/devthicket/willowui/internal/widget"
)
// =============================================================================
// Reactive
// =============================================================================
// Ref is a reactive reference — re-exported from internal/reactive.
type Ref[T comparable] = reactive.Ref[T]
// Computed is a reactive computed value — re-exported from internal/reactive.
type Computed[T comparable] = reactive.Computed[T]
// WatchHandle is a handle returned by WatchEffect / WatchValue.
type WatchHandle = reactive.WatchHandle
// Scheduler drives reactive flush cycles.
type Scheduler = reactive.Scheduler
// DefaultScheduler is the package-level scheduler. It points into the
// internal reactive package so that Ref.Set() and Computed.markDirty()
// enqueue to the same scheduler that external callers flush.
var DefaultScheduler = &reactive.DefaultScheduler
// NewRef creates a new reactive reference.
func NewRef[T comparable](initial T) *Ref[T] {
return reactive.NewRef(initial)
}
// NewComputed creates a new computed reactive value.
func NewComputed[T comparable](fn func() T) *Computed[T] {
return reactive.NewComputed(fn)
}
// WatchEffect creates a reactive effect that re-runs when dependencies change.
func WatchEffect(fn func()) WatchHandle {
return reactive.WatchEffect(fn)
}
// WatchValue watches a specific Ref and calls fn with old and new values.
func WatchValue[T comparable](ref *Ref[T], fn func(old, new T)) WatchHandle {
return reactive.WatchValue(ref, fn)
}
// Numeric is a constraint for types that support arithmetic operations.
type Numeric = reactive.Numeric
// Increment returns a func() that adds delta to a numeric ref.
func Increment[T Numeric](r *Ref[T], delta T) func() {
return reactive.Increment(r, delta)
}
// ToggleRef returns a func() that flips a boolean ref.
func ToggleRef(r *Ref[bool]) func() {
return reactive.Toggle(r)
}
// Set returns a func() that sets a ref to the given value.
func Set[T comparable](r *Ref[T], val T) func() {
return reactive.Set(r, val)
}
// BindFormatter returns a *Ref[string] that stays in sync with source,
// converting values via fmt.Sprint. Use with BindText.
//
// The returned WatchHandle must be stopped when the binding is no longer
// needed. Pass it to screen.TrackRef or call h.Stop() explicitly.
func BindFormatter[T comparable](source *Ref[T]) (*Ref[string], WatchHandle) {
return reactive.BindFormatter(source)
}
// BindFormatterf returns a *Ref[string] that stays in sync with source,
// converting values via fmt.Sprintf. Use with BindText.
//
// The returned WatchHandle must be stopped when the binding is no longer
// needed. Pass it to screen.TrackRef or call h.Stop() explicitly.
func BindFormatterf[T comparable](source *Ref[T], format string) (*Ref[string], WatchHandle) {
return reactive.BindFormatterf(source, format)
}
// Array[T] is a reactive ordered collection — re-exported from internal/reactive.
type Array[T any] = reactive.Array[T]
// Record is a reactive key-value object — re-exported from internal/reactive.
type Record = reactive.Record
// NewArray creates an empty reactive array.
func NewArray[T any]() *Array[T] {
return reactive.NewArray[T]()
}
// NewArrayFrom creates a reactive array copied from the given slice.
func NewArrayFrom[T any](items []T) *Array[T] {
return reactive.NewArrayFrom(items)
}
// NewArrayFromAny creates a reactive Array[any] from a typed slice, boxing each element.
func NewArrayFromAny[T any](items []T) *Array[any] {
return reactive.NewArrayFromAny(items)
}
// NewArrayWithCap creates an empty reactive array with the given initial capacity.
func NewArrayWithCap[T any](cap int) *Array[T] {
return reactive.NewArrayWithCap[T](cap)
}
// ArrayMap transforms each element of a using fn and returns a plain []U.
func ArrayMap[T, U any](a *Array[T], fn func(T) U) []U {
return reactive.ArrayMap(a, fn)
}
// ArrayReduce folds a into a single U value using fn, starting from init.
func ArrayReduce[T, U any](a *Array[T], fn func(U, T) U, init U) U {
return reactive.ArrayReduce(a, fn, init)
}
// ArraySort sorts a in ascending order. T must satisfy cmp.Ordered.
func ArraySort[T interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
~float32 | ~float64 | ~string
}](a *Array[T]) {
reactive.ArraySort(a)
}
// ArraySortDesc sorts a in descending order. T must satisfy cmp.Ordered.
func ArraySortDesc[T interface {
~int | ~int8 | ~int16 | ~int32 | ~int64 |
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
~float32 | ~float64 | ~string
}](a *Array[T]) {
reactive.ArraySortDesc(a)
}
// ArraySortFold sorts a case-insensitively using key to extract a string from
// each element. Comparison uses Unicode simple case-folding so "Abc" == "abc" == "ABC".
func ArraySortFold[T any](a *Array[T], key func(T) string) {
reactive.ArraySortFold(a, key)
}
// IndexOf returns the index of item in a, or -1 if absent.
func IndexOf[T comparable](a *Array[T], item T) int {
return reactive.IndexOf(a, item)
}
// Includes reports whether item is present in a.
func Includes[T comparable](a *Array[T], item T) bool {
return reactive.Includes(a, item)
}
// NewRecord creates an empty reactive Record.
func NewRecord() *Record {
return reactive.NewRecord()
}
// NewRecordFrom creates a reactive Record pre-populated from fields (copied).
func NewRecordFrom(fields map[string]any) *Record {
return reactive.NewRecordFrom(fields)
}
// =============================================================================
// Markup
// =============================================================================
// TextSpan represents a styled segment of text within a RichText component.
// Fields left at their zero values inherit from the parent RichText.
type TextSpan = markup.TextSpan
// Outline defines a text stroke rendered behind the fill.
type Outline = markup.Outline
var (
// ParseMarkup parses XML-like markup into TextSpan slices.
ParseMarkup = markup.ParseMarkup
// ParseColor parses a color string in any supported format.
ParseColor = markup.ParseColor
)
// =============================================================================
// Render
// =============================================================================
// Render — test-facing re-exports from internal/widget (backed by internal/render).
// SubRegion extracts a sub-region from a texture atlas region.
var SubRegion = widget.SubRegion
// CreateNineSliceNodes builds 9 sprite nodes for a nine-slice background.
var CreateNineSliceNodes = widget.CreateNineSliceNodes
// LayoutNineSlice positions and scales the 9 sprites of a nine-slice.
var LayoutNineSlice = widget.LayoutNineSlice
// RoundedRectPoints returns the outline points for a rounded rectangle.
var RoundedRectPoints = widget.RoundedRectPoints
// RoundedRectBorderMesh builds a mesh for a rounded rectangle border.
var RoundedRectBorderMesh = widget.RoundedRectBorderMesh
// LerpColor linearly interpolates between two colors.
var LerpColor = widget.LerpColor
// RoundedRectGradientMesh builds a gradient-filled rounded rectangle mesh.
var RoundedRectGradientMesh = widget.RoundedRectGradientMesh
// =============================================================================
// Core types
// =============================================================================
// ComponentState represents the visual state of a component.
type ComponentState = core.ComponentState
const (
StateDefault = core.StateDefault // Normal idle state.
StateHover = core.StateHover // Pointer is over the component.
StateActive = core.StateActive // Component is being pressed.
StateDisabled = core.StateDisabled // Component is non-interactive.
StateFocus = core.StateFocus // Component has keyboard focus.
StateFocusHover = core.StateFocusHover // Focused and hovered.
StateFocusActive = core.StateFocusActive // Focused and pressed.
StateFocusDisabled = core.StateFocusDisabled // Focused but disabled.
)
// BackgroundType tags the kind of background rendering.
type BackgroundType = core.BackgroundType
const (
BgNone = core.BgNone // No background rendered.
BgSolid = core.BgSolid // Flat solid-color fill.
BgNineSlice = core.BgNineSlice // Nine-slice image background.
BgGradient = core.BgGradient // Per-corner gradient fill.
)
// Rect describes a rectangle with position and dimensions.
// It is an alias for render.Rect.
type Rect = render.Rect
// NineSlice describes a nine-slice image for use as a component background.
// It is an alias for render.NineSlice.
type NineSlice = render.NineSlice
// GradientColors defines per-corner colors for gradient backgrounds.
// It is an alias for render.GradientColors.
type GradientColors = render.GradientColors
// Background describes how to render a component's background.
type Background = core.Background
// SolidBackground creates a solid-color background.
var SolidBackground = core.SolidBackground
// SliceBackground creates a nine-slice background.
var SliceBackground = core.SliceBackground
// GradientBackground creates a gradient background.
var GradientBackground = core.GradientBackground
// =============================================================================
// Theme
// =============================================================================
// Variant selects a color group for a component (e.g. Primary, Danger).
type Variant = theme.Variant
const (
Primary = theme.Primary // Primary action or branding color.
Secondary = theme.Secondary // Secondary or supporting color.
Accent = theme.Accent // Accent highlight color.
Neutral = theme.Neutral // Neutral/muted color.
Danger = theme.Danger // Destructive or error actions.
Success = theme.Success // Positive confirmation.
Warning = theme.Warning // Caution or non-blocking alert.
Info = theme.Info // Informational or help context.
Custom1 = theme.Custom1 // Application-defined variant 1.
Custom2 = theme.Custom2 // Application-defined variant 2.
Custom3 = theme.Custom3 // Application-defined variant 3.
Custom4 = theme.Custom4 // Application-defined variant 4.
Custom5 = theme.Custom5 // Application-defined variant 5.
Custom6 = theme.Custom6 // Application-defined variant 6.
Custom7 = theme.Custom7 // Application-defined variant 7.
Custom8 = theme.Custom8 // Application-defined variant 8.
Custom9 = theme.Custom9 // Application-defined variant 9.
Custom10 = theme.Custom10 // Application-defined variant 10.
Custom11 = theme.Custom11 // Application-defined variant 11.
Custom12 = theme.Custom12 // Application-defined variant 12.
Custom13 = theme.Custom13 // Application-defined variant 13.
Custom14 = theme.Custom14 // Application-defined variant 14.
Custom15 = theme.Custom15 // Application-defined variant 15.
Custom16 = theme.Custom16 // Application-defined variant 16.
Custom17 = theme.Custom17 // Application-defined variant 17.
Custom18 = theme.Custom18 // Application-defined variant 18.
Custom19 = theme.Custom19 // Application-defined variant 19.
Custom20 = theme.Custom20 // Application-defined variant 20.
Custom21 = theme.Custom21 // Application-defined variant 21.
Custom22 = theme.Custom22 // Application-defined variant 22.
Custom23 = theme.Custom23 // Application-defined variant 23.
Custom24 = theme.Custom24 // Application-defined variant 24.
Custom25 = theme.Custom25 // Application-defined variant 25.
Custom26 = theme.Custom26 // Application-defined variant 26.
Custom27 = theme.Custom27 // Application-defined variant 27.
Custom28 = theme.Custom28 // Application-defined variant 28.
Custom29 = theme.Custom29 // Application-defined variant 29.
Custom30 = theme.Custom30 // Application-defined variant 30.
Custom31 = theme.Custom31 // Application-defined variant 31.
Custom32 = theme.Custom32 // Application-defined variant 32.
Custom33 = theme.Custom33 // Application-defined variant 33.
Custom34 = theme.Custom34 // Application-defined variant 34.
Custom35 = theme.Custom35 // Application-defined variant 35.
Custom36 = theme.Custom36 // Application-defined variant 36.
Custom37 = theme.Custom37 // Application-defined variant 37.
Custom38 = theme.Custom38 // Application-defined variant 38.
Custom39 = theme.Custom39 // Application-defined variant 39.
Custom40 = theme.Custom40 // Application-defined variant 40.
Custom41 = theme.Custom41 // Application-defined variant 41.
Custom42 = theme.Custom42 // Application-defined variant 42.
Custom43 = theme.Custom43 // Application-defined variant 43.
Custom44 = theme.Custom44 // Application-defined variant 44.
Custom45 = theme.Custom45 // Application-defined variant 45.
Custom46 = theme.Custom46 // Application-defined variant 46.
Custom47 = theme.Custom47 // Application-defined variant 47.
Custom48 = theme.Custom48 // Application-defined variant 48.
Custom49 = theme.Custom49 // Application-defined variant 49.
Custom50 = theme.Custom50 // Application-defined variant 50.
Custom51 = theme.Custom51 // Application-defined variant 51.
Custom52 = theme.Custom52 // Application-defined variant 52.
Custom53 = theme.Custom53 // Application-defined variant 53.
Custom54 = theme.Custom54 // Application-defined variant 54.
Custom55 = theme.Custom55 // Application-defined variant 55.
Custom56 = theme.Custom56 // Application-defined variant 56.
)
// ColorProperty holds a color value for each component state.
type ColorProperty = theme.ColorProperty
// BackgroundProperty holds a background value for each component state.
type BackgroundProperty = theme.BackgroundProperty
// FloatProperty holds a float64 value for each component state.
type FloatProperty = theme.FloatProperty
var (
// NewColorPropUniform creates a ColorProperty with the same color for all states.
NewColorPropUniform = theme.NewColorPropUniform
// NewColorPropStates creates a ColorProperty with per-state colors.
NewColorPropStates = theme.NewColorPropStates
// NewSolidBgPropStates creates a BackgroundProperty with per-state solid backgrounds.
NewSolidBgPropStates = theme.NewSolidBgPropStates
// NewSolidBgPropUniform creates a BackgroundProperty with the same solid background for all states.
NewSolidBgPropUniform = theme.NewSolidBgPropUniform
// NewFloatPropUniform creates a FloatProperty with the same value for all states.
NewFloatPropUniform = theme.NewFloatPropUniform
// NewFloatPropStates creates a FloatProperty with per-state values.
NewFloatPropStates = theme.NewFloatPropStates
)
// Config is a generic component config with variant group support.
type Config[G any] = theme.Config[G]
// ShadowConfig describes a drop shadow for tooltip components.
type ShadowConfig = theme.ShadowConfig
// SpriteRef holds a resolved texture region from the theme atlas.
type SpriteRef = theme.SpriteRef
// Per-component Group types. Each Group holds the resolved visual properties
// (colors, sizes, corner radii, etc.) for one variant of a widget. Groups
// are loaded from the theme JSON and looked up at render time via Config[G].
// ButtonGroup holds theme properties for Button variants.
type ButtonGroup = theme.ButtonGroup
// LabelGroup holds theme properties for Label variants.
type LabelGroup = theme.LabelGroup
// BadgeGroup holds theme properties for Badge variants.
type BadgeGroup = theme.BadgeGroup
// ToggleGroup holds theme properties for Toggle variants.
type ToggleGroup = theme.ToggleGroup
// CheckboxGroup holds theme properties for Checkbox variants.
type CheckboxGroup = theme.CheckboxGroup
// RadioGroup holds theme properties for Radio variants.
type RadioGroup = theme.RadioGroup
// TextInputGroup holds theme properties for TextInput variants.
type TextInputGroup = theme.TextInputGroup
// MaskedInputGroup holds theme properties for MaskedInput variants.
type MaskedInputGroup = theme.MaskedInputGroup
// TextAreaGroup holds theme properties for TextArea variants.
type TextAreaGroup = theme.TextAreaGroup
// SliderGroup holds theme properties for Slider variants.
type SliderGroup = theme.SliderGroup
// ScrollBarGroup holds theme properties for ScrollBar variants.
type ScrollBarGroup = theme.ScrollBarGroup
// MeterBarGroup holds theme properties for MeterBar variants.
type MeterBarGroup = theme.MeterBarGroup
// PanelGroup holds theme properties for Panel variants.
type PanelGroup = theme.PanelGroup
// NavDrawerGroup holds theme properties for NavDrawer variants.
type NavDrawerGroup = theme.NavDrawerGroup
// WindowGroup holds theme properties for Window variants.
type WindowGroup = theme.WindowGroup
// TabsGroup holds theme properties for TabBar variants.
type TabsGroup = theme.TabsGroup
// ListGroup holds theme properties for List variants.
type ListGroup = theme.ListGroup
// TreeListGroup holds theme properties for TreeList variants.
type TreeListGroup = theme.TreeListGroup
// TileListGroup holds theme properties for TileList variants.
type TileListGroup = theme.TileListGroup
// RichTextGroup holds theme properties for RichText variants.
type RichTextGroup = theme.RichTextGroup
// OptionRotatorChevronGroup holds theme properties for OptionRotator chevron arrows.
type OptionRotatorChevronGroup = theme.OptionRotatorChevronGroup
// OptionRotatorGroup holds theme properties for OptionRotator variants.
type OptionRotatorGroup = theme.OptionRotatorGroup
// ToggleButtonBarGroup holds theme properties for ToggleButtonBar variants.
type ToggleButtonBarGroup = theme.ToggleButtonBarGroup
// TooltipGroup holds theme properties for Tooltip variants.
type TooltipGroup = theme.TooltipGroup
// MenuBarGroup holds theme properties for MenuBar variants.
type MenuBarGroup = theme.MenuBarGroup
// MenuPopupGroup holds theme properties for MenuPopup variants.
type MenuPopupGroup = theme.MenuPopupGroup
// SelectGroup holds theme properties for Select dropdown variants.
type SelectGroup = theme.SelectGroup
// DragHandleGroup holds theme properties for DragHandle variants.
type DragHandleGroup = theme.DragHandleGroup
// ImageGroup holds theme properties for Image variants.
type ImageGroup = theme.ImageGroup
// AnimatedImageGroup holds theme properties for AnimatedImage variants.
type AnimatedImageGroup = theme.AnimatedImageGroup
// ColorPickerGroup holds theme properties for ColorPicker variants.
type ColorPickerGroup = theme.ColorPickerGroup
// GradientEditorGroup holds theme properties for GradientEditor variants.
type GradientEditorGroup = theme.GradientEditorGroup
// ToastGroup holds theme properties for Toast variants.
type ToastGroup = theme.ToastGroup
// SortableListGroup holds theme properties for SortableList variants.
type SortableListGroup = theme.SortableListGroup
// SortableTreeListGroup holds theme properties for SortableTreeList variants.
type SortableTreeListGroup = theme.SortableTreeListGroup
// IconButtonGroup holds theme properties for IconButton variants.
type IconButtonGroup = theme.IconButtonGroup
// StatWebGroup holds theme properties for StatWeb variants.
type StatWebGroup = theme.StatWebGroup
// AccordionGroup holds theme properties for Accordion variants.
type AccordionGroup = theme.AccordionGroup
// TagGroup holds theme properties for Tag variants.
type TagGroup = theme.TagGroup
// TagBarGroup holds theme properties for TagBar variants.
type TagBarGroup = theme.TagBarGroup
// PopoverGroup holds theme properties for Popover variants.
type PopoverGroup = theme.PopoverGroup
// TreeTableGroup holds theme properties for TreeTable variants.
type TreeTableGroup = theme.TreeTableGroup
// DataTableGroup holds theme properties for DataTable variants.
type DataTableGroup = theme.DataTableGroup
// KeybindInputGroup holds theme properties for KeybindInput variants.
type KeybindInputGroup = theme.KeybindInputGroup
// TimePickerGroup holds theme properties for TimePicker variants.
type TimePickerGroup = theme.TimePickerGroup
// ImageCropperGroup holds theme properties for ImageCropper variants.
type ImageCropperGroup = theme.ImageCropperGroup
// ToolBarGroup holds theme properties for ToolBar variants.
type ToolBarGroup = theme.ToolBarGroup
// CalendarSelectorGroup holds theme properties for CalendarSelector variants.
type CalendarSelectorGroup = theme.CalendarSelectorGroup
// RichTextEditorGroup holds theme properties for RichTextEditor variants.
type RichTextEditorGroup = theme.RichTextEditorGroup
// PropertyInspectorGroup holds theme properties for PropertyInspector variants.
type PropertyInspectorGroup = theme.PropertyInspectorGroup
// UserGroup holds the parsed visual properties for a user-defined component variant.
type UserGroup = theme.UserGroup
// UserConfig holds a user-defined component configuration with variant support.
type UserConfig = theme.UserConfig
// Per-component Config types. Each Config is a Config[G] alias mapping
// variant names to their Group. Use SetTheme to load configs from JSON.
// ButtonConfig maps variant names to ButtonGroup.
type ButtonConfig = theme.ButtonConfig
// LabelConfig maps variant names to LabelGroup.
type LabelConfig = theme.LabelConfig
// BadgeConfig maps variant names to BadgeGroup.
type BadgeConfig = theme.BadgeConfig
// ToggleConfig maps variant names to ToggleGroup.
type ToggleConfig = theme.ToggleConfig
// CheckboxConfig maps variant names to CheckboxGroup.
type CheckboxConfig = theme.CheckboxConfig
// RadioConfig maps variant names to RadioGroup.
type RadioConfig = theme.RadioConfig
// TextInputConfig maps variant names to TextInputGroup.
type TextInputConfig = theme.TextInputConfig
// MaskedInputConfig maps variant names to MaskedInputGroup.
type MaskedInputConfig = theme.MaskedInputConfig
// TextAreaConfig maps variant names to TextAreaGroup.
type TextAreaConfig = theme.TextAreaConfig
// SliderConfig maps variant names to SliderGroup.
type SliderConfig = theme.SliderConfig
// ScrollBarConfig maps variant names to ScrollBarGroup.
type ScrollBarConfig = theme.ScrollBarConfig
// MeterBarConfig maps variant names to MeterBarGroup.
type MeterBarConfig = theme.MeterBarConfig
// PanelConfig maps variant names to PanelGroup.
type PanelConfig = theme.PanelConfig
// NavDrawerConfig maps variant names to NavDrawerGroup.
type NavDrawerConfig = theme.NavDrawerConfig
// WindowConfig maps variant names to WindowGroup.
type WindowConfig = theme.WindowConfig
// TabsConfig maps variant names to TabsGroup.
type TabsConfig = theme.TabsConfig
// ListConfig maps variant names to ListGroup.
type ListConfig = theme.ListConfig
// TreeListConfig maps variant names to TreeListGroup.
type TreeListConfig = theme.TreeListConfig
// TileListConfig maps variant names to TileListGroup.
type TileListConfig = theme.TileListConfig
// RichTextConfig maps variant names to RichTextGroup.
type RichTextConfig = theme.RichTextConfig
// OptionRotatorConfig maps variant names to OptionRotatorGroup.
type OptionRotatorConfig = theme.OptionRotatorConfig
// ToggleButtonBarConfig maps variant names to ToggleButtonBarGroup.
type ToggleButtonBarConfig = theme.ToggleButtonBarConfig
// TooltipConfig maps variant names to TooltipGroup.
type TooltipConfig = theme.TooltipConfig
// MenuBarConfig maps variant names to MenuBarGroup.
type MenuBarConfig = theme.MenuBarConfig
// MenuPopupConfig maps variant names to MenuPopupGroup.
type MenuPopupConfig = theme.MenuPopupConfig
// SelectConfig maps variant names to SelectGroup.
type SelectConfig = theme.SelectConfig
// DragHandleConfig maps variant names to DragHandleGroup.
type DragHandleConfig = theme.DragHandleConfig
// ImageConfig maps variant names to ImageGroup.
type ImageConfig = theme.ImageConfig
// AnimatedImageConfig maps variant names to AnimatedImageGroup.
type AnimatedImageConfig = theme.AnimatedImageConfig
// ColorPickerConfig maps variant names to ColorPickerGroup.
type ColorPickerConfig = theme.ColorPickerConfig
// GradientEditorConfig maps variant names to GradientEditorGroup.
type GradientEditorConfig = theme.GradientEditorConfig
// ToastConfig maps variant names to ToastGroup.
type ToastConfig = theme.ToastConfig
// SortableListConfig maps variant names to SortableListGroup.
type SortableListConfig = theme.SortableListConfig
// SortableTreeListConfig maps variant names to SortableTreeListGroup.
type SortableTreeListConfig = theme.SortableTreeListConfig
// IconButtonConfig maps variant names to IconButtonGroup.
type IconButtonConfig = theme.IconButtonConfig
// StatWebConfig maps variant names to StatWebGroup.
type StatWebConfig = theme.StatWebConfig
// AccordionConfig maps variant names to AccordionGroup.
type AccordionConfig = theme.AccordionConfig
// TagConfig maps variant names to TagGroup.
type TagConfig = theme.TagConfig
// TagBarConfig maps variant names to TagBarGroup.
type TagBarConfig = theme.TagBarConfig
// PopoverConfig maps variant names to PopoverGroup.
type PopoverConfig = theme.PopoverConfig
// TreeTableConfig maps variant names to TreeTableGroup.
type TreeTableConfig = theme.TreeTableConfig
// DataTableConfig maps variant names to DataTableGroup.
type DataTableConfig = theme.DataTableConfig
// KeybindInputConfig maps variant names to KeybindInputGroup.
type KeybindInputConfig = theme.KeybindInputConfig
// TimePickerConfig maps variant names to TimePickerGroup.
type TimePickerConfig = theme.TimePickerConfig
// ImageCropperConfig maps variant names to ImageCropperGroup.
type ImageCropperConfig = theme.ImageCropperConfig
// ToolBarConfig maps variant names to ToolBarGroup.
type ToolBarConfig = theme.ToolBarConfig
// CalendarSelectorConfig maps variant names to CalendarSelectorGroup.
type CalendarSelectorConfig = theme.CalendarSelectorConfig
// RichTextEditorConfig maps variant names to RichTextEditorGroup.
type RichTextEditorConfig = theme.RichTextEditorConfig
// PropertyInspectorConfig maps variant names to PropertyInspectorGroup.
type PropertyInspectorConfig = theme.PropertyInspectorConfig
// HeadingLevel represents a heading size level for rich text content.
type HeadingLevel = int
const (
HeadingNone HeadingLevel = 0 // No heading style.
Heading1 HeadingLevel = 1 // Largest heading.
Heading2 HeadingLevel = 2 // Medium heading.
Heading3 HeadingLevel = 3 // Smallest heading.
)
// Theme holds the complete visual configuration for all WillowUI components.
type Theme = theme.Theme
// DefaultTheme is the fallback theme used when no explicit theme is set.
// This is the canonical variable; theme.DefaultThemeRef is redirected here
// at init time so that widget.EffectiveTheme() always reads from this variable.
var DefaultTheme = theme.DefaultTheme
func init() {
// Redirect the internal/theme indirection to point at this package's
// DefaultTheme variable. This ensures that widget.EffectiveTheme()
// returns the current value of willowui.DefaultTheme whenever it is
// reassigned (e.g. in tests or user code).
theme.DefaultThemeRef = &DefaultTheme
// Inject the embedded glyph spritesheet into the widget package so
// default icons (chevrons, close X, sort arrows, etc.) are decoded
// from the pre-baked PNG rather than generated procedurally.
widget.SetGlyphSheet(embeddedGlyphSheet)
}
// LoadTheme parses JSON theme data and produces a *Theme.
// Returns an error if validation fails (bad colors, missing required groups, etc.).
// Nine-slice images are rejected — use LoadThemeFromFile or LoadThemeFromFS.
var LoadTheme = theme.LoadTheme
// LoadThemeRelative loads a theme JSON file resolved relative to the caller's
// source file. This is convenient for examples and tests where the JSON file
// sits next to the Go source.
func LoadThemeRelative(filename string) (*Theme, error) {
_, src, _, ok := runtime.Caller(1)
if !ok {
return nil, fmt.Errorf("LoadThemeRelative: unable to determine caller path")
}
return theme.LoadThemeFromFile(filepath.Join(filepath.Dir(src), filename))
}
// LoadThemeFromFile reads a JSON file and compiles the theme.
// Nine-slice image paths are resolved relative to the JSON file's directory.
var LoadThemeFromFile = theme.LoadThemeFromFile
// LoadThemeFromFS reads a JSON file from an fs.FS and compiles the theme.
// Nine-slice image paths are resolved within the FS.
var LoadThemeFromFS = func(fsys fs.FS, path string) (*Theme, error) {
return theme.LoadThemeFromFS(fsys, path)
}
// ValidateTheme checks that the given theme defines configs for all the
// named component types. Returns an error listing any missing configs.
var ValidateTheme = theme.ValidateTheme
// CollectThemeImages extracts all nine-slice image paths from theme JSON
// without loading them. Use this for prebaked atlas tooling.
var CollectThemeImages = theme.CollectThemeImages
// LoadThemeBinary decodes a WUIT binary (.theme file) and compiles the theme.
// The atlas (if present) is decoded from the embedded PNG + JSON sections.
var LoadThemeBinary = theme.LoadThemeBinary
// EncodeThemeBinary encodes theme JSON, atlas JSON, and atlas PNG into
// the WUIT binary format. Use the themec CLI tool for full compilation.
var EncodeThemeBinary = theme.EncodeThemeBinary
// =============================================================================
// Component & Layout
// =============================================================================
// Insets holds top/right/bottom/left spacing values used for padding and margin.
type Insets = widget.Insets
// UIElement is implemented by all UI component types in this package.
type UIElement = widget.UIElement
// Component is the base type for all WillowUI widgets.
type Component = widget.Component
// NewComponent creates a new Component with sensible defaults.
var NewComponent = widget.NewComponent
// NewHBox creates a Component with LayoutHBox pre-configured.
var NewHBox = widget.NewHBox
// NewVBox creates a Component with LayoutVBox pre-configured.
var NewVBox = widget.NewVBox
// NewFlow creates a Component with LayoutFlow pre-configured.
var NewFlow = widget.NewFlow
// LayoutMode controls how a Component arranges its children.
type LayoutMode = widget.LayoutMode
const (
LayoutNone = widget.LayoutNone // No automatic layout; children are manually positioned.
LayoutVBox = widget.LayoutVBox // Vertical stack layout.
LayoutHBox = widget.LayoutHBox // Horizontal row layout.
LayoutGrid = widget.LayoutGrid // Grid layout with rows and columns.
LayoutFlow = widget.LayoutFlow // Flowing wrap layout.
LayoutAnchor = widget.LayoutAnchor // Anchor-based absolute positioning within parent.
)
// Alignment controls child positioning.
type Alignment = widget.Alignment
const (
AlignStart = widget.AlignStart // Align children to the start (left or top).
AlignCenter = widget.AlignCenter // Center children along the axis.
AlignEnd = widget.AlignEnd // Align children to the end (right or bottom).
AlignSpaceBetween = widget.AlignSpaceBetween // Distribute children with equal space between.
)
// FillMode controls how a component stretches to fill its parent's content area.
type FillMode = widget.FillMode
const (
FillNone = widget.FillNone // No stretching.
FillWidth = widget.FillWidth // Stretch to parent's content width.
FillHeight = widget.FillHeight // Stretch to parent's content height.
FillBoth = widget.FillBoth // Stretch to fill both dimensions.
)
// Orientation represents horizontal or vertical direction.
type Orientation = widget.Orientation
const (
Horizontal = widget.Horizontal // Left-to-right orientation.
Vertical = widget.Vertical // Top-to-bottom orientation.
)
// =============================================================================
// Focus & Input
// =============================================================================
// InputManager reads keyboard state once per frame, tracks consumed keys,
// and exposes availability queries and event-style listeners for game logic.
type InputManager = widget.InputManager
// Input is the package-level InputManager singleton. Game logic reads key
// state through this instead of ebiten directly.
var Input = widget.DefaultInputManager
// NewInputManager creates an isolated InputManager (primarily for tests).
var NewInputManager = widget.NewInputManager
// ListenerHandle identifies a registered key listener for later removal.
type ListenerHandle = widget.ListenerHandle
// FocusManager tracks which component has keyboard focus.
type FocusManager = widget.FocusManager
// FM is the package-level FocusManager singleton. UI widgets and the
// screen system use this for focus dispatch, hotkeys, and navigation.
var FM = widget.DefaultFocusManager
// DefaultFocusManager is an alias for FM (backwards compatibility).
var DefaultFocusManager = widget.DefaultFocusManager
// NewFocusManager creates an empty focus manager.
var NewFocusManager = widget.NewFocusManager
// ModifierMask is a bitmask of modifier keys for keybind registration.
type ModifierMask = widget.ModifierMask
const (
ModNone = widget.ModNone // No modifier keys.
ModCtrl = widget.ModCtrl // Ctrl (or Cmd on macOS).
ModShift = widget.ModShift // Shift key.
ModAlt = widget.ModAlt // Alt (or Option on macOS).
)
// KeyCombo pairs an ebiten key with a modifier mask.
type KeyCombo = widget.KeyCombo
// Key creates a KeyCombo from a key and modifier mask.
var Key = widget.Key
// BindHandle identifies a registered keybind for later removal.
type BindHandle = widget.BindHandle
// =============================================================================
// Stage API
// =============================================================================
// FXAAConfig holds tunable parameters for the FXAA post-process pass.
// Use DefaultFXAAConfig for sensible defaults.
type FXAAConfig = sg.FXAAConfig
// DefaultFXAAConfig returns an FXAAConfig with FXAA 3.11 quality-15 defaults.
var DefaultFXAAConfig = sg.DefaultFXAAConfig
//go:embed assets/gofont.fontbundle
var embeddedGoFont []byte
//go:embed assets/icons/default-glyphs.png
var embeddedGlyphSheet []byte
// DefaultFont is the default FontFamily. If not set by StageConfig.Font or
// directly, Setup auto-loads the embedded Go font bundle.
var DefaultFont *sg.FontFamily
// EmbeddedGoFont is the raw bytes of the embedded Go font bundle
// (Regular + Bold + Italic + BoldItalic). Pass to
// willow.NewFontFamilyFromFontBundle to create a FontFamily manually,
// or use MustLoadDefaultFont for convenience.
var EmbeddedGoFont = embeddedGoFont
// MustLoadDefaultFont loads the embedded Go font bundle into DefaultFont
// and returns it. If DefaultFont is already loaded, it returns the existing
// value. This is intended for use in examples that need a font before
// ui.Setup runs. Panics on load failure.
func MustLoadDefaultFont() *sg.FontFamily {
if DefaultFont != nil {
return DefaultFont
}
ff, err := sg.NewFontFamilyFromFontBundle(embeddedGoFont)
if err != nil {
panic("willowui: failed to load embedded font: " + err.Error())
}
DefaultFont = ff
return DefaultFont
}
// DefaultSharpness is the recommended SDF sharpness value for labels.
const DefaultSharpness = 0.15
// FontSource is a type alias for *sg.FontFamily, kept for backward
// compatibility. New code should use *sg.FontFamily directly.
type FontSource = *sg.FontFamily
// RecommendedFXAAConfig returns the moderate FXAA config used by default in
// Setup — SubpixQuality=0.5, EdgeThreshold=0.275, EdgeThresholdMin=0.0505.
func RecommendedFXAAConfig() FXAAConfig {
return FXAAConfig{
SubpixQuality: 0.5,
EdgeThreshold: 0.275,
EdgeThresholdMin: 0.0505,
}
}
// StageConfig holds the window and scene configuration for ui.Setup.
type StageConfig struct {
Title string
Width int
Height int
ClearColor sg.Color
// Font, when non-nil, is a *sg.FontFamily used as DefaultFont
// before any controller OnCreate is called.
Font *sg.FontFamily
// FXAA overrides the FXAA post-process configuration. When nil, Setup uses
// RecommendedFXAAConfig() automatically. Set DisableFXAA to opt out entirely.
FXAA *FXAAConfig
// DisableFXAA opts out of the default FXAA pass. Has no effect when FXAA
// is set explicitly.
DisableFXAA bool
}
// StageManager manages a stack of Screens. Use the package-level Stage
// singleton in application code.
type StageManager = widget.StageManager
// Stage is the package-level screen-stack singleton. Add, remove, and replace
// screens here; the scene is wired automatically by Setup.
var Stage = widget.DefaultStage
// NewStageManager creates an isolated StageManager. Intended for testing;
// production code uses ui.Stage.
var NewStageManager = widget.NewStageManager
// Setup configures the application window, creates the internal scene, and
// starts the game loop.
// Setup never returns; errors are printed to stderr and the process exits.
//
// When components are passed, Setup creates a Screen, adds them to it, and
// pushes it onto the Stage automatically — no manual Screen/Stage wiring needed.
func Setup(cfg StageConfig, components ...UIElement) {
if len(components) > 0 {
screen := widget.NewScreen()
for _, c := range components {
screen.Add(c)
}
Stage.Add(screen)
}
// Set DefaultFont: use config font, or fall back to embedded Go font bundle.
if cfg.Font != nil && DefaultFont == nil {
DefaultFont = cfg.Font
}
if DefaultFont == nil {
ff, err := sg.NewFontFamilyFromFontBundle(embeddedGoFont)
if err != nil {
fmt.Fprintf(os.Stderr, "willowui: failed to load embedded font: %v\n", err)
os.Exit(1)
}
DefaultFont = ff
}
// Default FXAA to RecommendedFXAAConfig unless explicitly overridden or disabled.