From 4bb64298928e7434b62029ccb334e37a311bbfb1 Mon Sep 17 00:00:00 2001 From: xengineering Date: Tue, 8 Oct 2024 20:07:39 +0200 Subject: 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. --- main.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 727dad0..e67e20d 100644 --- a/main.go +++ b/main.go @@ -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) -- cgit v1.2.3-70-g09d2