Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lesleysin committed Dec 23, 2024
1 parent cf8fc90 commit 79d2169
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 59 deletions.
40 changes: 20 additions & 20 deletions pkg/duit_attributes/gesture_detector_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ import (
"github.com/Duit-Foundation/duit_go/v3/pkg/duit_core"
)

type GestureDetectorAttributes struct {
type GestureDetectorAttributes[TAction duit_core.Action] struct {
ValueReferenceHolder
OnTap *duit_core.Action `json:"onTap,omitempty"`
OnTapDown *duit_core.Action `json:"onTapDown,omitempty"`
OnTapUp *duit_core.Action `json:"onTapUp,omitempty"`
OnTapCancel *duit_core.Action `json:"onTapCancel,omitempty"`
OnDoubleTap *duit_core.Action `json:"onDoubleTap,omitempty"`
OnDoubleTapDown *duit_core.Action `json:"onDoubleTapDown,omitempty"`
OnDoubleTapCancel *duit_core.Action `json:"onDoubleTapCancel,omitempty"`
OnLongPressDown *duit_core.Action `json:"onLongPressDown,omitempty"`
OnLongPressCancel *duit_core.Action `json:"onLongPressCancel,omitempty"`
OnLongPress *duit_core.Action `json:"onLongPress,omitempty"`
OnLongPressStart *duit_core.Action `json:"onLongPressStart,omitempty"`
OnLongPressMoveUpdate *duit_core.Action `json:"onLongPressMoveUpdate,omitempty"`
OnLongPressUp *duit_core.Action `json:"onLongPressUp,omitempty"`
OnLongPressEnd *duit_core.Action `json:"onLongPressEnd,omitempty"`
OnPanStart *duit_core.Action `json:"onPanStart,omitempty"`
OnPanDown *duit_core.Action `json:"onPanDown,omitempty"`
OnPanUpdate *duit_core.Action `json:"onPanUpdate,omitempty"`
OnPanEnd *duit_core.Action `json:"onPanEnd,omitempty"`
OnPanCancel *duit_core.Action `json:"onPanCancel,omitempty"`
OnTap *TAction `json:"onTap,omitempty"`
OnTapDown *TAction `json:"onTapDown,omitempty"`
OnTapUp *TAction `json:"onTapUp,omitempty"`
OnTapCancel *TAction `json:"onTapCancel,omitempty"`
OnDoubleTap *TAction `json:"onDoubleTap,omitempty"`
OnDoubleTapDown *TAction `json:"onDoubleTapDown,omitempty"`
OnDoubleTapCancel *TAction `json:"onDoubleTapCancel,omitempty"`
OnLongPressDown *TAction `json:"onLongPressDown,omitempty"`
OnLongPressCancel *TAction `json:"onLongPressCancel,omitempty"`
OnLongPress *TAction `json:"onLongPress,omitempty"`
OnLongPressStart *TAction `json:"onLongPressStart,omitempty"`
OnLongPressMoveUpdate *TAction `json:"onLongPressMoveUpdate,omitempty"`
OnLongPressUp *TAction `json:"onLongPressUp,omitempty"`
OnLongPressEnd *TAction `json:"onLongPressEnd,omitempty"`
OnPanStart *TAction `json:"onPanStart,omitempty"`
OnPanDown *TAction `json:"onPanDown,omitempty"`
OnPanUpdate *TAction `json:"onPanUpdate,omitempty"`
OnPanEnd *TAction `json:"onPanEnd,omitempty"`
OnPanCancel *TAction `json:"onPanCancel,omitempty"`
ExcludeFromSemantics bool `json:"excludeFromSemantics,omitempty"`
DragStarnBehavior duit_gestures.DragStartBehavior `json:"dragStartBehavior,omitempty"`
Behavior duit_gestures.HitTestBehavior `json:"behavior,omitempty"`
Expand Down
14 changes: 7 additions & 7 deletions pkg/duit_attributes/lifecycle_event_listener_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package duit_attributes

import "github.com/Duit-Foundation/duit_go/v3/pkg/duit_core"

type LifecycleEventListenerAttributes struct {
type LifecycleEventListenerAttributes[TAction duit_core.Action] struct {
ValueReferenceHolder
OnStateChanged *duit_core.Action `json:"onStateChanged,omitempty"`
OnResumed *duit_core.Action `json:"onResumed,omitempty"`
OnInactive *duit_core.Action `json:"onInactive,omitempty"`
OnPaused *duit_core.Action `json:"onPaused,omitempty"`
OnDetached *duit_core.Action `json:"onDetached,omitempty"`
OnHidden *duit_core.Action `json:"onHidden,omitempty"`
OnStateChanged *TAction `json:"onStateChanged,omitempty"`
OnResumed *TAction `json:"onResumed,omitempty"`
OnInactive *TAction `json:"onInactive,omitempty"`
OnPaused *TAction `json:"onPaused,omitempty"`
OnDetached *TAction `json:"onDetached,omitempty"`
OnHidden *TAction `json:"onHidden,omitempty"`
}
8 changes: 4 additions & 4 deletions pkg/duit_attributes/slider_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import (
"github.com/Duit-Foundation/duit_go/v3/pkg/duit_core"
)

type SliderAttributes[TColor duit_color.Color] struct {
type SliderAttributes[TAction duit_core.Action, TColor duit_color.Color] struct {
ValueReferenceHolder
Value float32 `json:"value"`
Min float32 `json:"min,omitempty"`
Max float32 `json:"max,omitempty"`
Divisions uint32 `json:"divisions,omitempty"`
SecondaryTrackValue float32 `json:"secondaryTrackValue,omitempty"`
OnChanged *duit_core.Action `json:"onChanged,omitempty"`
OnChangeStart *duit_core.Action `json:"onChangeStart,omitempty"`
OnChangeEnd *duit_core.Action `json:"onChangeEnd,omitempty"`
OnChanged *TAction `json:"onChanged,omitempty"`
OnChangeStart *TAction `json:"onChangeStart,omitempty"`
OnChangeEnd *TAction `json:"onChangeEnd,omitempty"`
ActiveColor TColor `json:"activeColor,omitempty"`
InactiveColor TColor `json:"inactiveColor,omitempty"`
ThumbColor TColor `json:"thumbColor,omitempty"`
Expand Down
20 changes: 17 additions & 3 deletions pkg/duit_core/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,25 @@ type ScriptData struct {
// DependsOn is a string slice field that represents the dependencies of the action.
//
// Meta is an interface{} field that represents optional additional metadata for the action.
type Action struct {
type Action interface {
RemoteAction | LocalAction | ScriptActionS
}

type RemoteAction struct {
ExecutionType uint8 `json:"executionType"`
Event string `json:"event"`
DependsOn []*ActionDependency `json:"dependsOn"`
Meta interface{} `json:"meta,omitempty"`
Payload *Event `json:"payload,omitempty"`
Meta any `json:"meta,omitempty"`
}

type LocalAction struct {
ExecutionType uint8 `json:"executionType"`
Payload any `json:"payload,omitempty"`
}

type ScriptActionS struct {
ExecutionType uint8 `json:"executionType"`
Script *ScriptData `json:"script,omitempty"`
Event string `json:"event"`
DependsOn []*ActionDependency `json:"dependsOn"`
}
18 changes: 8 additions & 10 deletions pkg/duit_core/action_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ type HttpActionMetainfo struct {
// - metainfo: a pointer to an instance of HttpActionMetainfo representing the meta information of the action.
//
// The function returns a pointer to an instance of Action.
func HttpAction(event string, dependsOn []*ActionDependency, metainfo *HttpActionMetainfo) *Action {
return &Action{
func HttpAction(event string, dependsOn []*ActionDependency, metainfo *HttpActionMetainfo) *RemoteAction {
return &RemoteAction{
ExecutionType: Transport,
Event: event,
DependsOn: dependsOn,
Expand All @@ -26,25 +26,23 @@ func HttpAction(event string, dependsOn []*ActionDependency, metainfo *HttpActio
//
// It takes in an event string and dependsOn slice of strings as parameters.
// It returns a pointer to an Action struct.
func WebSocketAction(event string, dependsOn []*ActionDependency) *Action {
return &Action{
func WebSocketAction(event string, dependsOn []*ActionDependency) *RemoteAction {
return &RemoteAction{
ExecutionType: Transport,
Event: event,
DependsOn: dependsOn,
}
}

func LocalExecutedtAction(payload *Event) *Action {
return &Action{
func LocalExecutedtAction(payload any) *LocalAction {
return &LocalAction{
ExecutionType: Local,
Event: "local_event",
DependsOn: []*ActionDependency{},
Payload: payload,
}
}

func ScriptAction(event string, dependsOn []*ActionDependency, script *ScriptData) *Action {
return &Action{
func ScriptAction(event string, dependsOn []*ActionDependency, script *ScriptData) *ScriptActionS {
return &ScriptActionS{
ExecutionType: Script,
Event: event,
DependsOn: dependsOn,
Expand Down
6 changes: 3 additions & 3 deletions pkg/duit_core/element.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package duit_core
import "github.com/google/uuid"

type DuitWidget interface {
CreateElement(elemType string, elemId string, tag string, attributes interface{}, action *Action, controlled bool, mayHaveChildElements uint8) *DuitElementModel
CreateElement(elemType string, elemId string, tag string, attributes interface{}, action any, controlled bool, mayHaveChildElements uint8) *DuitElementModel
}

type DuitElementModel struct {
Expand All @@ -12,7 +12,7 @@ type DuitElementModel struct {
Id string `json:"id"`
Controlled bool `json:"controlled"`
Attributes interface{} `json:"attributes"`
Action *Action `json:"action,omitempty"`
Action any `json:"action,omitempty"`

//Special component tag.
//
Expand Down Expand Up @@ -51,7 +51,7 @@ type DuitViewChild interface {
// - controlled: a boolean indicating whether the element is controlled
//
// It returns a pointer to the upgraded created DuitElement.
func (element *DuitElementModel) CreateElement(elemType DuitElementType, elemId string, tag string, attributes interface{}, action *Action, controlled bool, mayHaveChildElements uint8, data interface{}, subviews ...*DuitElementModel) *DuitElementModel {
func (element *DuitElementModel) CreateElement(elemType DuitElementType, elemId string, tag string, attributes interface{}, action any, controlled bool, mayHaveChildElements uint8, data interface{}, subviews ...*DuitElementModel) *DuitElementModel {
var id string

if elemId == "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/duit_widget/checkbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import (
"github.com/Duit-Foundation/duit_go/v3/pkg/duit_core"
)

func CheckBox[T duit_color.Color](attributes *duit_attributes.CheckboxAttributes[T], id string, action *duit_core.Action) *duit_core.DuitElementModel {
func CheckBox[TAction duit_core.Action, TColor duit_color.Color](attributes *duit_attributes.CheckboxAttributes[TColor], id string, action *TAction) *duit_core.DuitElementModel {
return new(duit_core.DuitElementModel).CreateElement(duit_core.CheckBox, id, "", attributes, action, true, 0, nil)
}
2 changes: 1 addition & 1 deletion pkg/duit_widget/elevated_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import (
"github.com/Duit-Foundation/duit_go/v3/pkg/duit_core"
)

func ElevatedButton(attributes *duit_attributes.ElevatedButtonAttributes, id string, action *duit_core.Action, child *duit_core.DuitElementModel) *duit_core.DuitElementModel {
func ElevatedButton[TAction duit_core.Action](attributes *duit_attributes.ElevatedButtonAttributes, id string, action *TAction, child *duit_core.DuitElementModel) *duit_core.DuitElementModel {
return new(duit_core.DuitElementModel).CreateElement(duit_core.ElevatedButton, id, "", attributes, action, true, 1, nil, child)
}
3 changes: 1 addition & 2 deletions pkg/duit_widget/gesture_detector.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package duit_widget

import (
"github.com/Duit-Foundation/duit_go/v3/pkg/duit_attributes"
"github.com/Duit-Foundation/duit_go/v3/pkg/duit_core"
)

func GestureDetector(attributes *duit_attributes.GestureDetectorAttributes, id string, child *duit_core.DuitElementModel) *duit_core.DuitElementModel {
func GestureDetector[TAction duit_core.Action](attributes *TAction, id string, child *duit_core.DuitElementModel) *duit_core.DuitElementModel {
return new(duit_core.DuitElementModel).CreateElement(duit_core.GestureDetector, id, "", attributes, nil, true, 1, nil, child)
}
2 changes: 1 addition & 1 deletion pkg/duit_widget/lifecycle_event_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import (
"github.com/Duit-Foundation/duit_go/v3/pkg/duit_core"
)

func LifecycleEvent(attributes *duit_attributes.LifecycleEventListenerAttributes, id string, child *duit_core.DuitElementModel) *duit_core.DuitElementModel {
func LifecycleEvent[TAction duit_core.Action](attributes *duit_attributes.LifecycleEventListenerAttributes[TAction], id string, child *duit_core.DuitElementModel) *duit_core.DuitElementModel {
return new(duit_core.DuitElementModel).CreateElement(duit_core.LifecycleEventListener, id, "", attributes, nil, true, 1, nil, child)
}
2 changes: 1 addition & 1 deletion pkg/duit_widget/list_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import (
"github.com/Duit-Foundation/duit_go/v3/pkg/duit_core"
)

func ListView[TInsets duit_edge_insets.EdgeInsets, U duit_attributes.ListViewAttributes[TInsets]](attributes *U, id string, controlled bool, action *duit_core.Action, children []*duit_core.DuitElementModel) *duit_core.DuitElementModel {
func ListView[TAction duit_core.Action, TInsets duit_edge_insets.EdgeInsets, U duit_attributes.ListViewAttributes[TInsets]](attributes *U, id string, controlled bool, action *TAction, children []*duit_core.DuitElementModel) *duit_core.DuitElementModel {
return new(duit_core.DuitElementModel).CreateElement(duit_core.ListView, id, "", attributes, action, controlled, 2, nil, children...)
}
2 changes: 1 addition & 1 deletion pkg/duit_widget/radio.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/Duit-Foundation/duit_go/v3/pkg/duit_core"
)

func RadioGroupContext[TValue duit_attributes.PrimitiveValue](attributes *duit_attributes.RadioGroupContextAttributes[TValue], id string, action *duit_core.Action, child *duit_core.DuitElementModel) *duit_core.DuitElementModel {
func RadioGroupContext[TAction duit_core.Action, TValue duit_attributes.PrimitiveValue](attributes *duit_attributes.RadioGroupContextAttributes[TValue], id string, action *TAction, child *duit_core.DuitElementModel) *duit_core.DuitElementModel {
return new(duit_core.DuitElementModel).CreateElement(duit_core.RadioGroupContext, id, "", attributes, action, true, 1, nil, child)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/duit_widget/slider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import (
"github.com/Duit-Foundation/duit_go/v3/pkg/duit_core"
)

func Slider[T duit_color.Color](attributes *duit_attributes.SliderAttributes[T], id string) *duit_core.DuitElementModel {
func Slider[TAction duit_core.Action, TColor duit_color.Color](attributes *duit_attributes.SliderAttributes[TAction, TColor], id string) *duit_core.DuitElementModel {
return new(duit_core.DuitElementModel).CreateElement(duit_core.Slider, id, "", attributes, nil, true, 0, nil)
}
2 changes: 1 addition & 1 deletion pkg/duit_widget/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import (
"github.com/Duit-Foundation/duit_go/v3/pkg/duit_core"
)

func Switch[T duit_color.Color](attributes *duit_attributes.SwitchAttributes[T], id string, action *duit_core.Action) *duit_core.DuitElementModel {
func Switch[TAction duit_core.Action, TColor duit_color.Color](attributes *duit_attributes.SwitchAttributes[TColor], id string, action *TAction) *duit_core.DuitElementModel {
return new(duit_core.DuitElementModel).CreateElement(duit_core.Switch, id, "", attributes, action, true, 0, nil)
}
2 changes: 1 addition & 1 deletion pkg/duit_widget/text_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import (
"github.com/Duit-Foundation/duit_go/v3/pkg/duit_core"
)

func TextField[TInsets duit_edge_insets.EdgeInsets, TColor duit_color.Color](attributes *duit_attributes.TextFieldAttributes[TInsets, TColor], id string, action *duit_core.Action) *duit_core.DuitElementModel {
func TextField[TAction duit_core.Action, TInsets duit_edge_insets.EdgeInsets, TColor duit_color.Color](attributes *duit_attributes.TextFieldAttributes[TInsets, TColor], id string, action *TAction) *duit_core.DuitElementModel {
return new(duit_core.DuitElementModel).CreateElement(duit_core.TextField, id, "", attributes, action, true, 0, nil)
}
4 changes: 2 additions & 2 deletions pkg/duit_widget/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import (
"github.com/Duit-Foundation/duit_go/v3/pkg/duit_core"
)

func Wrap(attributes *duit_attributes.WrapAttributes, id string, controlled bool, action *duit_core.Action, child *duit_core.DuitElementModel) *duit_core.DuitElementModel {
return new(duit_core.DuitElementModel).CreateElement(duit_core.Wrap, id, "", attributes, action, controlled, 2, nil, child)
func Wrap(attributes *duit_attributes.WrapAttributes, id string, controlled bool, child *duit_core.DuitElementModel) *duit_core.DuitElementModel {
return new(duit_core.DuitElementModel).CreateElement(duit_core.Wrap, id, "", attributes, nil, controlled, 2, nil, child)
}

0 comments on commit 79d2169

Please sign in to comment.