Browse Source

Added Styles variable with default colors for primitives.

tablepad
Oliver 5 years ago
parent
commit
2874294d89
  1. 2
      README.md
  2. 11
      box.go
  3. 8
      button.go
  4. 6
      checkbox.go
  5. 6
      doc.go
  6. 14
      dropdown.go
  7. 10
      form.go
  8. 6
      inputfield.go
  9. 10
      list.go
  10. 13
      modal.go
  11. 32
      styles.go
  12. 4
      table.go
  13. 2
      textview.go
  14. 2
      util.go

2
README.md

@ -62,5 +62,7 @@ Add your issue here on GitHub. Feel free to get in touch if you have any questio
## Releases
- v0.2 (2018-01-10)
- Added `Styles` variable with default colors for primitives.
- v0.1 (2018-01-06)
- First Release

11
box.go

@ -46,11 +46,12 @@ type Box struct {
// NewBox returns a Box without a border.
func NewBox() *Box {
b := &Box{
width: 15,
height: 10,
borderColor: tcell.ColorWhite,
titleColor: tcell.ColorWhite,
titleAlign: AlignCenter,
width: 15,
height: 10,
backgroundColor: Styles.PrimitiveBackgroundColor,
borderColor: Styles.BorderColor,
titleColor: Styles.TitleColor,
titleAlign: AlignCenter,
}
b.focus = b
return b

8
button.go

@ -32,14 +32,14 @@ type Button struct {
// NewButton returns a new input field.
func NewButton(label string) *Button {
box := NewBox().SetBackgroundColor(tcell.ColorBlue)
box := NewBox().SetBackgroundColor(Styles.ContrastBackgroundColor)
box.SetRect(0, 0, len([]rune(label))+4, 1)
return &Button{
Box: box,
label: label,
labelColor: tcell.ColorWhite,
labelColorActivated: tcell.ColorBlue,
backgroundColorActivated: tcell.ColorWhite,
labelColor: Styles.PrimaryTextColor,
labelColorActivated: Styles.InverseTextColor,
backgroundColorActivated: Styles.PrimaryTextColor,
}
}

6
checkbox.go

@ -40,9 +40,9 @@ type Checkbox struct {
func NewCheckbox() *Checkbox {
return &Checkbox{
Box: NewBox(),
labelColor: tcell.ColorYellow,
fieldBackgroundColor: tcell.ColorBlue,
fieldTextColor: tcell.ColorWhite,
labelColor: Styles.SecondaryTextColor,
fieldBackgroundColor: Styles.ContrastBackgroundColor,
fieldTextColor: Styles.PrimaryTextColor,
}
}

6
doc.go

@ -59,6 +59,12 @@ You will find more demos in the "demos" subdirectory. It also contains a
presentation (written using tview) which gives an overview of the different
widgets and how they can be used.
Styles
When primitives are instantiated, they are initialized with colors taken from
the global Styles variable. You may change this variable to adapt the look and
feel of the primitives to your preferred style.
Type Hierarchy
All widgets listed above contain the Box type. All of Box's functions are

14
dropdown.go

@ -55,18 +55,18 @@ type DropDown struct {
// NewDropDown returns a new drop-down.
func NewDropDown() *DropDown {
list := NewList().ShowSecondaryText(false)
list.SetMainTextColor(tcell.ColorBlack).
SetSelectedTextColor(tcell.ColorBlack).
SetSelectedBackgroundColor(tcell.ColorWhite).
SetBackgroundColor(tcell.ColorGreen)
list.SetMainTextColor(Styles.PrimitiveBackgroundColor).
SetSelectedTextColor(Styles.PrimitiveBackgroundColor).
SetSelectedBackgroundColor(Styles.PrimaryTextColor).
SetBackgroundColor(Styles.MoreContrastBackgroundColor)
d := &DropDown{
Box: NewBox(),
currentOption: -1,
list: list,
labelColor: tcell.ColorYellow,
fieldBackgroundColor: tcell.ColorBlue,
fieldTextColor: tcell.ColorWhite,
labelColor: Styles.SecondaryTextColor,
fieldBackgroundColor: Styles.ContrastBackgroundColor,
fieldTextColor: Styles.PrimaryTextColor,
}
d.focus = d

10
form.go

@ -72,11 +72,11 @@ func NewForm() *Form {
f := &Form{
Box: box,
itemPadding: 1,
labelColor: tcell.ColorYellow,
fieldBackgroundColor: tcell.ColorBlue,
fieldTextColor: tcell.ColorWhite,
buttonBackgroundColor: tcell.ColorBlue,
buttonTextColor: tcell.ColorWhite,
labelColor: Styles.SecondaryTextColor,
fieldBackgroundColor: Styles.ContrastBackgroundColor,
fieldTextColor: Styles.PrimaryTextColor,
buttonBackgroundColor: Styles.ContrastBackgroundColor,
buttonTextColor: Styles.PrimaryTextColor,
}
f.focus = f

6
inputfield.go

@ -46,9 +46,9 @@ type InputField struct {
func NewInputField() *InputField {
return &InputField{
Box: NewBox(),
labelColor: tcell.ColorYellow,
fieldBackgroundColor: tcell.ColorBlue,
fieldTextColor: tcell.ColorWhite,
labelColor: Styles.SecondaryTextColor,
fieldBackgroundColor: Styles.ContrastBackgroundColor,
fieldTextColor: Styles.PrimaryTextColor,
}
}

10
list.go

@ -61,11 +61,11 @@ func NewList() *List {
return &List{
Box: NewBox(),
showSecondaryText: true,
mainTextColor: tcell.ColorWhite,
secondaryTextColor: tcell.ColorGreen,
shortcutColor: tcell.ColorYellow,
selectedTextColor: tcell.ColorBlack,
selectedBackgroundColor: tcell.ColorWhite,
mainTextColor: Styles.PrimaryTextColor,
secondaryTextColor: Styles.TertiaryTextColor,
shortcutColor: Styles.SecondaryTextColor,
selectedTextColor: Styles.PrimitiveBackgroundColor,
selectedBackgroundColor: Styles.PrimaryTextColor,
}
}

13
modal.go

@ -33,18 +33,17 @@ type Modal struct {
func NewModal() *Modal {
m := &Modal{
Box: NewBox(),
textColor: tcell.ColorWhite,
textColor: Styles.PrimaryTextColor,
}
m.form = NewForm().
SetButtonsAlign(AlignCenter).
SetButtonBackgroundColor(tcell.ColorBlack).
SetButtonTextColor(tcell.ColorWhite)
m.form.SetBackgroundColor(tcell.ColorBlue).SetBorderPadding(0, 0, 0, 0)
SetButtonBackgroundColor(Styles.PrimitiveBackgroundColor).
SetButtonTextColor(Styles.PrimaryTextColor)
m.form.SetBackgroundColor(Styles.ContrastBackgroundColor).SetBorderPadding(0, 0, 0, 0)
m.frame = NewFrame(m.form).SetBorders(0, 0, 1, 0, 0, 0)
m.frame.SetBorder(true).
SetBackgroundColor(tcell.ColorBlue).
SetBorderPadding(1, 1, 1, 1).
SetBackgroundColor(tcell.ColorBlue)
SetBackgroundColor(Styles.ContrastBackgroundColor).
SetBorderPadding(1, 1, 1, 1)
m.focus = m
return m
}

32
styles.go

@ -0,0 +1,32 @@
package tview
import "github.com/gdamore/tcell"
// Styles defines various colors used when primitives are initialized. These
// may be changed to accommodate a different look and feel.
//
// The default is for applications with a black background and basic colors:
// black, white, yellow, green, and blue.
var Styles = struct {
PrimitiveBackgroundColor tcell.Color // Main background color for primitives.
ContrastBackgroundColor tcell.Color // Background color for contrasting elements.
MoreContrastBackgroundColor tcell.Color // Background color for even more contrasting elements.
BorderColor tcell.Color // Box borders.
TitleColor tcell.Color // Box titles.
GraphicsColor tcell.Color // Graphics.
PrimaryTextColor tcell.Color // Primary text.
SecondaryTextColor tcell.Color // Secondary text (e.g. labels).
TertiaryTextColor tcell.Color // Tertiary text (e.g. subtitles, notes).
InverseTextColor tcell.Color // Text on primary-colored backgrounds.
}{
PrimitiveBackgroundColor: tcell.ColorBlack,
ContrastBackgroundColor: tcell.ColorBlue,
MoreContrastBackgroundColor: tcell.ColorGreen,
BorderColor: tcell.ColorWhite,
TitleColor: tcell.ColorWhite,
GraphicsColor: tcell.ColorWhite,
PrimaryTextColor: tcell.ColorWhite,
SecondaryTextColor: tcell.ColorYellow,
TertiaryTextColor: tcell.ColorGreen,
InverseTextColor: tcell.ColorBlue,
}

4
table.go

@ -138,7 +138,7 @@ type Table struct {
func NewTable() *Table {
return &Table{
Box: NewBox(),
bordersColor: tcell.ColorWhite,
bordersColor: Styles.GraphicsColor,
separator: ' ',
lastColumn: -1,
}
@ -261,7 +261,7 @@ func (t *Table) SetCell(row, column int, cell *TableCell) *Table {
// SetCellSimple calls SetCell() with the given text, left-aligned, in white.
func (t *Table) SetCellSimple(row, column int, text string) *Table {
t.SetCell(row, column, &TableCell{Text: text, Align: AlignLeft, Color: tcell.ColorWhite})
t.SetCell(row, column, &TableCell{Text: text, Align: AlignLeft, Color: Styles.PrimaryTextColor})
return t
}

2
textview.go

@ -180,7 +180,7 @@ func NewTextView() *TextView {
lineOffset: -1,
scrollable: true,
wrap: true,
textColor: tcell.ColorWhite,
textColor: Styles.PrimaryTextColor,
dynamicColors: false,
}
}

2
util.go

@ -128,7 +128,7 @@ func Print(screen tcell.Screen, text string, x, y, maxWidth, align int, color tc
// PrintSimple prints white text to the screen at the given position.
func PrintSimple(screen tcell.Screen, text string, x, y int) {
Print(screen, text, x, y, math.MaxInt64, AlignLeft, tcell.ColorWhite)
Print(screen, text, x, y, math.MaxInt64, AlignLeft, Styles.PrimaryTextColor)
}
// WordWrap splits a text such that each resulting line does not exceed the

Loading…
Cancel
Save