Skip to content

Commit

Permalink
Remove the old style and hideshadow fields.
Browse files Browse the repository at this point in the history
This fixes a mistake in 1.4 where low importance buttons were too small
  • Loading branch information
andydotxyz committed Jan 14, 2021
1 parent 6d0629f commit 7a0f00b
Show file tree
Hide file tree
Showing 35 changed files with 43 additions and 56 deletions.
2 changes: 1 addition & 1 deletion cmd/fyne_settings/settings/appearance.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (s *Settings) LoadAppearanceScreen(w fyne.Window) fyne.CanvasObject {
scale.Append(widget.NewGroup("Theme", themes))

bottom := widget.NewHBox(layout.NewSpacer(),
&widget.Button{Text: "Apply", Style: widget.PrimaryButton, OnTapped: func() {
&widget.Button{Text: "Apply", Importance: widget.HighImportance, OnTapped: func() {
err := s.save()
if err != nil {
fyne.LogError("Failed on saving", err)
Expand Down
6 changes: 3 additions & 3 deletions cmd/fyne_settings/settings/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func (s *Settings) chooseScale(value float32) {

for _, scale := range scales {
if scale.scale == value {
scale.button.Style = widget.PrimaryButton
scale.button.Importance = widget.HighImportance
} else {
scale.button.Style = widget.DefaultButton
scale.button.Importance = widget.MediumImportance
}

scale.button.Refresh()
Expand All @@ -50,7 +50,7 @@ func (s *Settings) makeScaleButtons() []fyne.CanvasObject {
s.chooseScale(value)
})
if s.fyneSettings.Scale == scale.scale {
button.Style = widget.PrimaryButton
button.Importance = widget.HighImportance
}

scale.button = button
Expand Down
8 changes: 4 additions & 4 deletions cmd/fyne_settings/settings/scale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ func TestChooseScale(t *testing.T) {

test.Tap(buttons[0].(*widget.Button))
assert.Equal(t, float32(0.5), s.fyneSettings.Scale)
assert.Equal(t, widget.PrimaryButton, buttons[0].(*widget.Button).Style)
assert.Equal(t, widget.DefaultButton, buttons[2].(*widget.Button).Style)
assert.Equal(t, widget.HighImportance, buttons[0].(*widget.Button).Importance)
assert.Equal(t, widget.MediumImportance, buttons[2].(*widget.Button).Importance)
}

func TestMakeScaleButtons(t *testing.T) {
Expand All @@ -27,8 +27,8 @@ func TestMakeScaleButtons(t *testing.T) {
buttons := s.makeScaleButtons()

assert.Equal(t, 5, len(buttons))
assert.Equal(t, widget.DefaultButton, buttons[0].(*widget.Button).Style)
assert.Equal(t, widget.PrimaryButton, buttons[2].(*widget.Button).Style)
assert.Equal(t, widget.MediumImportance, buttons[0].(*widget.Button).Importance)
assert.Equal(t, widget.HighImportance, buttons[2].(*widget.Button).Importance)
}

func TestMakeScalePreviews(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion dialog/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func NewCustomConfirm(title, confirm, dismiss string, content fyne.CanvasObject,
d.dismiss = &widget.Button{Text: dismiss, Icon: theme.CancelIcon(),
OnTapped: d.Hide,
}
ok := &widget.Button{Text: confirm, Icon: theme.ConfirmIcon(), Style: widget.PrimaryButton,
ok := &widget.Button{Text: confirm, Icon: theme.ConfirmIcon(), Importance: widget.HighImportance,
OnTapped: func() {
d.hideWithResponse(true)
},
Expand Down
2 changes: 1 addition & 1 deletion dialog/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (p *ColorPickerDialog) updateUI() {
p.advanced,
)

confirm := &widget.Button{Text: "Confirm", Icon: theme.ConfirmIcon(), Style: widget.PrimaryButton,
confirm := &widget.Button{Text: "Confirm", Icon: theme.ConfirmIcon(), Importance: widget.HighImportance,
OnTapped: func() {
p.selectColor(p.color)
},
Expand Down
2 changes: 1 addition & 1 deletion dialog/confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewConfirm(title, message string, callback func(bool), parent fyne.Window)
d.dismiss = &widget.Button{Text: "No", Icon: theme.CancelIcon(),
OnTapped: d.Hide,
}
confirm := &widget.Button{Text: "Yes", Icon: theme.ConfirmIcon(), Style: widget.PrimaryButton,
confirm := &widget.Button{Text: "Yes", Icon: theme.ConfirmIcon(), Importance: widget.HighImportance,
OnTapped: func() {
d.hideWithResponse(true)
},
Expand Down
2 changes: 1 addition & 1 deletion dialog/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (f *fileDialog) makeUI() fyne.CanvasObject {
callback(f.dir, nil)
}
})
f.open.Style = widget.PrimaryButton
f.open.Importance = widget.HighImportance
f.open.Disable()
if f.file.save {
f.fileName.SetText(f.initialFileName)
Expand Down
Binary file modified dialog/testdata/color/dialog_expanded_theme_default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dialog/testdata/color/dialog_expanded_theme_ugly.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dialog/testdata/color/dialog_recents_theme_default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dialog/testdata/color/dialog_recents_theme_ugly.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dialog/testdata/color/dialog_theme_default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified dialog/testdata/color/dialog_theme_ugly.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 8 additions & 21 deletions widget/button.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,11 @@ const (
LowImportance
)

const (
// DefaultButton is the standard button style.
// Deprecated: use Importance = MediumImportance instead.
DefaultButton ButtonStyle = iota
// PrimaryButton that should be more prominent to the user.
// Deprecated: use Importance = HighImportance instead.
PrimaryButton
)

// Button widget has a text label and triggers an event func when clicked
type Button struct {
DisableableWidget
Text string
// Deprecated, use Importance instead, where HighImportance matches PrimaryButton
Style ButtonStyle
Icon fyne.Resource
Icon fyne.Resource
// Specify how prominent the button should be, High will highlight the button and Low will remove some decoration.
//
// Since: 1.4
Expand All @@ -74,8 +63,6 @@ type Button struct {
IconPlacement ButtonIconPlacement

OnTapped func() `json:"-"`
// Deprecated: use Importance = LowImportance instead of HideShadow = true.
HideShadow bool

hovered bool
tapAnim *fyne.Animation
Expand Down Expand Up @@ -119,7 +106,7 @@ func (b *Button) CreateRenderer() fyne.WidgetRenderer {
text,
}
shadowLevel := widget.ButtonLevel
if b.HideShadow || b.Importance == LowImportance {
if b.Importance == LowImportance {
shadowLevel = widget.BaseLevel
}
r := &buttonRenderer{
Expand Down Expand Up @@ -223,7 +210,7 @@ func (r *buttonRenderer) BackgroundColor() color.Color {
func (r *buttonRenderer) Layout(size fyne.Size) {
var inset fyne.Position
bgSize := size
if !r.button.HideShadow || r.button.Importance != LowImportance {
if r.button.Importance != LowImportance {
inset = fyne.NewPos(theme.Padding()/2, theme.Padding()/2)
bgSize = size.Subtract(fyne.NewSize(theme.Padding(), theme.Padding()))
}
Expand Down Expand Up @@ -307,18 +294,18 @@ func (r *buttonRenderer) applyTheme() {
switch {
case r.button.disabled:
r.label.Color = theme.DisabledColor()
case r.button.Style == PrimaryButton || r.button.Importance == HighImportance:
case r.button.Importance == HighImportance:
r.label.Color = theme.BackgroundColor()
}
if r.icon != nil && r.icon.Resource != nil {
switch res := r.icon.Resource.(type) {
case *theme.ThemedResource:
if r.button.Style == PrimaryButton || r.button.Importance == HighImportance {
if r.button.Importance == HighImportance {
r.icon.Resource = theme.NewInvertedThemedResource(res)
r.icon.Refresh()
}
case *theme.InvertedThemedResource:
if r.button.Style != PrimaryButton || r.button.Importance != HighImportance {
if r.button.Importance != HighImportance {
r.icon.Resource = res.Original()
r.icon.Refresh()
}
Expand All @@ -330,7 +317,7 @@ func (r *buttonRenderer) buttonColor() color.Color {
switch {
case r.button.Disabled():
return theme.DisabledButtonColor()
case r.button.Style == PrimaryButton, r.button.Importance == HighImportance:
case r.button.Importance == HighImportance:
return theme.PrimaryColor()
case r.button.hovered:
return theme.HoverColor()
Expand All @@ -340,7 +327,7 @@ func (r *buttonRenderer) buttonColor() color.Color {
}

func (r *buttonRenderer) padding() fyne.Size {
if r.button.HideShadow || r.button.Importance == LowImportance {
if r.button.Importance == LowImportance {
return fyne.NewSize(theme.Padding()*2, theme.Padding()*2)
}
if r.button.Text == "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<container pos="4,4" size="142x192">
<widget pos="23,58" size="95x75" type="*widget.Accordion">
<widget pos="0,4" size="95x29" type="*widget.Button">
<rectangle fillColor="button" pos="2,2" size="91x25"/>
<rectangle fillColor="button" size="95x29"/>
<rectangle size="0x0"/>
<text bold pos="28,4" size="11x21">A</text>
<image fillMode="contain" pos="4,4" rsc="menuDropDownIcon" size="20x21"/>
</widget>
<widget pos="0,42" size="95x29" type="*widget.Button">
<rectangle fillColor="button" pos="2,2" size="91x25"/>
<rectangle fillColor="button" size="95x29"/>
<rectangle size="0x0"/>
<text bold pos="28,4" size="11x21">B</text>
<image fillMode="contain" pos="4,4" rsc="menuDropDownIcon" size="20x21"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<container pos="4,4" size="142x192">
<widget pos="23,17" size="95x157" type="*widget.Accordion">
<widget pos="0,4" size="95x29" type="*widget.Button">
<rectangle fillColor="button" pos="2,2" size="91x25"/>
<rectangle fillColor="button" size="95x29"/>
<rectangle size="0x0"/>
<text bold pos="28,4" size="11x21">A</text>
<image fillMode="contain" pos="4,4" rsc="menuDropUpIcon" size="20x21"/>
</widget>
<widget pos="0,83" size="95x29" type="*widget.Button">
<rectangle fillColor="button" pos="2,2" size="91x25"/>
<rectangle fillColor="button" size="95x29"/>
<rectangle size="0x0"/>
<text bold pos="28,4" size="11x21">B</text>
<image fillMode="contain" pos="4,4" rsc="menuDropUpIcon" size="20x21"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<container pos="4,4" size="142x192">
<widget pos="45,77" size="52x37" type="*widget.Accordion">
<widget pos="0,4" size="52x29" type="*widget.Button">
<rectangle fillColor="button" pos="2,2" size="48x25"/>
<rectangle fillColor="button" size="52x29"/>
<rectangle size="0x0"/>
<text bold pos="28,4" size="11x21">A</text>
<image fillMode="contain" pos="4,4" rsc="menuDropDownIcon" size="20x21"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<container pos="4,4" size="142x192">
<widget pos="45,57" size="52x78" type="*widget.Accordion">
<widget pos="0,4" size="52x29" type="*widget.Button">
<rectangle fillColor="button" pos="2,2" size="48x25"/>
<rectangle fillColor="button" size="52x29"/>
<rectangle size="0x0"/>
<text bold pos="28,4" size="11x21">A</text>
<image fillMode="contain" pos="4,4" rsc="menuDropUpIcon" size="20x21"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<container pos="4,4" size="142x192">
<widget pos="23,58" size="95x75" type="*widget.Accordion">
<widget pos="0,4" size="95x29" type="*widget.Button">
<rectangle fillColor="button" pos="2,2" size="91x25"/>
<rectangle fillColor="button" size="95x29"/>
<rectangle size="0x0"/>
<text bold pos="28,4" size="11x21">A</text>
<image fillMode="contain" pos="4,4" rsc="menuDropDownIcon" size="20x21"/>
</widget>
<widget pos="0,42" size="95x29" type="*widget.Button">
<rectangle fillColor="button" pos="2,2" size="91x25"/>
<rectangle fillColor="button" size="95x29"/>
<rectangle size="0x0"/>
<text bold pos="28,4" size="11x21">B</text>
<image fillMode="contain" pos="4,4" rsc="menuDropDownIcon" size="20x21"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<container pos="4,4" size="142x192">
<widget pos="23,38" size="95x116" type="*widget.Accordion">
<widget pos="0,4" size="95x29" type="*widget.Button">
<rectangle fillColor="button" pos="2,2" size="91x25"/>
<rectangle fillColor="button" size="95x29"/>
<rectangle size="0x0"/>
<text bold pos="28,4" size="11x21">A</text>
<image fillMode="contain" pos="4,4" rsc="menuDropDownIcon" size="20x21"/>
</widget>
<widget pos="0,42" size="95x29" type="*widget.Button">
<rectangle fillColor="button" pos="2,2" size="91x25"/>
<rectangle fillColor="button" size="95x29"/>
<rectangle size="0x0"/>
<text bold pos="28,4" size="11x21">B</text>
<image fillMode="contain" pos="4,4" rsc="menuDropUpIcon" size="20x21"/>
Expand Down
2 changes: 1 addition & 1 deletion widget/testdata/accordion/layout_single_open_one_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<container pos="4,4" size="142x192">
<widget pos="45,77" size="52x37" type="*widget.Accordion">
<widget pos="0,4" size="52x29" type="*widget.Button">
<rectangle fillColor="button" pos="2,2" size="48x25"/>
<rectangle fillColor="button" size="52x29"/>
<rectangle size="0x0"/>
<text bold pos="28,4" size="11x21">A</text>
<image fillMode="contain" pos="4,4" rsc="menuDropDownIcon" size="20x21"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<container pos="4,4" size="142x192">
<widget pos="45,57" size="52x78" type="*widget.Accordion">
<widget pos="0,4" size="52x29" type="*widget.Button">
<rectangle fillColor="button" pos="2,2" size="48x25"/>
<rectangle fillColor="button" size="52x29"/>
<rectangle size="0x0"/>
<text bold pos="28,4" size="11x21">A</text>
<image fillMode="contain" pos="4,4" rsc="menuDropUpIcon" size="20x21"/>
Expand Down
Binary file modified widget/testdata/accordion/theme_changed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified widget/testdata/accordion/theme_initial.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion widget/testdata/select_entry/disableable_disabled.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</widget>
</widget>
<widget pos="102,8" size="20x20" type="*widget.Button">
<rectangle fillColor="disabled button" pos="2,2" size="16x16"/>
<rectangle fillColor="disabled button" size="20x20"/>
<rectangle fillColor="rgba(0,0,0,0)" pos="0,2" size="16x16"/>
<image fillMode="contain" rsc="menuDropDownIcon" size="iconInlineSize" themed="disabled"/>
</widget>
Expand Down
2 changes: 1 addition & 1 deletion widget/testdata/select_entry/disableable_enabled.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</widget>
</widget>
<widget pos="102,8" size="20x20" type="*widget.Button">
<rectangle fillColor="button" pos="2,2" size="16x16"/>
<rectangle fillColor="button" size="20x20"/>
<rectangle size="0x0"/>
<image fillMode="contain" rsc="menuDropDownIcon" size="iconInlineSize"/>
</widget>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</widget>
</widget>
<widget pos="102,8" size="20x20" type="*widget.Button">
<rectangle fillColor="button" pos="2,2" size="16x16"/>
<rectangle fillColor="button" size="20x20"/>
<rectangle fillColor="rgba(0,0,0,0)" pos="0,2" size="16x16"/>
<image fillMode="contain" rsc="menuDropDownIcon" size="iconInlineSize"/>
</widget>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</widget>
</widget>
<widget pos="102,8" size="20x20" type="*widget.Button">
<rectangle fillColor="button" pos="2,2" size="16x16"/>
<rectangle fillColor="button" size="20x20"/>
<rectangle fillColor="rgba(0,0,0,0)" pos="0,2" size="16x16"/>
<image fillMode="contain" rsc="menuDropDownIcon" size="iconInlineSize"/>
</widget>
Expand Down
2 changes: 1 addition & 1 deletion widget/testdata/select_entry/dropdown_B_opened.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</widget>
</widget>
<widget pos="102,8" size="20x20" type="*widget.Button">
<rectangle fillColor="button" pos="2,2" size="16x16"/>
<rectangle fillColor="button" size="20x20"/>
<rectangle fillColor="rgba(0,0,0,0)" pos="0,2" size="16x16"/>
<image fillMode="contain" rsc="menuDropDownIcon" size="iconInlineSize"/>
</widget>
Expand Down
2 changes: 1 addition & 1 deletion widget/testdata/select_entry/dropdown_empty_opened.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</widget>
</widget>
<widget pos="102,8" size="20x20" type="*widget.Button">
<rectangle fillColor="button" pos="2,2" size="16x16"/>
<rectangle fillColor="button" size="20x20"/>
<rectangle fillColor="rgba(0,0,0,0)" pos="0,2" size="16x16"/>
<image fillMode="contain" rsc="menuDropDownIcon" size="iconInlineSize"/>
</widget>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</widget>
</widget>
<widget pos="82,8" size="20x20" type="*widget.Button">
<rectangle fillColor="button" pos="2,2" size="16x16"/>
<rectangle fillColor="button" size="20x20"/>
<rectangle fillColor="rgba(0,0,0,0)" pos="0,2" size="16x16"/>
<image fillMode="contain" rsc="menuDropDownIcon" size="iconInlineSize"/>
</widget>
Expand Down
2 changes: 1 addition & 1 deletion widget/testdata/select_entry/dropdown_empty_setopts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</widget>
</widget>
<widget pos="102,8" size="20x20" type="*widget.Button">
<rectangle fillColor="button" pos="2,2" size="16x16"/>
<rectangle fillColor="button" size="20x20"/>
<rectangle fillColor="rgba(0,0,0,0)" pos="0,2" size="16x16"/>
<image fillMode="contain" rsc="menuDropDownIcon" size="iconInlineSize"/>
</widget>
Expand Down
2 changes: 1 addition & 1 deletion widget/testdata/select_entry/dropdown_initial.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</widget>
</widget>
<widget pos="102,8" size="20x20" type="*widget.Button">
<rectangle fillColor="button" pos="2,2" size="16x16"/>
<rectangle fillColor="button" size="20x20"/>
<rectangle size="0x0"/>
<image fillMode="contain" rsc="menuDropDownIcon" size="iconInlineSize"/>
</widget>
Expand Down
2 changes: 1 addition & 1 deletion widget/testdata/select_entry/dropdown_tapped_B.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</widget>
</widget>
<widget pos="102,8" size="20x20" type="*widget.Button">
<rectangle fillColor="button" pos="2,2" size="16x16"/>
<rectangle fillColor="button" size="20x20"/>
<rectangle fillColor="rgba(0,0,0,0)" pos="0,2" size="16x16"/>
<image fillMode="contain" rsc="menuDropDownIcon" size="iconInlineSize"/>
</widget>
Expand Down
2 changes: 1 addition & 1 deletion widget/testdata/select_entry/dropdown_tapped_C.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</widget>
</widget>
<widget pos="102,8" size="20x20" type="*widget.Button">
<rectangle fillColor="button" pos="2,2" size="16x16"/>
<rectangle fillColor="button" size="20x20"/>
<rectangle fillColor="rgba(0,0,0,0)" pos="0,2" size="16x16"/>
<image fillMode="contain" rsc="menuDropDownIcon" size="iconInlineSize"/>
</widget>
Expand Down

0 comments on commit 7a0f00b

Please sign in to comment.