Skip to content

Commit

Permalink
use a similar style in the callinfo view as in the spots list
Browse files Browse the repository at this point in the history
  • Loading branch information
ftl committed Jun 10, 2023
1 parent 342befa commit f3d7507
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 46 deletions.
55 changes: 24 additions & 31 deletions ui/callinfoView.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,17 @@ func (s *callinfoStyle) Refresh() {
s.worthlessBG = s.colorProvider.ColorByName(worthlessBGColorName)
}

const (
callinfoDuplicateClass style.Class = "callinfo-duplicate"
callinfoWorkedClass style.Class = "callinfo-worked"
callinfoWorthlessClass style.Class = "callinfo-worthless"
callinfoMultiClass style.Class = "callinfo-multi"
)

type callinfoView struct {
controller CallinfoController

rootGrid *gtk.Grid
callsignLabel *gtk.Label
exchangeLabel *gtk.Label
dxccLabel *gtk.Label
Expand All @@ -59,6 +67,7 @@ func setupCallinfoView(builder *gtk.Builder, colors colorProvider, controller Ca
}
result.style.Refresh()

result.rootGrid = getUI(builder, "callinfoGrid").(*gtk.Grid)
result.callsignLabel = getUI(builder, "callsignLabel").(*gtk.Label)
result.exchangeLabel = getUI(builder, "xchangeLabel").(*gtk.Label)
result.dxccLabel = getUI(builder, "dxccLabel").(*gtk.Label)
Expand Down Expand Up @@ -91,27 +100,19 @@ func (v *callinfoView) SetCallsign(callsign string, worked, duplicate bool) {

normalized := strings.ToUpper(strings.TrimSpace(callsign))
if normalized == "" {
v.callsignLabel.SetMarkup("-")
return
normalized = "-"
}
v.callsignLabel.SetText(normalized)

style.RemoveClass(&v.callsignLabel.Widget, callinfoDuplicateClass)
style.RemoveClass(&v.callsignLabel.Widget, callinfoWorkedClass)
style.RemoveClass(&v.callsignLabel.Widget, callinfoWorthlessClass)

// see https://docs.gtk.org/Pango/pango_markup.html for reference
attributes := make([]string, 0, 1)
if duplicate {
attributes = append(attributes,
attr("background", v.style.duplicateBG.ToWeb()),
attr("foreground", v.style.duplicateFG.ToWeb()),
)
style.AddClass(&v.callsignLabel.Widget, callinfoDuplicateClass)
} else if worked {
attributes = append(attributes,
attr("background", v.style.workedBG.ToWeb()),
attr("foreground", v.style.workedFG.ToWeb()),
)
style.AddClass(&v.callsignLabel.Widget, callinfoWorkedClass)
}
attributeString := strings.Join(attributes, " ")

renderedCallsign := fmt.Sprintf("<span %s>%s</span>", attributeString, normalized)
v.callsignLabel.SetMarkup(renderedCallsign)
}

func (v *callinfoView) SetDXCC(name, continent string, itu, cq int, arrlCompliant bool) {
Expand Down Expand Up @@ -143,25 +144,17 @@ func (v *callinfoView) SetValue(points, multis int) {
return
}

// see https://docs.gtk.org/Pango/pango_markup.html for reference
var pointsMarkup string
switch {
case points < 1:
pointsMarkup = attr("foreground", "silver")
case points > 1:
pointsMarkup = attr("font-weight", "heavy")
}
style.RemoveClass(&v.valueLabel.Widget, callinfoWorthlessClass)
style.RemoveClass(&v.valueLabel.Widget, callinfoMultiClass)

var multisMarkup string
switch {
case multis < 1:
multisMarkup = attr("foreground", "silver")
case multis > 1:
multisMarkup = attr("font-weight", "heavy")
case points < 1 && multis < 1:
style.AddClass(&v.valueLabel.Widget, callinfoWorthlessClass)
case multis > 0:
style.AddClass(&v.valueLabel.Widget, callinfoMultiClass)
}

valueText := fmt.Sprintf("<span %s>%d points</span> / <span %s>%d multis</span>", pointsMarkup, points, multisMarkup, multis)
v.valueLabel.SetMarkup(valueText)
v.valueLabel.SetText(fmt.Sprintf("%dP %dM", points, multis))
}

func (v *callinfoView) SetExchange(exchange string) {
Expand Down
22 changes: 13 additions & 9 deletions ui/glade/contest.glade
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ THE SOFTWARE.
<property name="can-focus">False</property>
<property name="accept-focus">False</property>
<child>
<!-- n-columns=2 n-rows=4 -->
<object class="GtkGrid">
<!-- n-columns=2 n-rows=5 -->
<object class="GtkGrid" id="callinfoGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="row-spacing">2</property>
Expand All @@ -47,12 +47,13 @@ THE SOFTWARE.
<property name="label" translatable="yes">DL1ABC</property>
<property name="wrap">True</property>
<attributes>
<attribute name="scale" value="3"/>
<attribute name="scale" value="4"/>
</attributes>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
<property name="height">2</property>
</packing>
</child>
<child>
Expand All @@ -69,7 +70,8 @@ THE SOFTWARE.
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
<property name="top-attach">2</property>
<property name="width">2</property>
</packing>
</child>
<child>
Expand Down Expand Up @@ -104,7 +106,7 @@ THE SOFTWARE.
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">3</property>
<property name="top-attach">4</property>
<property name="width">2</property>
</packing>
</child>
Expand All @@ -117,7 +119,7 @@ THE SOFTWARE.
<property name="label" translatable="yes">1234</property>
<property name="justify">right</property>
<attributes>
<attribute name="scale" value="3"/>
<attribute name="scale" value="2"/>
</attributes>
</object>
<packing>
Expand All @@ -133,9 +135,11 @@ THE SOFTWARE.
<property name="margin-start">2</property>
<property name="margin-end">2</property>
<property name="hexpand">True</property>
<property name="label" translatable="yes">1 Points / 0 Multis</property>
<property name="use-markup">True</property>
<property name="label" translatable="yes">1P 1M</property>
<property name="wrap">True</property>
<attributes>
<attribute name="scale" value="2"/>
</attributes>
</object>
<packing>
<property name="left-attach">1</property>
Expand All @@ -152,7 +156,7 @@ THE SOFTWARE.
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
<property name="top-attach">3</property>
<property name="width">2</property>
</packing>
</child>
Expand Down
10 changes: 4 additions & 6 deletions ui/style/contest.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,21 @@
* Callinfo window
*/

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

.callinfo-duplicate {
background-color: @hellocontest-duplicate-bg;
color: @hellocontest-duplicate-fg;
padding-right: 3px;
padding-left: 3px;
}

.callinfo-worked {
background-color: @hellocontest-worked-spot-bg;
color: @hellocontest-spot-fg;
padding-right: 3px;
padding-left: 3px;
}

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

Expand Down

0 comments on commit f3d7507

Please sign in to comment.