ids and classes
This commit is contained in:
+2
-2
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/orus-dev/osui/isKey"
|
||||
)
|
||||
|
||||
type BtnParams struct {
|
||||
type ButtonParams struct {
|
||||
Style ButtonStyle
|
||||
Toggle bool
|
||||
OnClick func(*ButtonComponent) bool
|
||||
@@ -92,7 +92,7 @@ func (b *ButtonComponent) GetComponentData() *osui.ComponentData {
|
||||
return &b.Data
|
||||
}
|
||||
|
||||
func (b *ButtonComponent) Params(param BtnParams) *ButtonComponent {
|
||||
func (b *ButtonComponent) Params(param ButtonParams) *ButtonComponent {
|
||||
b.Style = osui.SetDefaults(¶m.Style).(*ButtonStyle)
|
||||
if param.OnClick != nil {
|
||||
b.on_click = param.OnClick
|
||||
|
||||
@@ -81,6 +81,7 @@ func (m *MenuComponent) Update(key string) bool {
|
||||
|
||||
func (b *MenuComponent) Params(param MenuParams) *MenuComponent {
|
||||
b.Style = osui.SetDefaults(¶m.Style).(*MenuStyle)
|
||||
b.OnSelected = param.OnSelected
|
||||
return b
|
||||
}
|
||||
|
||||
|
||||
+32
@@ -81,3 +81,35 @@ func findClosestComponent(a []osui.Component, i int, d string) int {
|
||||
|
||||
return closestIndex
|
||||
}
|
||||
|
||||
type Id[T osui.Component] struct {
|
||||
changer func(T) T
|
||||
Component T
|
||||
}
|
||||
|
||||
func (i *Id[T]) Id(c T) T {
|
||||
i.Component = c
|
||||
if i.changer != nil {
|
||||
return i.changer(i.Component)
|
||||
}
|
||||
return i.Component
|
||||
}
|
||||
|
||||
func (i *Id[T]) SetProperties(c func(T) T) {
|
||||
i.changer = c
|
||||
}
|
||||
|
||||
type Class[T osui.Component] struct {
|
||||
changer func(T) T
|
||||
}
|
||||
|
||||
func (c *Class[T]) Class(co T) T {
|
||||
if c.changer != nil {
|
||||
return c.changer(co)
|
||||
}
|
||||
return co
|
||||
}
|
||||
|
||||
func (c *Class[T]) SetProperties(ch func(T) T) {
|
||||
c.changer = ch
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user