feat(tracker): change unit list into labels

This commit is contained in:
vsariola 2021-01-14 19:14:56 +02:00
parent a29f34734b
commit 2378be5021
3 changed files with 21 additions and 10 deletions

View File

@ -108,9 +108,14 @@ func (t *Tracker) layoutUnitList() layout.Widget {
for t.UnitBtns[i].Clicked() {
t.CurrentUnit = i
}
btnStyle := material.Button(t.Theme, t.UnitBtns[i], u.Type)
btnStyle.Background = transparent
children[i] = layout.Rigid(btnStyle.Layout)
i2 := i
labelStyle := LabelStyle{Text: u.Type, ShadeColor: black, Color: white, Font: labelDefaultFont, FontSize: unit.Sp(12)}
children[i] = layout.Rigid(func(gtx C) D {
dims := labelStyle.Layout(gtx)
gtx.Constraints = layout.Exact(dims.Size)
t.UnitBtns[i2].Layout(gtx)
return dims
})
}
return layout.Flex{Axis: layout.Vertical}.Layout(gtx, children...)
}

View File

@ -1,20 +1,24 @@
package tracker
import (
"image"
"image/color"
"gioui.org/f32"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/op/paint"
"gioui.org/text"
"gioui.org/unit"
"gioui.org/widget"
"image"
"image/color"
)
type LabelStyle struct {
Text string
Color color.RGBA
ShadeColor color.RGBA
Font text.Font
FontSize unit.Value
}
func (l LabelStyle) Layout(gtx layout.Context) layout.Dimensions {
@ -26,7 +30,7 @@ func (l LabelStyle) Layout(gtx layout.Context) layout.Dimensions {
dims := widget.Label{
Alignment: text.Start,
MaxLines: 1,
}.Layout(gtx, textShaper, labelFont, labelFontSize, l.Text)
}.Layout(gtx, textShaper, l.Font, l.FontSize, l.Text)
return layout.Dimensions{
Size: dims.Size.Add(image.Pt(2, 2)),
Baseline: dims.Baseline,
@ -37,11 +41,11 @@ func (l LabelStyle) Layout(gtx layout.Context) layout.Dimensions {
return widget.Label{
Alignment: text.Start,
MaxLines: 1,
}.Layout(gtx, textShaper, labelFont, labelFontSize, l.Text)
}.Layout(gtx, textShaper, l.Font, l.FontSize, l.Text)
}),
)
}
func Label(text string, color color.RGBA) layout.Widget {
return LabelStyle{Text: text, Color: color, ShadeColor: black}.Layout
return LabelStyle{Text: text, Color: color, ShadeColor: black, Font: labelDefaultFont, FontSize: labelDefaultFontSize}.Layout
}

View File

@ -45,8 +45,10 @@ var panelLightColor = light
var backgroundColor = color.RGBA{R: 18, G: 18, B: 18, A: 255}
var labelFont = fontCollection[6].Font
var labelFontSize = unit.Px(18)
var labelDefaultColor = highEmphasisTextColor
var labelDefaultBgColor = transparent
var labelDefaultFont = fontCollection[6].Font
var labelDefaultFontSize = unit.Sp(18)
var separatorLineColor = color.RGBA{R: 97, G: 97, B: 97, A: 97}