updated structure
This commit is contained in:
+12
-27
@@ -15,16 +15,8 @@ type InputBoxParams struct {
|
||||
Height int
|
||||
}
|
||||
|
||||
type InputBoxStyle struct {
|
||||
Background string `default:"" type:"bg"`
|
||||
Foreground string `default:"" type:"fg"`
|
||||
Outline string `default:"" type:"fg"`
|
||||
Cursor string `default:"" type:"fg"`
|
||||
}
|
||||
|
||||
type InputBoxComponent struct {
|
||||
Data osui.ComponentData
|
||||
Style *InputBoxStyle
|
||||
max_size uint
|
||||
cursor uint
|
||||
InputData string
|
||||
@@ -35,26 +27,26 @@ func (s *InputBoxComponent) GetComponentData() *osui.ComponentData {
|
||||
}
|
||||
|
||||
func (s InputBoxComponent) Render() string {
|
||||
osui.UseStyle(s.Style)
|
||||
s.Data.Style.UseStyle()
|
||||
if s.max_size > uint(len(s.InputData)) {
|
||||
return fmt.Sprintf(
|
||||
" %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.Style.Outline+strings.Repeat("_", int(s.max_size))+colors.Reset,
|
||||
colors.Reset+s.Data.Style.Outline,
|
||||
colors.Combine(s.Data.Style.Foreground, s.Data.Style.Background)+s.InputData+osui.LogicValue(s.Data.IsActive, s.Data.Style.Cursor+"█"+colors.Combine(s.Data.Style.Foreground, s.Data.Style.Background), ""),
|
||||
strings.Repeat(" ", int(s.max_size)-len(s.InputData)-osui.LogicValueInt(s.Data.IsActive, 1, 0))+colors.Reset+s.Data.Style.Outline,
|
||||
colors.Reset+s.Data.DefaultColor,
|
||||
s.Style.Outline+strings.Repeat("‾", int(s.max_size))+colors.Reset+s.Data.DefaultColor,
|
||||
s.Data.Style.Outline+strings.Repeat("‾", int(s.max_size))+colors.Reset+s.Data.DefaultColor,
|
||||
)
|
||||
}
|
||||
|
||||
return fmt.Sprintf(
|
||||
" %s\n%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.Reset, s.Style.Outline+"|"+colors.Reset),
|
||||
colors.Reset+s.Data.Style.Outline+strings.Repeat("_", int(s.max_size))+colors.Reset,
|
||||
colors.Reset+s.Data.Style.Outline,
|
||||
colors.Combine(s.Data.Style.Foreground, s.Data.Style.Background)+s.InputData+osui.LogicValue(s.Data.IsActive, s.Data.Style.Cursor+"█"+colors.Reset, s.Data.Style.Outline+"|"+colors.Reset),
|
||||
colors.Reset+s.Data.DefaultColor,
|
||||
colors.Reset+s.Style.Outline+strings.Repeat("‾", int(s.max_size))+colors.Reset+s.Data.DefaultColor,
|
||||
colors.Reset+s.Data.Style.Outline+strings.Repeat("‾", int(s.max_size))+colors.Reset+s.Data.DefaultColor,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -83,13 +75,6 @@ func (s *InputBoxComponent) Update(key string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (b *InputBoxComponent) Params(p interface{}) *InputBoxComponent {
|
||||
param := p.(InputBoxParams)
|
||||
b.Style = osui.SetDefaults(¶m.Style).(*InputBoxStyle)
|
||||
b.Data.Width = osui.LogicValueInt(param.Width == 0, 20, param.Width)
|
||||
return b
|
||||
}
|
||||
|
||||
func InputBox(max_size uint) *InputBoxComponent {
|
||||
return &InputBoxComponent{max_size: max_size, Style: osui.SetDefaults(&InputBoxStyle{}).(*InputBoxStyle)}
|
||||
func InputBox(param osui.Param, max_size uint) *InputBoxComponent {
|
||||
return param.UseParam(&InputBoxComponent{max_size: max_size}).(*InputBoxComponent)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user