Skip to content

Commit

Permalink
use the desktop theme colors for the status indicators
Browse files Browse the repository at this point in the history
  • Loading branch information
ftl committed May 30, 2024
1 parent aaaaf6a commit 1f3bd70
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ui/mainWindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func setupMainWindow(builder *gtk.Builder, application *gtk.Application, style *
result.entryView = setupEntryView(builder)
result.workmodeView = setupWorkmodeView(builder)
result.keyerView = setupKeyerView(builder)
result.statusView = setupStatusView(builder)
result.statusView = setupStatusView(builder, style.ForWidget(result.window.ToWidget()))
result.callinfoView = setupCallinfoView(builder, style.ForWidget(result.window.ToWidget()))
result.stopKeyHandler = setupStopKeyHandler(&result.window.Widget)

Expand Down
40 changes: 25 additions & 15 deletions ui/statusView.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
)

type statusView struct {
colors colorProvider

radioLabel *gtk.Label
keyerLabel *gtk.Label
dxccLabel *gtk.Label
Expand All @@ -18,28 +20,41 @@ type statusView struct {
}

const (
availableStyle = "foreground='black'"
unavailableStyle = "foreground='lightgray'"
availableColor = "theme_selected_fg_color"
unavailableColor = "unfocused_insensitive_color"
)

func setupStatusView(builder *gtk.Builder) *statusView {
result := new(statusView)
func setupStatusView(builder *gtk.Builder, colors colorProvider) *statusView {
result := &statusView{
colors: colors,
}

result.radioLabel = getUI(builder, "radioStatusLabel").(*gtk.Label)
result.keyerLabel = getUI(builder, "keyerStatusLabel").(*gtk.Label)
result.dxccLabel = getUI(builder, "dxccStatusLabel").(*gtk.Label)
result.scpLabel = getUI(builder, "scpStatusLabel").(*gtk.Label)
result.callHistoryLabel = getUI(builder, "callHistoryStatusLabel").(*gtk.Label)

setStyledText(result.radioLabel, unavailableStyle, "Radio")
setStyledText(result.keyerLabel, unavailableStyle, "CW")
setStyledText(result.dxccLabel, unavailableStyle, "DXCC")
setStyledText(result.scpLabel, unavailableStyle, "SCP")
setStyledText(result.callHistoryLabel, unavailableStyle, "CH")
style := result.indicatorStyle(false)
setStyledText(result.radioLabel, style, "Radio")
setStyledText(result.keyerLabel, style, "CW")
setStyledText(result.dxccLabel, style, "DXCC")
setStyledText(result.scpLabel, style, "SCP")
setStyledText(result.callHistoryLabel, style, "CH")

return result
}

func (v *statusView) indicatorStyle(available bool) string {
var color string
if available {
color = availableColor
} else {
color = unavailableColor
}
return fmt.Sprintf("foreground='%s'", v.colors.ColorByName(color).ToWeb())
}

func (v *statusView) StatusChanged(service core.Service, available bool) {
log.Printf("service status changed: %d, %t", service, available)
label, text := v.serviceLabel(service)
Expand All @@ -48,12 +63,7 @@ func (v *statusView) StatusChanged(service core.Service, available bool) {
return
}

var style string
if available {
style = availableStyle
} else {
style = unavailableStyle
}
style := v.indicatorStyle(available)
setStyledText(label, style, text)
}

Expand Down

0 comments on commit 1f3bd70

Please sign in to comment.