Skip to content

Commit

Permalink
widget.Importance for every widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
blaize committed Jul 17, 2023
1 parent 8c730f7 commit 8edc6d1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 46 deletions.
2 changes: 1 addition & 1 deletion container/tabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ type tabButton struct {
hovered bool
icon fyne.Resource
iconPosition buttonIconPosition
importance widget.ButtonImportance
importance widget.Importance
onTapped func()
onClosed func()
text string
Expand Down
2 changes: 1 addition & 1 deletion dialog/confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (d *ConfirmDialog) SetConfirmText(label string) {
// SetConfirmImportance sets the importance level of the confirm button.
//
// Since 2.4
func (d *ConfirmDialog) SetConfirmImportance(importance widget.ButtonImportance) {
func (d *ConfirmDialog) SetConfirmImportance(importance widget.Importance) {
d.confirm.Importance = importance
}

Expand Down
23 changes: 3 additions & 20 deletions widget/button.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ type ButtonIconPlacement int
// ButtonImportance represents how prominent the button should appear
//
// Since: 1.4
type ButtonImportance int
// Deprecated: Use widget.Importance instead
type ButtonImportance Importance

// ButtonStyle determines the behaviour and rendering of a button.
type ButtonStyle int
Expand All @@ -42,24 +43,6 @@ const (
ButtonIconTrailingText
)

const (
// MediumImportance applies a standard appearance.
MediumImportance ButtonImportance = iota
// HighImportance applies a prominent appearance.
HighImportance
// LowImportance applies a subtle appearance.
LowImportance

// DangerImportance applies an error theme to the button.
//
// Since 2.3
DangerImportance
// WarningImportance applies an error theme to the button.
//
// Since 2.3
WarningImportance
)

var _ fyne.Focusable = (*Button)(nil)

// Button widget has a text label and triggers an event func when clicked
Expand All @@ -70,7 +53,7 @@ type Button struct {
// Specify how prominent the button should be, High will highlight the button and Low will remove some decoration.
//
// Since: 1.4
Importance ButtonImportance
Importance Importance
Alignment ButtonAlign
IconPlacement ButtonIconPlacement

Expand Down
24 changes: 24 additions & 0 deletions widget/importance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package widget

type Importance int

const (
// MediumImportance applies a standard appearance.
MediumImportance Importance = iota
// HighImportance applies a prominent appearance.
HighImportance
// LowImportance applies a subtle appearance.
LowImportance

// DangerImportance applies an error theme to the widget.
//
// Since 2.3
DangerImportance
// WarningImportance applies a warning theme to the widget.
//
// Since 2.3
WarningImportance

// SuccessImportance applies a success theme to the widget.
SuccessImportance
)
36 changes: 12 additions & 24 deletions widget/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,6 @@ import (
"fyne.io/fyne/v2/theme"
)

// TextImportance represents how colored the text should appear
type TextImportance int

const (
// TextImportanceNormal applies a standard appearance.
TextImportanceNormal TextImportance = iota
// TextImportanceSuccess applies a success color.
TextImportanceSuccess
// TextImportanceWarning applies a warning color.
TextImportanceWarning
// TextImportanceError applies an error color.
TextImportanceError
// TextImportanceDisabled applies a disabled color.
TextImportanceDisabled
)

// Label widget is a label component with appropriate padding and layout.
type Label struct {
BaseWidget
Expand All @@ -31,7 +15,7 @@ type Label struct {
Wrapping fyne.TextWrap // The wrapping of the Text
TextStyle fyne.TextStyle // The style of the label text
provider *RichText
Importance TextImportance
Importance Importance

binder basicBinder
}
Expand Down Expand Up @@ -144,14 +128,18 @@ func (l *Label) Unbind() {
func (l *Label) syncSegments() {
var color fyne.ThemeColorName
switch l.Importance {
case TextImportanceSuccess:
color = theme.ColorNameSuccess
case TextImportanceWarning:
color = theme.ColorNameWarning
case TextImportanceError:
color = theme.ColorNameError
case TextImportanceDisabled:
case LowImportance:
color = theme.ColorNameDisabled
case MediumImportance:
color = theme.ColorNameForeground
case HighImportance:
color = theme.ColorNamePrimary
case DangerImportance:
color = theme.ColorNameError
case WarningImportance:
color = theme.ColorNameWarning
case SuccessImportance:
color = theme.ColorNameSuccess
default:
color = theme.ColorNameForeground
}
Expand Down

0 comments on commit 8edc6d1

Please sign in to comment.