Skip to content

Commit

Permalink
Rename TwoStateToolbarAction args and methods
Browse files Browse the repository at this point in the history
Name the function args and method names to match OnState and OffState.
  • Loading branch information
jimorc committed Oct 13, 2024
1 parent c1029a0 commit 60b932d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions cmd/twostatetoolbaraction_demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ func main() {
state := twoState0.GetState()
twoState0.SetState(!state)
})
icon0Button := widget.NewButton("Set Icon0", func() {
twoState0.SetState0Icon(theme.MediaPlayIcon())
offIconButton := widget.NewButton("Set OffIcon", func() {
twoState0.SetOffStateIcon(theme.MediaPlayIcon())
})
icon1Button := widget.NewButton("Set Icon1", func() {
onIconButton := widget.NewButton("Set OnIcon", func() {
twoState0.SetState1Icon(theme.MediaPauseIcon())
})
vc := container.NewVBox(toggleButton, icon0Button, icon1Button)
vc := container.NewVBox(toggleButton, offIconButton, onIconButton)
c := container.NewBorder(tb, vc, nil, nil)
w.SetContent(c)
w.ShowAndRun()
Expand Down
12 changes: 6 additions & 6 deletions widget/twostatetoolbaraction.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ type TwoStateToolbarAction struct {

// NewTwoStateToolbarAction returns a new push button style of Toolbar item that displays
// a different icon for each of its two states
func NewTwoStateToolbarAction(state0Icon fyne.Resource,
state1Icon fyne.Resource,
func NewTwoStateToolbarAction(offStateIcon fyne.Resource,
onStateIcon fyne.Resource,
onTapped func(TwoStateState)) *TwoStateToolbarAction {
t := &TwoStateToolbarAction{offIcon: state0Icon, onIcon: state1Icon, OnActivated: onTapped}
t := &TwoStateToolbarAction{offIcon: offStateIcon, onIcon: onStateIcon, OnActivated: onTapped}
t.button.SetIcon(t.offIcon)
t.button.OnTapped = t.activated
return t
Expand All @@ -50,14 +50,14 @@ func (t *TwoStateToolbarAction) SetState(state TwoStateState) {
t.button.Refresh()
}

// SetState0Icon sets the icon that is displayed when the state is TwoState0
func (t *TwoStateToolbarAction) SetState0Icon(icon fyne.Resource) {
// SetOffStateIcon sets the icon that is displayed when the state is OffState
func (t *TwoStateToolbarAction) SetOffStateIcon(icon fyne.Resource) {
t.offIcon = icon
t.setButtonIcon()
t.button.Refresh()
}

// SetState1Icon sets the icon that is displayed when the state is TwoState1
// SetOnStateIcon sets the icon that is displayed when the state is OnState
func (t *TwoStateToolbarAction) SetState1Icon(icon fyne.Resource) {
t.onIcon = icon
t.setButtonIcon()
Expand Down
14 changes: 7 additions & 7 deletions widget/twostatetoolbaraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func TestTwoStateToolbarAction_Tapped(t *testing.T) {
tb := widget.NewToolbar(action)
w := test.NewWindow(tb)
defer w.Close()
test.AssertRendersToImage(t, "twostatetoolbaraction/state0.png", w.Canvas())
test.AssertRendersToImage(t, "twostatetoolbaraction/offstate.png", w.Canvas())
action.button.Tapped(nil)
test.AssertRendersToImage(t, "twostatetoolbaraction/state1.png", w.Canvas())
test.AssertRendersToImage(t, "twostatetoolbaraction/onstate.png", w.Canvas())
}

func TestTwoStateToolbarAction_GetSetState(t *testing.T) {
Expand All @@ -57,10 +57,10 @@ func TestTwoStateToolbarAction_GetSetState(t *testing.T) {
action.SetState(OnState)
assert.Equal(t, OnState, action.GetState())
assert.Equal(t, OnState, ts)
test.AssertRendersToImage(t, "twostatetoolbaraction/state1.png", w.Canvas())
test.AssertRendersToImage(t, "twostatetoolbaraction/onstate.png", w.Canvas())
}

func TestTwoStateToolbarAction_SetState0Icon(t *testing.T) {
func TestTwoStateToolbarAction_SetOffStateIcon(t *testing.T) {
test.NewApp()
action := NewTwoStateToolbarAction(nil,
theme.MediaPauseIcon(),
Expand All @@ -69,11 +69,11 @@ func TestTwoStateToolbarAction_SetState0Icon(t *testing.T) {
w := test.NewWindow(tb)
defer w.Close()

action.SetState0Icon(theme.MediaPlayIcon())
action.SetOffStateIcon(theme.MediaPlayIcon())
assert.Equal(t, theme.MediaPlayIcon().Name(), action.offIcon.Name())
}

func TestTwoStateToolbarAction_SetState1Icon(t *testing.T) {
func TestTwoStateToolbarAction_SetOnStateIcon(t *testing.T) {
test.NewApp()
action := NewTwoStateToolbarAction(theme.MediaPlayIcon(),
nil,
Expand All @@ -82,6 +82,6 @@ func TestTwoStateToolbarAction_SetState1Icon(t *testing.T) {
w := test.NewWindow(tb)
defer w.Close()

action.SetState1Icon(theme.MediaPauseIcon())
action.SetOffStateIcon(theme.MediaPauseIcon())
assert.Equal(t, theme.MediaPauseIcon().Name(), action.onIcon.Name())
}

0 comments on commit 60b932d

Please sign in to comment.