From 7b002dd6b691b610fcc066442cb85823a8a0d3b4 Mon Sep 17 00:00:00 2001 From: sewn Date: Fri, 8 Mar 2024 19:09:00 +0300 Subject: [PATCH] splash: remove progress bar code, pr upstreamed --- splash/progressbar.go | 66 ------------------------------------------- splash/styles.go | 8 ++++-- 2 files changed, 6 insertions(+), 68 deletions(-) delete mode 100644 splash/progressbar.go diff --git a/splash/progressbar.go b/splash/progressbar.go deleted file mode 100644 index ff78f10c..00000000 --- a/splash/progressbar.go +++ /dev/null @@ -1,66 +0,0 @@ -package splash - -import ( - "image" - "image/color" - - "gioui.org/layout" - "gioui.org/op/clip" - "gioui.org/op/paint" - "gioui.org/unit" - "gioui.org/widget/material" -) - -type ProgressBarStyle struct { - Color color.NRGBA - TrackColor color.NRGBA - Progress float32 -} - -func ProgressBar(th *material.Theme, progress float32) ProgressBarStyle { - return ProgressBarStyle{ - Progress: progress, - Color: th.Palette.ContrastBg, - TrackColor: mulAlpha(th.Palette.Fg, 0x05), - } -} - -func (p ProgressBarStyle) Layout(gtx layout.Context) layout.Dimensions { - shader := func(width int, color color.NRGBA) layout.Dimensions { - d := image.Point{X: width, Y: gtx.Dp(unit.Dp(6))} - rr := gtx.Dp(4) - - defer clip.UniformRRect(image.Rectangle{Max: image.Pt(width, d.Y)}, rr).Push(gtx.Ops).Pop() - paint.ColorOp{Color: color}.Add(gtx.Ops) - paint.PaintOp{}.Add(gtx.Ops) - - return layout.Dimensions{Size: d} - } - - progressBarWidth := gtx.Constraints.Max.X - return layout.Stack{Alignment: layout.W}.Layout(gtx, - layout.Stacked(func(gtx layout.Context) layout.Dimensions { - return shader(progressBarWidth, p.TrackColor) - }), - layout.Stacked(func(gtx layout.Context) layout.Dimensions { - if p.Progress == 0.0 { - return layout.Dimensions{} - } - - fillWidth := int(float32(progressBarWidth) * clamp1(p.Progress)) - fillColor := p.Color - return shader(fillWidth, fillColor) - }), - ) -} - -// clamp1 limits v to range [0..1]. -func clamp1(v float32) float32 { - if v >= 1 { - return 1 - } else if v <= 0 { - return 0 - } else { - return v - } -} diff --git a/splash/styles.go b/splash/styles.go index 590f4a8c..133842c4 100644 --- a/splash/styles.go +++ b/splash/styles.go @@ -55,7 +55,9 @@ func (ui *Splash) drawCompact(gtx C) D { }), layout.Rigid(layout.Spacer{Height: unit.Dp(20)}.Layout), layout.Rigid(func(gtx C) D { - pb := ProgressBar(ui.Theme, ui.progress) + pb := material.ProgressBar(ui.Theme, ui.progress) + pb.Height = unit.Dp(6) + pb.Radius = unit.Dp(4) pb.TrackColor = rgb(ui.Config.TrackColor) return pb.Layout(gtx) }), @@ -92,7 +94,9 @@ func (ui *Splash) drawFamiliar(gtx C) D { Left: unit.Dp(32), Right: unit.Dp(32), }.Layout(gtx, func(gtx C) D { - pb := ProgressBar(ui.Theme, ui.progress) + pb := material.ProgressBar(ui.Theme, ui.progress) + pb.Height = unit.Dp(6) + pb.Radius = unit.Dp(4) pb.TrackColor = rgb(ui.Config.TrackColor) return pb.Layout(gtx) })