buttons and styles
This commit is contained in:
+46
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user