ids and classes

This commit is contained in:
2024-09-30 14:10:00 +02:00
parent bf70ceacf1
commit 705bd8d61b
5 changed files with 85 additions and 44 deletions
+2 -2
View File
@@ -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(&param.Style).(*ButtonStyle)
if param.OnClick != nil {
b.on_click = param.OnClick
+1
View File
@@ -81,6 +81,7 @@ func (m *MenuComponent) Update(key string) bool {
func (b *MenuComponent) Params(param MenuParams) *MenuComponent {
b.Style = osui.SetDefaults(&param.Style).(*MenuStyle)
b.OnSelected = param.OnSelected
return b
}
+32
View File
@@ -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
}