Skip to content

Commit

Permalink
use RichText to indicate available services
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Thienel <[email protected]>
  • Loading branch information
ftl committed Dec 7, 2024
1 parent f198541 commit 924cf4b
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions fyneui/statusBar.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,30 @@ import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/ftl/hellocontest/core"
)

type statusBar struct {
container *fyne.Container

radio *widget.Label
keyer *widget.Label
dxcc *widget.Label
scp *widget.Label
callhistory *widget.Label
mapLabel *widget.Label
radio *widget.RichText
keyer *widget.RichText
dxcc *widget.RichText
scp *widget.RichText
callhistory *widget.RichText
mapLabel *widget.RichText
}

func setupStatusBar() *statusBar {
result := &statusBar{
radio: widget.NewLabel(""),
keyer: widget.NewLabel(""),
dxcc: widget.NewLabel(""),
scp: widget.NewLabel(""),
callhistory: widget.NewLabel(""),
mapLabel: widget.NewLabel(""),
radio: widget.NewRichText(&widget.TextSegment{}),
keyer: widget.NewRichText(&widget.TextSegment{}),
dxcc: widget.NewRichText(&widget.TextSegment{}),
scp: widget.NewRichText(&widget.TextSegment{}),
callhistory: widget.NewRichText(&widget.TextSegment{}),
mapLabel: widget.NewRichText(&widget.TextSegment{}),
}
result.container = container.New(layout.NewHBoxLayout(), result.radio, result.keyer, result.dxcc, result.scp, result.callhistory, result.mapLabel, layout.NewSpacer())

Expand All @@ -48,17 +49,26 @@ func (b *statusBar) StatusChanged(service core.Service, available bool) {
}

func (b *statusBar) updateStatus(service core.Service, available bool) {
label, text := b.serviceLabel(service)
if label == nil {
indicator, text := b.serviceIndicator(service)
if indicator == nil {
log.Printf("unknown service %d", service)
return
}

label.TextStyle.Bold = available
label.SetText(text)
var color fyne.ThemeColorName
if available {
color = theme.ColorNameForeground
} else {
color = theme.ColorNameDisabled
}

segment := indicator.Segments[0].(*widget.TextSegment)
segment.Text = text
segment.Style.ColorName = color
segment.Style.TextStyle.Bold = available
indicator.Refresh()
}

func (b *statusBar) serviceLabel(service core.Service) (*widget.Label, string) {
func (b *statusBar) serviceIndicator(service core.Service) (*widget.RichText, string) {
switch service {
case core.RadioService:
return b.radio, "Radio"
Expand Down

0 comments on commit 924cf4b

Please sign in to comment.