Skip to content

Commit

Permalink
make the callinfo view aware of the ui theme
Browse files Browse the repository at this point in the history
  • Loading branch information
ftl committed Jun 4, 2023
1 parent b34e9b0 commit e7955bb
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 30 deletions.
6 changes: 5 additions & 1 deletion core/callinfo/callinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,13 @@ func (c *Callinfo) SetView(view View) {
c.view = view
}

func (c *Callinfo) Refresh() {
c.ShowInfo(c.lastCallsign, c.lastBand, c.lastMode, c.lastExchange)
}

func (c *Callinfo) Show() {
c.view.Show()
c.ShowInfo(c.lastCallsign, c.lastBand, c.lastMode, c.lastExchange)
c.Refresh()
}

func (c *Callinfo) Hide() {
Expand Down
2 changes: 1 addition & 1 deletion ui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (a *application) activate() {
a.style = style.New()
a.style.AddToScreen(screen)

a.callinfoWindow = setupCallinfoWindow(a.windowGeometry)
a.callinfoWindow = setupCallinfoWindow(a.windowGeometry, a.style, a.controller.Callinfo)
a.scoreWindow = setupScoreWindow(a.windowGeometry, a.style)
a.rateWindow = setupRateWindow(a.windowGeometry, a.style)
a.spotsWindow = setupSpotsWindow(a.windowGeometry, a.controller.Bandmap)
Expand Down
108 changes: 92 additions & 16 deletions ui/callinfoView.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,57 @@ import (
"github.com/gotk3/gotk3/gtk"

"github.com/ftl/hellocontest/core"
"github.com/ftl/hellocontest/ui/style"
)

type CallinfoController interface {
Refresh()
}

type callinfoStyle struct {
colorProvider

backgroundColor style.Color
fontColor style.Color
fontSize float64
duplicateFG style.Color
duplicateBG style.Color
workedFG style.Color
workedBG style.Color
worthlessFG style.Color
worthlessBG style.Color
}

func (s *callinfoStyle) Refresh() {
s.backgroundColor = s.colorProvider.BackgroundColor()
s.fontColor = s.colorProvider.ForegroundColor()
s.duplicateFG = s.colorProvider.ColorByName(duplicateFGColorName)
s.duplicateBG = s.colorProvider.ColorByName(duplicateBGColorName)
s.workedFG = s.colorProvider.ColorByName(workedFGColorName)
s.workedBG = s.colorProvider.ColorByName(workedBGColorName)
s.worthlessFG = s.colorProvider.ColorByName(worthlessFGColorName)
s.worthlessBG = s.colorProvider.ColorByName(worthlessBGColorName)
}

type callinfoView struct {
controller CallinfoController

callsignLabel *gtk.Label
exchangeLabel *gtk.Label
dxccLabel *gtk.Label
valueLabel *gtk.Label
userInfoLabel *gtk.Label
supercheckLabel *gtk.Label

style *callinfoStyle
}

func setupCallinfoView(builder *gtk.Builder) *callinfoView {
result := new(callinfoView)
func setupCallinfoView(builder *gtk.Builder, colors colorProvider, controller CallinfoController) *callinfoView {
result := &callinfoView{
controller: controller,
style: &callinfoStyle{colorProvider: colors},
}
result.style.Refresh()

result.callsignLabel = getUI(builder, "callsignLabel").(*gtk.Label)
result.exchangeLabel = getUI(builder, "xchangeLabel").(*gtk.Label)
Expand All @@ -31,6 +69,21 @@ func setupCallinfoView(builder *gtk.Builder) *callinfoView {
return result
}

func (c *callinfoView) SetCallinfoController(controller CallinfoController) {
c.controller = controller
}

func (v *callinfoView) RefreshStyle() {
v.style.Refresh()
if v.controller != nil {
v.controller.Refresh()
}
}

func attr(name, value string) string {
return fmt.Sprintf("%s=%q", name, value)
}

func (v *callinfoView) SetCallsign(callsign string, worked, duplicate bool) {
if v == nil {
return
Expand All @@ -45,9 +98,15 @@ func (v *callinfoView) SetCallsign(callsign string, worked, duplicate bool) {
// see https://docs.gtk.org/Pango/pango_markup.html for reference
attributes := make([]string, 0, 1)
if duplicate {
attributes = append(attributes, "background='red' foreground='white'")
attributes = append(attributes,
attr("background", v.style.duplicateBG.ToWeb()),
attr("foreground", v.style.duplicateFG.ToWeb()),
)
} else if worked {
attributes = append(attributes, "foreground='orange'")
attributes = append(attributes,
attr("background", v.style.workedBG.ToWeb()),
attr("foreground", v.style.workedFG.ToWeb()),
)
}
attributeString := strings.Join(attributes, " ")

Expand Down Expand Up @@ -88,17 +147,17 @@ func (v *callinfoView) SetValue(points, multis int) {
var pointsMarkup string
switch {
case points < 1:
pointsMarkup = "foreground='silver'"
pointsMarkup = attr("foreground", "silver")
case points > 1:
pointsMarkup = "font-weight='heavy'"
pointsMarkup = attr("font-weight", "heavy")
}

var multisMarkup string
switch {
case multis < 1:
multisMarkup = "foreground='silver'"
multisMarkup = attr("foreground", "silver")
case multis > 1:
multisMarkup = "font-weight='heavy'"
multisMarkup = attr("font-weight", "heavy")
}

valueText := fmt.Sprintf("<span %s>%d points</span> / <span %s>%d multis</span>", pointsMarkup, points, multisMarkup, multis)
Expand Down Expand Up @@ -134,24 +193,41 @@ func (v *callinfoView) SetSupercheck(callsigns []core.AnnotatedCallsign) {
attributes := make([]string, 0, 3)
switch {
case callsign.Duplicate:
attributes = append(attributes, "foreground='red'")
attributes = append(attributes,
attr("background", v.style.duplicateBG.ToWeb()),
attr("foreground", v.style.duplicateFG.ToWeb()),
)

case callsign.Worked:
attributes = append(attributes, "foreground='orange'")
attributes = append(attributes,
attr("background", v.style.workedBG.ToWeb()),
attr("foreground", v.style.workedFG.ToWeb()),
)
case (callsign.Points == 0) && (callsign.Multis == 0):
attributes = append(attributes, "foreground='silver'")
attributes = append(attributes,
attr("background", v.style.worthlessBG.ToWeb()),
attr("foreground", v.style.worthlessFG.ToWeb()),
)
case callsign.Multis > 0:
attributes = append(attributes, "foreground='black'", "font-weight='heavy'")
attributes = append(attributes,
attr("background", v.style.backgroundColor.ToWeb()),
attr("foreground", v.style.fontColor.ToWeb()),
attr("font-weight", "heavy"),
)
default:
attributes = append(attributes, "foreground='black'")
attributes = append(attributes,
attr("background", v.style.backgroundColor.ToWeb()),
attr("foreground", v.style.fontColor.ToWeb()),
)
}

hasPredictedExchange := strings.Join(callsign.PredictedExchange, "") != ""
if callsign.ExactMatch || hasPredictedExchange {
attributes = append(attributes, "font-size='x-large'")
attributes = append(attributes, attr("font-size", "x-large"))
}
if hasPredictedExchange {
attributes = append(attributes, "font-style='italic'")
attributes = append(attributes, attr("font-style", "italic"))
}
attributes = append(attributes, "background='white'")
attributeString := strings.Join(attributes, " ")

var renderedCallsign string
Expand Down
13 changes: 10 additions & 3 deletions ui/callinfoWindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@ package ui
import (
"github.com/ftl/gmtry"
"github.com/gotk3/gotk3/gtk"

"github.com/ftl/hellocontest/ui/style"
)

const CallinfoWindowID = gmtry.ID("callinfo")

type callinfoWindow struct {
*callinfoView
controller CallinfoController

window *gtk.Window
geometry *gmtry.Geometry
style *style.Style
}

func setupCallinfoWindow(geometry *gmtry.Geometry) *callinfoWindow {
func setupCallinfoWindow(geometry *gmtry.Geometry, style *style.Style, controller CallinfoController) *callinfoWindow {
result := &callinfoWindow{
geometry: geometry,
controller: controller,
geometry: geometry,
style: style,
}

return result
Expand All @@ -38,7 +44,8 @@ func (w *callinfoWindow) Show() {
w.window.SetDefaultSize(300, 500)
w.window.SetTitle("Callsign Information")
w.window.Connect("destroy", w.onDestroy)
w.callinfoView = setupCallinfoView(builder)
w.callinfoView = setupCallinfoView(builder, w.style.ForWidget(w.window.ToWidget()), w.controller)
w.window.Connect("style-updated", w.callinfoView.RefreshStyle)
connectToGeometry(w.geometry, CallinfoWindowID, w.window)
}
w.window.ShowAll()
Expand Down
5 changes: 2 additions & 3 deletions ui/rateView.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/gotk3/gotk3/gtk"

"github.com/ftl/hellocontest/core"
"github.com/ftl/hellocontest/ui/style"
)

type rateView struct {
Expand All @@ -13,11 +12,11 @@ type rateView struct {
indicator *rateIndicator
}

func setupNewRateView(builder *gtk.Builder, style *style.Style) *rateView {
func setupNewRateView(builder *gtk.Builder, colors colorProvider) *rateView {
result := &rateView{}

result.indicator = newRateIndicator(colors)
result.indicatorArea = getUI(builder, "rateIndicatorArea").(*gtk.DrawingArea)
result.indicator = newRateIndicator(style.ForWidget(result.indicatorArea.ToWidget()))
result.indicatorArea.Connect("draw", result.indicator.Draw)
result.indicatorArea.Connect("style-updated", result.indicator.RefreshStyle)

Expand Down
3 changes: 2 additions & 1 deletion ui/rateWindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type rateWindow struct {
func setupRateWindow(geometry *gmtry.Geometry, style *style.Style) *rateWindow {
result := &rateWindow{
geometry: geometry,
style: style,
}

return result
Expand All @@ -41,7 +42,7 @@ func (w *rateWindow) Show() {
w.window.SetDefaultSize(300, 500)
w.window.SetTitle("QSO Rate")
w.window.Connect("destroy", w.onDestroy)
w.rateView = setupNewRateView(builder, w.style)
w.rateView = setupNewRateView(builder, w.style.ForWidget(w.window.ToWidget()))
connectToGeometry(w.geometry, RateWindowID, w.window)
}
w.window.ShowAll()
Expand Down
5 changes: 2 additions & 3 deletions ui/scoreView.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/gotk3/gotk3/gtk"

"github.com/ftl/hellocontest/core"
"github.com/ftl/hellocontest/ui/style"
)

type scoreView struct {
Expand All @@ -16,13 +15,13 @@ type scoreView struct {
graph *scoreGraph
}

func setupNewScoreView(builder *gtk.Builder, style *style.Style) *scoreView {
func setupNewScoreView(builder *gtk.Builder, colors colorProvider) *scoreView {
result := &scoreView{}

result.tableLabel = getUI(builder, "tableLabel").(*gtk.Label)

result.graph = newScoreGraph(colors)
result.graphArea = getUI(builder, "scoreGraphArea").(*gtk.DrawingArea)
result.graph = newScoreGraph(style.ForWidget(result.graphArea.ToWidget()))
result.graphArea.Connect("draw", result.graph.Draw)
result.graphArea.Connect("style-updated", result.graph.RefreshStyle)

Expand Down
3 changes: 2 additions & 1 deletion ui/scoreWindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type scoreWindow struct {
func setupScoreWindow(geometry *gmtry.Geometry, style *style.Style) *scoreWindow {
result := &scoreWindow{
geometry: geometry,
style: style,
}

return result
Expand All @@ -41,7 +42,7 @@ func (w *scoreWindow) Show() {
w.window.SetDefaultSize(300, 500)
w.window.SetTitle("Score")
w.window.Connect("destroy", w.onDestroy)
w.scoreView = setupNewScoreView(builder, w.style)
w.scoreView = setupNewScoreView(builder, w.style.ForWidget(w.window.ToWidget()))
connectToGeometry(w.geometry, ScoreWindowID, w.window)
}
w.window.ShowAll()
Expand Down
58 changes: 57 additions & 1 deletion ui/style/contest.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

@define-color hellocontest-graph-bg @theme_bg_color;
@define-color hellocontest-graph-axis @theme_text_color;
@define-color hellocontest-timeindicator #FFBF33;
@define-color hellocontest-timeindicator @theme_selected_bg_color;
@define-color hellocontest-lowzone #CCCCCC;

/*
Expand All @@ -39,6 +39,62 @@
color: black;
}

/*
* Callinfo window
*/

.callinfo {
background-color: @theme_bg_color;
color: @theme_fg_color;
}

.callinfo-duplicate {
background-color: @hellocontest-duplicate-bg;
color: @hellocontest-duplicate-fg;
}

.callinfo-worked {
background-color: @hellocontest-worked-spot-bg;
color: @hellocontest-spot-fg;
}

.callinfo-worthless {
background-color: @insensitive_bg_color;
color: @insensitive_fg_color;
}

.callinfo-multi {
font-weight: bold;
}

.callinfo-exact-match {
font-size: x-large;
}

.callinfo-predicted-exchange {
font-size: x-large;
font-style: italic;
}

.callinfo-match-insert {
text-decoration-line: underline;
text-decoration-style: solid;
}

.callinfo-match-delete {
/* no default */
}

.callinfo-match-substitude {
text-decoration-line: underline;
text-decoration-style: solid;
}

.callinfo-match-false-friend {
text-decoration-line: underline;
text-decoration-style: double;
}

/*
* Score window, band selection buttons
*/
Expand Down
Loading

0 comments on commit e7955bb

Please sign in to comment.