mirror of https://github.com/rivo/tview.git
Added a style function for form element colours.
This commit is contained in:
parent
3e06d118c3
commit
65faf5cfc7
26
form.go
26
form.go
|
@ -84,11 +84,8 @@ type Form struct {
|
||||||
// The label color.
|
// The label color.
|
||||||
labelColor tcell.Color
|
labelColor tcell.Color
|
||||||
|
|
||||||
// The background color of the input area.
|
// The style of the input area.
|
||||||
fieldBackgroundColor tcell.Color
|
fieldStyle tcell.Style
|
||||||
|
|
||||||
// The text color of the input area.
|
|
||||||
fieldTextColor tcell.Color
|
|
||||||
|
|
||||||
// The style of the buttons when they are not focused.
|
// The style of the buttons when they are not focused.
|
||||||
buttonStyle tcell.Style
|
buttonStyle tcell.Style
|
||||||
|
@ -115,8 +112,7 @@ func NewForm() *Form {
|
||||||
Box: box,
|
Box: box,
|
||||||
itemPadding: 1,
|
itemPadding: 1,
|
||||||
labelColor: Styles.SecondaryTextColor,
|
labelColor: Styles.SecondaryTextColor,
|
||||||
fieldBackgroundColor: Styles.ContrastBackgroundColor,
|
fieldStyle: tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.PrimaryTextColor),
|
||||||
fieldTextColor: Styles.PrimaryTextColor,
|
|
||||||
buttonStyle: tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.PrimaryTextColor),
|
buttonStyle: tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.PrimaryTextColor),
|
||||||
buttonActivatedStyle: tcell.StyleDefault.Background(Styles.PrimaryTextColor).Foreground(Styles.ContrastBackgroundColor),
|
buttonActivatedStyle: tcell.StyleDefault.Background(Styles.PrimaryTextColor).Foreground(Styles.ContrastBackgroundColor),
|
||||||
buttonDisabledStyle: tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.ContrastSecondaryTextColor),
|
buttonDisabledStyle: tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.ContrastSecondaryTextColor),
|
||||||
|
@ -151,13 +147,20 @@ func (f *Form) SetLabelColor(color tcell.Color) *Form {
|
||||||
|
|
||||||
// SetFieldBackgroundColor sets the background color of the input areas.
|
// SetFieldBackgroundColor sets the background color of the input areas.
|
||||||
func (f *Form) SetFieldBackgroundColor(color tcell.Color) *Form {
|
func (f *Form) SetFieldBackgroundColor(color tcell.Color) *Form {
|
||||||
f.fieldBackgroundColor = color
|
f.fieldStyle = f.fieldStyle.Background(color)
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetFieldTextColor sets the text color of the input areas.
|
// SetFieldTextColor sets the text color of the input areas.
|
||||||
func (f *Form) SetFieldTextColor(color tcell.Color) *Form {
|
func (f *Form) SetFieldTextColor(color tcell.Color) *Form {
|
||||||
f.fieldTextColor = color
|
f.fieldStyle = f.fieldStyle.Foreground(color)
|
||||||
|
return f
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetFieldStyle sets the style of the input areas. Attributes are currently
|
||||||
|
// still ignored to maintain backwards compatibility.
|
||||||
|
func (f *Form) SetFieldStyle(style tcell.Style) *Form {
|
||||||
|
f.fieldStyle = style
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -570,12 +573,13 @@ func (f *Form) Draw(screen tcell.Screen) {
|
||||||
if x+itemWidth >= rightLimit {
|
if x+itemWidth >= rightLimit {
|
||||||
itemWidth = rightLimit - x
|
itemWidth = rightLimit - x
|
||||||
}
|
}
|
||||||
|
fieldTextColor, fieldBackgroundColor, _ := f.fieldStyle.Decompose()
|
||||||
item.SetFormAttributes(
|
item.SetFormAttributes(
|
||||||
labelWidth,
|
labelWidth,
|
||||||
f.labelColor,
|
f.labelColor,
|
||||||
f.backgroundColor,
|
f.backgroundColor,
|
||||||
f.fieldTextColor,
|
fieldTextColor,
|
||||||
f.fieldBackgroundColor,
|
fieldBackgroundColor,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Save position.
|
// Save position.
|
||||||
|
|
Loading…
Reference in New Issue