mirror of
https://github.com/rivo/tview.git
synced 2025-04-24 13:48:56 +08:00
Merge 0e1fc10b3258546ff290fec426628c0c0415e9b5 into 23476fa0bab2d63c9d609d45ea351013ca7a0e56
This commit is contained in:
commit
83a7b29645
4
box.go
4
box.go
@ -68,6 +68,10 @@ type Box struct {
|
||||
mouseCapture func(action MouseAction, event *tcell.EventMouse) (MouseAction, *tcell.EventMouse)
|
||||
}
|
||||
|
||||
func (b *Box) SetDontClear(dontClear bool) {
|
||||
b.dontClear = dontClear
|
||||
}
|
||||
|
||||
// NewBox returns a Box without a border.
|
||||
func NewBox() *Box {
|
||||
b := &Box{
|
||||
|
73
button.go
73
button.go
@ -32,6 +32,9 @@ type Button struct {
|
||||
// key is provided indicating which key was pressed to leave (tab or
|
||||
// backtab).
|
||||
exit func(tcell.Key)
|
||||
|
||||
// Label's alignment, by default AlignCenter
|
||||
align int
|
||||
}
|
||||
|
||||
// NewButton returns a new input field.
|
||||
@ -41,9 +44,11 @@ func NewButton(label string) *Button {
|
||||
return &Button{
|
||||
Box: box,
|
||||
text: label,
|
||||
align: AlignCenter,
|
||||
disabled: false,
|
||||
style: tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.PrimaryTextColor),
|
||||
activatedStyle: tcell.StyleDefault.Background(Styles.PrimaryTextColor).Foreground(Styles.InverseTextColor),
|
||||
disabledStyle: tcell.StyleDefault.Background(Styles.ContrastBackgroundColor).Foreground(Styles.ContrastSecondaryTextColor),
|
||||
disabledStyle: tcell.StyleDefault.Background(Styles.DisabledBackgroundColor).Foreground(Styles.DisabledTextColor),
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,6 +69,13 @@ func (b *Button) SetLabelColor(color tcell.Color) *Button {
|
||||
return b
|
||||
}
|
||||
|
||||
// SetLabelAlign sets the label alignment within the button. This must be
|
||||
// either AlignLeft, AlignCenter, or AlignRight.
|
||||
func (b *Button) SetLabelAlign(align int) *Button {
|
||||
b.align = align
|
||||
return b
|
||||
}
|
||||
|
||||
// SetStyle sets the style of the button used when it is not focused.
|
||||
func (b *Button) SetStyle(style tcell.Style) *Button {
|
||||
b.style = style
|
||||
@ -77,6 +89,13 @@ func (b *Button) SetLabelColorActivated(color tcell.Color) *Button {
|
||||
return b
|
||||
}
|
||||
|
||||
// SetBackgroundColor sets the background color of the button text when
|
||||
// the button is not in focus. Overrides embeddedBox method.
|
||||
func (b *Button) SetBackgroundColor(color tcell.Color) *Button {
|
||||
b.style = b.style.Background(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 {
|
||||
@ -111,6 +130,47 @@ func (b *Button) IsDisabled() bool {
|
||||
return b.disabled
|
||||
}
|
||||
|
||||
// SetLabelColorDisabled sets the color of the button text when the button is
|
||||
// disabled.
|
||||
func (b *Button) SetLabelColorDisabled(color tcell.Color) *Button {
|
||||
b.disabledStyle = b.disabledStyle.Foreground(color)
|
||||
return b
|
||||
}
|
||||
|
||||
// SetBackgroundColorDisabled sets the background color of the button text when
|
||||
// the button is disabled.
|
||||
func (b *Button) SetBackgroundColorDisabled(color tcell.Color) *Button {
|
||||
b.disabledStyle = b.disabledStyle.Background(color)
|
||||
return b
|
||||
}
|
||||
|
||||
// SetStyleAttrs sets the label's style attributes. You can combine
|
||||
// different attributes using bitmask operations:
|
||||
//
|
||||
// button.SetStyleAttrs(tcell.AttrUnderline | tcell.AttrBold)
|
||||
func (b *Button) SetStyleAttrs(attrs tcell.AttrMask) *Button {
|
||||
b.style = b.style.Attributes(attrs)
|
||||
return b
|
||||
}
|
||||
|
||||
// SetActivatedStyleAttrs sets the label's activatedStyle attributes. You can combine
|
||||
// different attributes using bitmask operations:
|
||||
//
|
||||
// button.SetActivatedStyleAttrs(tcell.AttrUnderline | tcell.AttrBold)
|
||||
func (b *Button) SetActivatedStyleAttrs(attrs tcell.AttrMask) *Button {
|
||||
b.activatedStyle = b.activatedStyle.Attributes(attrs)
|
||||
return b
|
||||
}
|
||||
|
||||
// SetDisabledStyleAttrs sets the label's disabledStyle attributes. You can combine
|
||||
// different attributes using bitmask operations:
|
||||
//
|
||||
// button.SetDisabledStyleAttrs(tcell.AttrUnderline | tcell.AttrBold)
|
||||
func (b *Button) SetDisabledStyleAttrs(attrs tcell.AttrMask) *Button {
|
||||
b.disabledStyle = b.disabledStyle.Attributes(attrs)
|
||||
return b
|
||||
}
|
||||
|
||||
// SetSelectedFunc sets a handler which is called when the button was selected.
|
||||
func (b *Button) SetSelectedFunc(handler func()) *Button {
|
||||
b.selected = handler
|
||||
@ -129,6 +189,13 @@ func (b *Button) SetExitFunc(handler func(key tcell.Key)) *Button {
|
||||
return b
|
||||
}
|
||||
|
||||
|
||||
// SetEnabled sets the flag that, if false, button is available for interactions
|
||||
func (b *Button) SetEnabled() *Button {
|
||||
b.disabled = false
|
||||
return b
|
||||
}
|
||||
|
||||
// Draw draws this primitive onto the screen.
|
||||
func (b *Button) Draw(screen tcell.Screen) {
|
||||
// Draw the box.
|
||||
@ -148,14 +215,14 @@ func (b *Button) Draw(screen tcell.Screen) {
|
||||
b.SetBorderColor(borderColor)
|
||||
}()
|
||||
}
|
||||
b.SetBackgroundColor(backgroundColor)
|
||||
b.Box.SetBackgroundColor(backgroundColor)
|
||||
b.Box.DrawForSubclass(screen, b)
|
||||
|
||||
// Draw label.
|
||||
x, y, width, height := b.GetInnerRect()
|
||||
if width > 0 && height > 0 {
|
||||
y = y + height/2
|
||||
printWithStyle(screen, b.text, x, y, 0, width, AlignCenter, style, true)
|
||||
printWithStyle(screen, b.text, x, y, 0, width, b.align, style, true)
|
||||
}
|
||||
}
|
||||
|
||||
|
2
go.mod
2
go.mod
@ -1,4 +1,4 @@
|
||||
module github.com/rivo/tview
|
||||
module github.com/censync/tview
|
||||
|
||||
go 1.18
|
||||
|
||||
|
@ -15,6 +15,8 @@ type Theme struct {
|
||||
TertiaryTextColor tcell.Color // Tertiary text (e.g. subtitles, notes).
|
||||
InverseTextColor tcell.Color // Text on primary-colored backgrounds.
|
||||
ContrastSecondaryTextColor tcell.Color // Secondary text on ContrastBackgroundColor-colored backgrounds.
|
||||
DisabledBackgroundColor tcell.Color // Background color for disabled elements
|
||||
DisabledTextColor tcell.Color // Primary text for disabled elements
|
||||
}
|
||||
|
||||
// Styles defines the theme for applications. The default is for a black
|
||||
@ -31,5 +33,7 @@ var Styles = Theme{
|
||||
SecondaryTextColor: tcell.ColorYellow,
|
||||
TertiaryTextColor: tcell.ColorGreen,
|
||||
InverseTextColor: tcell.ColorBlue,
|
||||
DisabledBackgroundColor: tcell.ColorDarkSlateGray,
|
||||
DisabledTextColor: tcell.ColorLightGray,
|
||||
ContrastSecondaryTextColor: tcell.ColorNavy,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user