diff options
author | xengineering <me@xengineering.eu> | 2024-10-08 20:07:39 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-10-08 20:07:39 +0200 |
commit | 4bb64298928e7434b62029ccb334e37a311bbfb1 (patch) | |
tree | d2260d1336f7a6c1fb6e2a351e4fdfd93f539dda | |
parent | 9a31ee11242c8827eca1330a568362904c29d890 (diff) | |
download | soundbox-app-4bb64298928e7434b62029ccb334e37a311bbfb1.tar soundbox-app-4bb64298928e7434b62029ccb334e37a311bbfb1.tar.zst soundbox-app-4bb64298928e7434b62029ccb334e37a311bbfb1.zip |
Remove unnecessary state member PlayPauseButtonText
It was never idiomatic to add this member. Instead the state should only
contain a boolean state of playing or not and the text should be
selected during rendering based on this variable.
-rw-r--r-- | main.go | 16 |
1 files changed, 7 insertions, 9 deletions
@@ -44,7 +44,6 @@ type State struct { Title string UrlSelector widget.Enum PlayPauseButton widget.Clickable - PlayPauseButtonText string PlayerContext context.Context PlayerCancel context.CancelFunc } @@ -67,7 +66,6 @@ func NewUi(config Config) *Ui { ui.Window.Option(app.Title("soundbox")) ui.State.Title = "soundbox" - ui.State.PlayPauseButtonText = "Play" return &ui } @@ -134,7 +132,13 @@ func (ui *Ui) Layout(gtx layout.Context) layout.Dimensions { h1.Color = color.NRGBA{R: 88, G: 88, B: 88, A: 255} h1.Alignment = text.Middle - button := material.Button(ui.State.Theme, &ui.State.PlayPauseButton, ui.State.PlayPauseButtonText) + var playPauseButtonText string + if ui.State.IsPlaying { + playPauseButtonText = "Stop" + } else { + playPauseButtonText = "Play" + } + button := material.Button(ui.State.Theme, &ui.State.PlayPauseButton, playPauseButtonText) entries := []layout.FlexChild{ layout.Rigid(h1.Layout), @@ -160,13 +164,7 @@ func play(ctx context.Context, url string, targets []net.HardwareAddr, ui *Ui) { ui.State.Lock() defer ui.Window.Invalidate() defer ui.State.Unlock() - ui.State.IsPlaying = isPlaying - if ui.State.IsPlaying { - ui.State.PlayPauseButtonText = "Stop" - } else { - ui.State.PlayPauseButtonText = "Play" - } } setPlayingState(true) |