Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions button.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewButton(label string) *Button {
Box: box,
text: label,
style: tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.PrimaryTextColor),
activatedStyle: tcell.StyleDefault.Background(Styles.PrimaryTextColor).Foreground(Styles.InverseTextColor),
activatedStyle: tcell.StyleDefault.Foreground(Styles.PrimaryTextColor).Background(Styles.InverseTextColor).Reverse(true),
disabledStyle: tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.ContrastSecondaryTextColor),
}
b.Box.Primitive = b
Expand Down Expand Up @@ -75,14 +75,24 @@ func (b *Button) SetStyle(style tcell.Style) *Button {
// SetLabelColorActivated sets the color of the button text when the button is
// in focus.
func (b *Button) SetLabelColorActivated(color tcell.Color) *Button {
b.activatedStyle = b.activatedStyle.Foreground(color)
_, _, attrs := b.activatedStyle.Decompose()
if attrs&tcell.AttrReverse != 0 {
b.activatedStyle = b.activatedStyle.Background(color)
} else {
b.activatedStyle = b.activatedStyle.Foreground(color)
}
return b
}

// SetBackgroundColorActivated sets the background color of the button text when
// the button is in focus.
func (b *Button) SetBackgroundColorActivated(color tcell.Color) *Button {
b.activatedStyle = b.activatedStyle.Background(color)
_, _, attrs := b.activatedStyle.Decompose()
if attrs&tcell.AttrReverse != 0 {
b.activatedStyle = b.activatedStyle.Foreground(color)
} else {
b.activatedStyle = b.activatedStyle.Background(color)
}
return b
}

Expand Down
16 changes: 13 additions & 3 deletions checkbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewCheckbox() *Checkbox {
labelStyle: tcell.StyleDefault.Foreground(Styles.SecondaryTextColor),
uncheckedStyle: tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.PrimaryTextColor),
checkedStyle: tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.PrimaryTextColor),
focusStyle: tcell.StyleDefault.Background(Styles.PrimaryTextColor).Foreground(Styles.ContrastBackgroundColor),
focusStyle: tcell.StyleDefault.Foreground(Styles.PrimaryTextColor).Background(Styles.ContrastBackgroundColor).Reverse(true),
uncheckedString: " ",
checkedString: "X",
}
Expand Down Expand Up @@ -122,15 +122,25 @@ func (c *Checkbox) SetLabelStyle(style tcell.Style) *Checkbox {
func (c *Checkbox) SetFieldBackgroundColor(color tcell.Color) *Checkbox {
c.uncheckedStyle = c.uncheckedStyle.Background(color)
c.checkedStyle = c.checkedStyle.Background(color)
c.focusStyle = c.focusStyle.Foreground(color)
_, _, attrs := c.focusStyle.Decompose()
if attrs&tcell.AttrReverse != 0 {
c.focusStyle = c.focusStyle.Background(color)
} else {
c.focusStyle = c.focusStyle.Foreground(color)
}
return c
}

// SetFieldTextColor sets the text color of the input area.
func (c *Checkbox) SetFieldTextColor(color tcell.Color) *Checkbox {
c.uncheckedStyle = c.uncheckedStyle.Foreground(color)
c.checkedStyle = c.checkedStyle.Foreground(color)
c.focusStyle = c.focusStyle.Background(color)
_, _, attrs := c.focusStyle.Decompose()
if attrs&tcell.AttrReverse != 0 {
c.focusStyle = c.focusStyle.Foreground(color)
} else {
c.focusStyle = c.focusStyle.Background(color)
}
return c
}

Expand Down
6 changes: 3 additions & 3 deletions dropdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func NewDropDown() *DropDown {
list := NewList()
list.ShowSecondaryText(false).
SetMainTextStyle(tcell.StyleDefault.Background(Styles.MoreContrastBackgroundColor).Foreground(Styles.PrimitiveBackgroundColor)).
SetSelectedStyle(tcell.StyleDefault.Background(Styles.PrimaryTextColor).Foreground(Styles.PrimitiveBackgroundColor)).
SetSelectedStyle(tcell.StyleDefault.Foreground(Styles.PrimaryTextColor).Background(Styles.PrimitiveBackgroundColor).Reverse(true)).
SetHighlightFullLine(true).
SetBackgroundColor(Styles.MoreContrastBackgroundColor)

Expand All @@ -111,9 +111,9 @@ func NewDropDown() *DropDown {
prefix: prefix,
labelStyle: tcell.StyleDefault.Foreground(Styles.SecondaryTextColor),
fieldStyle: tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.PrimaryTextColor),
focusedStyle: tcell.StyleDefault.Background(Styles.PrimaryTextColor).Foreground(Styles.ContrastBackgroundColor),
focusedStyle: tcell.StyleDefault.Foreground(Styles.PrimaryTextColor).Background(Styles.ContrastBackgroundColor).Reverse(true),
disabledStyle: tcell.StyleDefault.Background(box.backgroundColor).Foreground(Styles.SecondaryTextColor),
prefixStyle: tcell.StyleDefault.Background(Styles.PrimaryTextColor).Foreground(Styles.ContrastBackgroundColor),
prefixStyle: tcell.StyleDefault.Foreground(Styles.PrimaryTextColor).Background(Styles.ContrastBackgroundColor).Reverse(true),
}

d.Box.Primitive = d
Expand Down
16 changes: 13 additions & 3 deletions form.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func NewForm() *Form {
labelColor: Styles.SecondaryTextColor,
fieldStyle: 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.Foreground(Styles.PrimaryTextColor).Background(Styles.ContrastBackgroundColor).Reverse(true),
buttonDisabledStyle: tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.ContrastSecondaryTextColor),
requestedFocus: -1,
setFocus: func(Primitive) {},
Expand Down Expand Up @@ -186,15 +186,25 @@ func (f *Form) SetButtonsAlign(align int) *Form {
// also the text color of the buttons when they are focused.
func (f *Form) SetButtonBackgroundColor(color tcell.Color) *Form {
f.buttonStyle = f.buttonStyle.Background(color)
f.buttonActivatedStyle = f.buttonActivatedStyle.Foreground(color)
_, _, attrs := f.buttonActivatedStyle.Decompose()
if attrs&tcell.AttrReverse != 0 {
f.buttonActivatedStyle = f.buttonActivatedStyle.Background(color)
} else {
f.buttonActivatedStyle = f.buttonActivatedStyle.Foreground(color)
}
return f
}

// SetButtonTextColor sets the color of the button texts. This is also the
// background of the buttons when they are focused.
func (f *Form) SetButtonTextColor(color tcell.Color) *Form {
f.buttonStyle = f.buttonStyle.Foreground(color)
f.buttonActivatedStyle = f.buttonActivatedStyle.Background(color)
_, _, attrs := f.buttonActivatedStyle.Decompose()
if attrs&tcell.AttrReverse != 0 {
f.buttonActivatedStyle = f.buttonActivatedStyle.Foreground(color)
} else {
f.buttonActivatedStyle = f.buttonActivatedStyle.Background(color)
}
return f
}

Expand Down
2 changes: 1 addition & 1 deletion inputfield.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func NewInputField() *InputField {
i.textArea.textStyle = tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.PrimaryTextColor)
i.textArea.placeholderStyle = tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.ContrastSecondaryTextColor)
i.autocompleteStyles.main = tcell.StyleDefault.Background(Styles.MoreContrastBackgroundColor).Foreground(Styles.PrimitiveBackgroundColor)
i.autocompleteStyles.selected = tcell.StyleDefault.Background(Styles.PrimaryTextColor).Foreground(Styles.PrimitiveBackgroundColor)
i.autocompleteStyles.selected = tcell.StyleDefault.Foreground(Styles.PrimaryTextColor).Background(Styles.PrimitiveBackgroundColor).Reverse(true)
i.autocompleteStyles.background = Styles.MoreContrastBackgroundColor
i.autocompleteStyles.useTags = true
i.Box.Primitive = i
Expand Down
16 changes: 13 additions & 3 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func NewList() *List {
mainTextStyle: tcell.StyleDefault.Foreground(Styles.PrimaryTextColor).Background(Styles.PrimitiveBackgroundColor),
secondaryTextStyle: tcell.StyleDefault.Foreground(Styles.TertiaryTextColor).Background(Styles.PrimitiveBackgroundColor),
shortcutStyle: tcell.StyleDefault.Foreground(Styles.SecondaryTextColor).Background(Styles.PrimitiveBackgroundColor),
selectedStyle: tcell.StyleDefault.Foreground(Styles.PrimitiveBackgroundColor).Background(Styles.PrimaryTextColor),
selectedStyle: tcell.StyleDefault.Foreground(Styles.PrimaryTextColor).Background(Styles.PrimitiveBackgroundColor).Reverse(true),
mainStyleTags: true,
secondaryStyleTags: true,
}
Expand Down Expand Up @@ -261,13 +261,23 @@ func (l *List) SetShortcutStyle(style tcell.Style) *List {
// color of main text characters that are different from the main text color
// (e.g. style tags) is maintained.
func (l *List) SetSelectedTextColor(color tcell.Color) *List {
l.selectedStyle = l.selectedStyle.Foreground(color)
_, _, attrs := l.selectedStyle.Decompose()
if attrs&tcell.AttrReverse != 0 {
l.selectedStyle = l.selectedStyle.Background(color)
} else {
l.selectedStyle = l.selectedStyle.Foreground(color)
}
return l
}

// SetSelectedBackgroundColor sets the background color of selected items.
func (l *List) SetSelectedBackgroundColor(color tcell.Color) *List {
l.selectedStyle = l.selectedStyle.Background(color)
_, _, attrs := l.selectedStyle.Decompose()
if attrs&tcell.AttrReverse != 0 {
l.selectedStyle = l.selectedStyle.Foreground(color)
} else {
l.selectedStyle = l.selectedStyle.Background(color)
}
return l
}

Expand Down
13 changes: 5 additions & 8 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ type TableCell struct {

// The style of the cell when it is selected. If this is uninitialized
// (tcell.StyleDefault), the table's selected style is used instead. If that
// is uninitialized as well, the cell's background and text color are
// swapped.
// is uninitialized as well, reverse attributes are toggled.
SelectedStyle tcell.Style

// If set to true, the BackgroundColor is not used and the cell will have
Expand Down Expand Up @@ -175,8 +174,7 @@ func (c *TableCell) SetStyle(style tcell.Style) *TableCell {

// SetSelectedStyle sets the cell's style when it is selected. If this is
// uninitialized (tcell.StyleDefault), the table's selected style is used
// instead. If that is uninitialized as well, the cell's background and text
// color are swapped.
// instead. If that is uninitialized as well, reverse attributes are toggled.
func (c *TableCell) SetSelectedStyle(style tcell.Style) *TableCell {
c.SelectedStyle = style
return c
Expand Down Expand Up @@ -585,7 +583,7 @@ func (t *Table) SetBordersColor(color tcell.Color) *Table {
}

// SetSelectedStyle sets a specific style for selected cells. If no such style
// is set, the cell's background and text color are swapped. If a cell defines
// is set, reverse attributes are toggled. If a cell defines
// its own selected style, that will be used instead.
//
// To reset a previous setting to its default, make the following call:
Expand Down Expand Up @@ -1260,15 +1258,14 @@ func (t *Table) Draw(screen tcell.Screen) {
// backgroundTransparent == true => Don't modify background color (when invert == false).
// textTransparent == true => Don't modify text color (when invert == false).
// attr == 0 => Don't change attributes.
// invert == true => Ignore attr, set text to backgroundColor or t.backgroundColor;
// set background to textColor.
// invert == true => Ignore attr and toggle reverse attributes.
colorBackground := func(fromX, fromY, w, h int, backgroundColor, textColor tcell.Color, backgroundTransparent, textTransparent bool, attr tcell.AttrMask, invert bool) {
for by := 0; by < h && fromY+by < y+height; by++ {
for bx := 0; bx < w && fromX+bx < x+width; bx++ {
m, c, style, _ := screen.GetContent(fromX+bx, fromY+by)
fg, bg, a := style.Decompose()
if invert {
style = style.Background(textColor).Foreground(backgroundColor)
style = style.Reverse(a&tcell.AttrReverse == 0)
} else {
if !backgroundTransparent {
bg = backgroundColor
Expand Down
2 changes: 1 addition & 1 deletion textarea.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func NewTextArea() *TextArea {
placeholderStyle: tcell.StyleDefault.Background(Styles.PrimitiveBackgroundColor).Foreground(Styles.TertiaryTextColor),
labelStyle: tcell.StyleDefault.Foreground(Styles.SecondaryTextColor),
textStyle: tcell.StyleDefault.Background(Styles.PrimitiveBackgroundColor).Foreground(Styles.PrimaryTextColor),
selectedStyle: tcell.StyleDefault.Background(Styles.PrimaryTextColor).Foreground(Styles.PrimitiveBackgroundColor),
selectedStyle: tcell.StyleDefault.Foreground(Styles.PrimaryTextColor).Background(Styles.PrimitiveBackgroundColor).Reverse(true),
spans: make([]textAreaSpan, 2, pieceChainMinCap), // We reserve some space to avoid reallocations right when editing starts.
lastAction: taActionOther,
minCursorPrefix: minCursorPrefixDefault,
Expand Down
9 changes: 7 additions & 2 deletions treeview.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func NewTreeNode(text string) *TreeNode {
return &TreeNode{
text: text,
textStyle: tcell.StyleDefault.Foreground(Styles.PrimaryTextColor).Background(Styles.PrimitiveBackgroundColor),
selectedTextStyle: tcell.StyleDefault.Foreground(Styles.PrimitiveBackgroundColor).Background(Styles.PrimaryTextColor),
selectedTextStyle: tcell.StyleDefault.Foreground(Styles.PrimaryTextColor).Background(Styles.PrimitiveBackgroundColor).Reverse(true),
indent: 2,
expanded: true,
selectable: true,
Expand Down Expand Up @@ -219,7 +219,12 @@ func (n *TreeNode) GetColor() tcell.Color {
// styles, use [TreeNode.SetTextStyle] and [TreeNode.SetSelectedTextStyle].
func (n *TreeNode) SetColor(color tcell.Color) *TreeNode {
n.textStyle = n.textStyle.Foreground(color)
n.selectedTextStyle = n.selectedTextStyle.Background(color)
_, _, attrs := n.selectedTextStyle.Decompose()
if attrs&tcell.AttrReverse != 0 {
n.selectedTextStyle = n.selectedTextStyle.Foreground(color)
} else {
n.selectedTextStyle = n.selectedTextStyle.Background(color)
}
return n
}

Expand Down