styling
This commit is contained in:
+18
-7
@@ -5,10 +5,19 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/orus-dev/osui"
|
||||
"github.com/orus-dev/osui/colors"
|
||||
)
|
||||
|
||||
type InputBoxStyle struct {
|
||||
Background string `defaults:"" type:"bg"`
|
||||
Foreground string `defaults:"" type:"fg"`
|
||||
Outline string `defaults:"" type:"fg"`
|
||||
Cursor string `defaults:"" type:"fg"`
|
||||
}
|
||||
|
||||
type InputBoxComponent struct {
|
||||
Data osui.ComponentData
|
||||
Style *InputBoxStyle
|
||||
max_size uint
|
||||
InputData string
|
||||
}
|
||||
@@ -18,13 +27,16 @@ func (s *InputBoxComponent) GetComponentData() *osui.ComponentData {
|
||||
}
|
||||
|
||||
func (s InputBoxComponent) Render() string {
|
||||
osui.UseStyle(s.Style)
|
||||
if s.max_size > uint(len(s.InputData)) {
|
||||
return fmt.Sprintf(
|
||||
" %s\n|%s%s|\n %s",
|
||||
strings.Repeat("_", int(s.max_size)),
|
||||
s.InputData+osui.LogicValue(s.Data.IsActive, "█", ""),
|
||||
strings.Repeat(" ", int(s.max_size)-len(s.InputData)-osui.LogicValueInt(s.Data.IsActive, 1, 0)),
|
||||
strings.Repeat("‾", int(s.max_size)),
|
||||
" %s\n%s|%s%s|%s\n %s",
|
||||
colors.Reset+s.Style.Outline+strings.Repeat("_", int(s.max_size))+colors.Reset,
|
||||
colors.Reset+s.Style.Outline,
|
||||
colors.Combine(s.Style.Foreground, s.Style.Background)+s.InputData+osui.LogicValue(s.Data.IsActive, s.Style.Cursor+"█"+colors.Combine(s.Style.Foreground, s.Style.Background), ""),
|
||||
strings.Repeat(" ", int(s.max_size)-len(s.InputData)-osui.LogicValueInt(s.Data.IsActive, 1, 0))+colors.Reset+s.Style.Outline,
|
||||
colors.Reset+s.Data.DefaultColor,
|
||||
s.Style.Outline+strings.Repeat("‾", int(s.max_size))+colors.Reset+s.Data.DefaultColor,
|
||||
)
|
||||
}
|
||||
return fmt.Sprintf(
|
||||
@@ -53,7 +65,6 @@ func (s *InputBoxComponent) Read() error {
|
||||
|
||||
func (s *InputBoxComponent) Update(key string) bool {
|
||||
switch key {
|
||||
case "":
|
||||
case osui.Key.Enter:
|
||||
return true
|
||||
case osui.Key.Backspace:
|
||||
@@ -72,5 +83,5 @@ func (s *InputBoxComponent) Update(key string) bool {
|
||||
}
|
||||
|
||||
func InputBox(max_size uint) *InputBoxComponent {
|
||||
return &InputBoxComponent{max_size: max_size}
|
||||
return &InputBoxComponent{max_size: max_size, Style: osui.SetDefaults(&InputBoxStyle{}).(*InputBoxStyle)}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user