buttons and styles

This commit is contained in:
2024-09-28 17:12:45 +02:00
parent 5a94fc34ad
commit 90f106f127
10 changed files with 218 additions and 80 deletions
+46
View File
@@ -0,0 +1,46 @@
package ui
import (
"fmt"
"strings"
"github.com/orus-dev/osui"
)
func centerText(text string, width int) string {
if len(text) > width {
return text[:width]
}
padding := (width - len(text)) / 2
leftPadding := strings.Repeat(" ", padding)
rightPadding := strings.Repeat(" ", padding)
return fmt.Sprintf("%s%s%s", leftPadding, text, rightPadding)
}
func WithPosition(x, y int, c osui.Component) osui.Component {
data := c.GetComponentData()
data.X = x
data.Y = y
return c
}
func WithStyle(style interface{}, c osui.Component) osui.Component {
c.SetStyle(style)
return c
}
func WithSize(width, height int, c osui.Component) osui.Component {
data := c.GetComponentData()
data.Width = width
data.Height = height
return c
}
func fnLogicValue(f func(*ButtonComponent) bool) func(*ButtonComponent) bool {
if f == nil {
return func(*ButtonComponent) bool { return false }
} else {
return f
}
}