-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoflow.go
More file actions
607 lines (472 loc) · 19 KB
/
goflow.go
File metadata and controls
607 lines (472 loc) · 19 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
// Package goflow provides a declarative UI framework for Go, inspired by Flutter.
// It offers a single import path for all framework functionality.
//
// Example usage:
//
// import gf "github.com/base-go/GoFlow"
//
// func main() {
// count := gf.CreateSignal(0)
//
// app := gf.Container{
// Child: gf.Center{
// Child: gf.Column{
// Children: []gf.Widget{
// gf.Text{Content: "Counter Example"},
// gf.Text{Content: fmt.Sprintf("Count: %d", count.Get())},
// },
// },
// },
// }
//
// gf.RunApp(app)
// }
package goflow
import (
"github.com/base-go/GoFlow/pkg/core/animation"
framework "github.com/base-go/GoFlow/pkg/core/framework"
"github.com/base-go/GoFlow/pkg/core/signals"
"github.com/base-go/GoFlow/pkg/core/widgets"
"github.com/base-go/GoFlow/pkg/hotreload"
"github.com/base-go/GoFlow/pkg/input"
"github.com/base-go/GoFlow/pkg/navigation"
"github.com/base-go/GoFlow/pkg/testing"
"github.com/base-go/GoFlow/pkg/ui/adaptive"
"github.com/base-go/GoFlow/pkg/ui/cupertino"
"github.com/base-go/GoFlow/pkg/ui/material"
)
// ============================================================================
// Core Framework Types
// ============================================================================
// Widget is the base interface for all UI components.
type Widget = framework.Widget
// Element represents a widget instance in the widget tree.
type Element = framework.Element
// BuildContext provides context information during widget builds.
type BuildContext = framework.BuildContext
// RenderObject handles layout and painting operations.
type RenderObject = framework.RenderObject
// App represents the application root.
type App = framework.App
// BaseWidget provides a base implementation for stateless widgets.
type BaseWidget = framework.BaseWidget
// BaseElement provides a base implementation for elements.
type BaseElement = framework.BaseElement
// BaseRenderBox provides a base implementation for render objects.
type BaseRenderBox = framework.BaseRenderBox
// ============================================================================
// Geometry Types
// ============================================================================
// Size represents 2D dimensions (width, height).
type Size = framework.Size
// Offset represents a 2D position (x, y).
type Offset = framework.Offset
// Rect represents a rectangle (position + size).
type Rect = framework.Rect
// Constraints define layout constraints for widgets.
type Constraints = framework.Constraints
// EdgeInsets represents spacing/padding on all four sides.
type EdgeInsets = framework.EdgeInsets
// ============================================================================
// Styling Types
// ============================================================================
// Color represents an RGBA color.
type Color = framework.Color
// Paint defines drawing properties (color, stroke, etc.).
type Paint = framework.Paint
// TextStyle defines text appearance (font, size, color, etc.).
type TextStyle = framework.TextStyle
// Canvas provides a drawing surface.
type Canvas = framework.Canvas
// ============================================================================
// Color Constants
// ============================================================================
var (
ColorBlack = framework.ColorBlack
ColorWhite = framework.ColorWhite
ColorRed = framework.ColorRed
ColorGreen = framework.ColorGreen
ColorBlue = framework.ColorBlue
ColorYellow = framework.ColorYellow
ColorCyan = framework.ColorCyan
ColorMagenta = framework.ColorMagenta
ColorGray = framework.ColorGray
ColorTransparent = framework.ColorTransparent
)
// ============================================================================
// Platform Constants
// ============================================================================
const (
PlatformAndroid = framework.PlatformAndroid
PlatformIOS = framework.PlatformIOS
PlatformMacOS = framework.PlatformMacOS
PlatformLinux = framework.PlatformLinux
PlatformWindows = framework.PlatformWindows
PlatformWeb = framework.PlatformWeb
PlatformFuchsia = framework.PlatformFuchsia
)
// ============================================================================
// Core Framework Functions
// ============================================================================
// RunApp is the main entry point to start a GoFlow application.
var RunApp = framework.RunApp
// NewApp creates a new application instance with specified dimensions.
var NewApp = framework.NewApp
// Platform detection and management
var (
DetectPlatform = framework.DetectPlatform
GetPlatform = framework.GetPlatform
SetPlatform = framework.SetPlatform
)
// Constraint helpers
var (
TightConstraints = framework.TightConstraints
LooseConstraints = framework.LooseConstraints
UnboundedConstraints = framework.UnboundedConstraints
)
// Geometry helpers
var (
NewSize = framework.NewSize
NewOffset = framework.NewOffset
NewRect = framework.NewRect
ZeroSize = framework.ZeroSize
ZeroOffset = framework.ZeroOffset
)
// Styling helpers
var (
NewColor = framework.NewColor
NewPaint = framework.NewPaint
NewTextStyle = framework.NewTextStyle
NewEdgeInsets = framework.NewEdgeInsets
NewEdgeInsetsAll = framework.NewEdgeInsetsAll
NewEdgeInsetsSymmetric = framework.NewEdgeInsetsSymmetric
)
// ============================================================================
// Layout Widgets
// ============================================================================
// Column arranges widgets vertically.
type Column = widgets.Column
// Row arranges widgets horizontally.
type Row = widgets.Row
// Stack overlays widgets on top of each other.
type Stack = widgets.Stack
// Wrap flows widgets and wraps to the next line when needed.
type Wrap = widgets.Wrap
// Center centers its child widget.
type Center = widgets.Center
// Align positions its child within itself.
type Align = widgets.Align
// Container is a multi-purpose widget combining common styling and layout.
type Container = widgets.Container
// Padding adds padding around its child.
type Padding = widgets.Padding
// SizedBox creates a fixed-size box.
type SizedBox = widgets.SizedBox
// Flexible controls how a child flexes in a Row or Column.
type Flexible = widgets.Flexible
// Expanded makes a child fill available space in a Row or Column.
type Expanded = widgets.Expanded
// ============================================================================
// Display Widgets
// ============================================================================
// Text displays a string of text.
type Text = widgets.Text
// Icon displays an icon.
type Icon = widgets.Icon
// Image displays an image.
type Image = widgets.Image
// Badge displays a notification badge.
type Badge = widgets.Badge
// Chip displays a material chip (compact element).
type Chip = widgets.Chip
// ActionChip displays an action chip.
type ActionChip = widgets.ActionChip
// Divider displays a visual separator line.
type Divider = widgets.Divider
// ============================================================================
// Input Widgets
// ============================================================================
// TextField is a text input widget.
type TextField = widgets.TextField
// Checkbox is a boolean selection widget.
type Checkbox = widgets.Checkbox
// Radio is a single selection widget within a group.
type Radio = widgets.Radio
// Switch is a toggle switch widget.
type Switch = widgets.Switch
// Slider is a range selection widget.
type Slider = widgets.Slider
// RangeSlider is a dual-handle range selection widget.
type RangeSlider = widgets.RangeSlider
// RangeValues represents a range of values for RangeSlider.
type RangeValues = widgets.RangeValues
// DropdownButton is a dropdown menu widget.
type DropdownButton = widgets.DropdownButton
// Form manages form fields and validation.
type Form = widgets.Form
// FormField represents a single form field.
type FormField = widgets.FormField
// GestureDetector recognizes gestures on its child.
type GestureDetector = widgets.GestureDetector
// ============================================================================
// Data Display Widgets
// ============================================================================
// ListView displays a scrollable list of widgets.
type ListView = widgets.ListView
// DataTable displays data in a table format.
type DataTable = widgets.DataTable
// PaginatedDataTable displays a paginated data table.
type PaginatedDataTable = widgets.PaginatedDataTable
// ExpansionPanel displays expandable/collapsible panels.
type ExpansionPanel = widgets.ExpansionPanel
// ExpansionTile displays an expandable list tile.
type ExpansionTile = widgets.ExpansionTile
// TreeView displays hierarchical data in a tree structure.
type TreeView = widgets.TreeView
// Card displays content in a material card.
type Card = widgets.Card
// ============================================================================
// Animation Widgets
// ============================================================================
// AnimatedContainer animates container property changes.
type AnimatedContainer = widgets.AnimatedContainer
// AnimatedOpacity animates opacity changes.
type AnimatedOpacity = widgets.AnimatedOpacity
// AnimatedSize animates size changes.
type AnimatedSize = widgets.AnimatedSize
// FadeTransition animates opacity with an animation controller.
type FadeTransition = widgets.FadeTransition
// ScaleTransition animates scale with an animation controller.
type ScaleTransition = widgets.ScaleTransition
// SlideTransition animates position with an animation controller.
type SlideTransition = widgets.SlideTransition
// RotationTransition animates rotation with an animation controller.
type RotationTransition = widgets.RotationTransition
// AnimatedBuilder builds widgets based on animation values.
type AnimatedBuilder = widgets.AnimatedBuilder
// Hero creates shared element transitions between routes.
type Hero = widgets.Hero
// ============================================================================
// Other Widgets
// ============================================================================
// PageView displays swipeable pages.
type PageView = widgets.PageView
// ScrollController controls scrollable widgets.
type ScrollController = widgets.ScrollController
// FocusNode represents a focus target.
type FocusNode = widgets.FocusNode
// FocusScope manages focus within a subtree.
type FocusScope = widgets.FocusScope
// DatePicker displays a date picker.
type DatePicker = widgets.DatePicker
// TimePicker displays a time picker.
type TimePicker = widgets.TimePicker
// ColorPicker displays a color picker.
type ColorPicker = widgets.ColorPicker
// ============================================================================
// Layout Alignment Constants
// ============================================================================
// MainAxisAlignment constants
const (
MainAxisStart = widgets.MainAxisStart
MainAxisEnd = widgets.MainAxisEnd
MainAxisCenter = widgets.MainAxisCenter
MainAxisSpaceBetween = widgets.MainAxisSpaceBetween
MainAxisSpaceAround = widgets.MainAxisSpaceAround
MainAxisSpaceEvenly = widgets.MainAxisSpaceEvenly
)
// CrossAxisAlignment constants
const (
CrossAxisStart = widgets.CrossAxisStart
CrossAxisEnd = widgets.CrossAxisEnd
CrossAxisCenter = widgets.CrossAxisCenter
CrossAxisStretch = widgets.CrossAxisStretch
)
// MainAxisSize constants
const (
MainAxisSizeMin = widgets.MainAxisSizeMin
MainAxisSizeMax = widgets.MainAxisSizeMax
)
// ============================================================================
// Reactive State Management (Signals)
// ============================================================================
// Signal is a reactive value container that notifies listeners on changes.
type Signal[T any] = signals.Signal[T]
// Computed is a derived reactive value that recomputes when dependencies change.
type Computed[T any] = signals.Computed[T]
// SignalSlice is a reactive slice.
type SignalSlice[T any] = signals.SignalSlice[T]
// SignalMap is a reactive map.
type SignalMap[K comparable, V any] = signals.SignalMap[K, V]
// Signal creation and management functions
// CreateSignal creates a new signal with an initial value.
func CreateSignal[T any](initialValue T) *Signal[T] {
return signals.New(initialValue)
}
// CreateComputed creates a computed value that derives from other signals.
func CreateComputed[T any](computeFn func() T) *Computed[T] {
return signals.NewComputed(computeFn)
}
// CreateEffect creates a side effect that runs when dependencies change.
func CreateEffect(effectFn func()) func() {
return signals.NewEffect(effectFn)
}
// Batch batches multiple signal updates into a single notification.
func Batch(fn func()) {
signals.Batch(fn)
}
// Untracked runs a function without tracking signal dependencies.
func Untracked[T any](fn func() T) T {
return signals.Untracked(fn)
}
// CreateSignalSlice creates a reactive slice.
func CreateSignalSlice[T any](initialValue []T) *SignalSlice[T] {
return signals.NewSlice(initialValue)
}
// CreateSignalMap creates a reactive map.
func CreateSignalMap[K comparable, V any](initialValue map[K]V) *SignalMap[K, V] {
return signals.NewMap(initialValue)
}
// ============================================================================
// Animation System
// ============================================================================
// Animation represents an animation.
type Animation = animation.Animation
// AnimationController controls animation playback.
type AnimationController = animation.AnimationController
// AnimationStatus represents the animation state.
type AnimationStatus = animation.AnimationStatus
// NewAnimationController creates a new animation controller.
var NewAnimationController = animation.NewAnimationController
// ============================================================================
// Material Design (Material UI)
// ============================================================================
// Material widget types with "Material" prefix to avoid conflicts
type (
MaterialAppBar = material.AppBar
MaterialScaffold = material.Scaffold
MaterialButton = material.Button
MaterialFloatingActionButton = material.FloatingActionButton
MaterialCard = material.Card
MaterialDrawer = material.Drawer
MaterialDrawerHeader = material.DrawerHeader
MaterialBottomNavigationBar = material.BottomNavigationBar
MaterialTextField = material.TextField
MaterialCheckbox = material.Checkbox
MaterialRadio = material.Radio
MaterialSwitch = material.Switch
MaterialSlider = material.Slider
MaterialDialog = material.Dialog
MaterialAlertDialog = material.AlertDialog
MaterialTheme = material.MaterialTheme
)
// Material theme functions
var (
DefaultLightTheme = material.DefaultLightTheme
DefaultDarkTheme = material.DefaultDarkTheme
)
// ============================================================================
// Cupertino (iOS-style UI)
// ============================================================================
// Cupertino widget types with "Cupertino" prefix
type (
CupertinoPageScaffold = cupertino.CupertinoPageScaffold
CupertinoTabScaffold = cupertino.CupertinoTabScaffold
CupertinoNavigationBar = cupertino.NavigationBar
CupertinoButton = cupertino.Button
CupertinoTextField = cupertino.CupertinoTextField
CupertinoSwitch = cupertino.CupertinoSwitch
CupertinoSlider = cupertino.CupertinoSlider
CupertinoCard = cupertino.Card
CupertinoTheme = cupertino.CupertinoTheme
)
// ============================================================================
// Adaptive (Cross-platform UI)
// ============================================================================
// Adaptive widget types with "Adaptive" prefix
type (
AdaptiveButton = adaptive.Button
AdaptiveAppBar = adaptive.AppBar
AdaptiveCard = adaptive.Card
)
// ============================================================================
// Navigation (GetX-style)
// ============================================================================
// Get is the global navigation instance providing navigation methods.
var Get = navigation.Get
// Navigation types
type (
Navigator = navigation.Navigator
Route = navigation.Route
RouteBuilder = navigation.RouteBuilder
)
// Navigation app constructors
var (
GetApp = navigation.GetApp
GetMaterialApp = navigation.GetMaterialApp
GetCupertinoApp = navigation.GetCupertinoApp
)
// Navigation helper functions
var (
ShowDialog = navigation.ShowDialog
ShowAlertDialog = navigation.ShowAlertDialog
ShowBottomSheet = navigation.ShowBottomSheet
ShowModalBottomSheet = navigation.ShowModalBottomSheet
ShowSnackbar = navigation.ShowSnackbar
)
// Navigation transition constants
const (
TransitionFade = navigation.TransitionFade
TransitionSlideRight = navigation.TransitionSlideRight
TransitionSlideLeft = navigation.TransitionSlideLeft
TransitionSlideUp = navigation.TransitionSlideUp
TransitionSlideDown = navigation.TransitionSlideDown
TransitionZoom = navigation.TransitionZoom
)
// ============================================================================
// Input System
// ============================================================================
// Input event types
type (
InputEvent = input.InputEvent
KeyboardEvent = input.KeyboardEvent
MouseEvent = input.MouseEvent
TouchEvent = input.TouchEvent
EventDispatcher = input.EventDispatcher
MultiTouchRecognizer = input.MultiTouchRecognizer
)
// Input functions
var (
NewEventDispatcher = input.NewEventDispatcher
NewKeyboardState = input.NewKeyboardState
NewMouseState = input.NewMouseState
NewMultiTouchRecognizer = input.NewMultiTouchRecognizer
)
// ============================================================================
// Hot Reload (Development)
// ============================================================================
// HotReloader manages hot reload during development.
type HotReloader = hotreload.HotReloader
// StateStore preserves state across hot reloads.
type StateStore = hotreload.StateStore
// Hot reload functions
var (
NewHotReloader = hotreload.NewHotReloader
NewStateStore = hotreload.NewStateStore
)
// ============================================================================
// Testing
// ============================================================================
// Testing types
type (
WidgetTester = testing.WidgetTester
GoldenTester = testing.GoldenTester
IntegrationTester = testing.IntegrationTester
GestureSimulator = testing.GestureSimulator
)
// Testing functions
var (
NewWidgetTester = testing.NewWidgetTester
NewGoldenTester = testing.NewGoldenTester
NewIntegrationTester = testing.NewIntegrationTester
)