45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"image"
|
|
|
|
"gioui.org/layout"
|
|
"gioui.org/op/paint"
|
|
"gioui.org/unit"
|
|
"gioui.org/widget"
|
|
)
|
|
|
|
func (u *ui) lifecycleBranding(gtx layout.Context) layout.Dimensions {
|
|
if u.mode != "phone" {
|
|
return layout.Dimensions{}
|
|
}
|
|
return layout.Dimensions{}
|
|
}
|
|
|
|
func (u *ui) brandMark(gtx layout.Context, widthDP, heightDP float32) layout.Dimensions {
|
|
if u.mode == "phone" {
|
|
return u.brandImage(gtx, u.splashSquare, widthDP, heightDP)
|
|
}
|
|
return u.brandImage(gtx, u.logoHorizontal, widthDP, heightDP)
|
|
}
|
|
|
|
func (u *ui) brandImage(gtx layout.Context, src paint.ImageOp, widthDP, heightDP float32) layout.Dimensions {
|
|
width := gtx.Dp(unit.Dp(widthDP))
|
|
height := gtx.Dp(unit.Dp(heightDP))
|
|
if width > gtx.Constraints.Max.X {
|
|
width = gtx.Constraints.Max.X
|
|
}
|
|
if height > gtx.Constraints.Max.Y && gtx.Constraints.Max.Y > 0 {
|
|
height = gtx.Constraints.Max.Y
|
|
}
|
|
img := widget.Image{
|
|
Src: src,
|
|
Fit: widget.Contain,
|
|
Position: layout.W,
|
|
Scale: 1.0 / gtx.Metric.PxPerDp,
|
|
}
|
|
gtx.Constraints.Min = image.Point{}
|
|
gtx.Constraints.Max = image.Pt(width, height)
|
|
return img.Layout(gtx)
|
|
}
|