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() { for t.UnitBtns[i].Clicked() {
t.CurrentUnit = i t.CurrentUnit = i
} }
btnStyle := material.Button(t.Theme, t.UnitBtns[i], u.Type) i2 := i
btnStyle.Background = transparent labelStyle := LabelStyle{Text: u.Type, ShadeColor: black, Color: white, Font: labelDefaultFont, FontSize: unit.Sp(12)}
children[i] = layout.Rigid(btnStyle.Layout) 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...) return layout.Flex{Axis: layout.Vertical}.Layout(gtx, children...)
} }

View File

@ -1,20 +1,24 @@
package tracker package tracker
import ( import (
"image"
"image/color"
"gioui.org/f32" "gioui.org/f32"
"gioui.org/layout" "gioui.org/layout"
"gioui.org/op" "gioui.org/op"
"gioui.org/op/paint" "gioui.org/op/paint"
"gioui.org/text" "gioui.org/text"
"gioui.org/unit"
"gioui.org/widget" "gioui.org/widget"
"image"
"image/color"
) )
type LabelStyle struct { type LabelStyle struct {
Text string Text string
Color color.RGBA Color color.RGBA
ShadeColor color.RGBA ShadeColor color.RGBA
Font text.Font
FontSize unit.Value
} }
func (l LabelStyle) Layout(gtx layout.Context) layout.Dimensions { 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{ dims := widget.Label{
Alignment: text.Start, Alignment: text.Start,
MaxLines: 1, MaxLines: 1,
}.Layout(gtx, textShaper, labelFont, labelFontSize, l.Text) }.Layout(gtx, textShaper, l.Font, l.FontSize, l.Text)
return layout.Dimensions{ return layout.Dimensions{
Size: dims.Size.Add(image.Pt(2, 2)), Size: dims.Size.Add(image.Pt(2, 2)),
Baseline: dims.Baseline, Baseline: dims.Baseline,
@ -37,11 +41,11 @@ func (l LabelStyle) Layout(gtx layout.Context) layout.Dimensions {
return widget.Label{ return widget.Label{
Alignment: text.Start, Alignment: text.Start,
MaxLines: 1, 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 { 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 backgroundColor = color.RGBA{R: 18, G: 18, B: 18, A: 255}
var labelFont = fontCollection[6].Font var labelDefaultColor = highEmphasisTextColor
var labelFontSize = unit.Px(18) 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} var separatorLineColor = color.RGBA{R: 97, G: 97, B: 97, A: 97}