mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 01:15:35 +00:00
all: [API] change clip.RRect and UniformRRect to take integer coordinates
Like the change to op.Offset before this, clip.RRect and UniformRRect is usually used with integer coordinates. Change to integer coordinates to eliminate many useless conversions to float32. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"image"
|
||||
"image/color"
|
||||
|
||||
"gioui.org/f32"
|
||||
"gioui.org/internal/f32color"
|
||||
"gioui.org/layout"
|
||||
"gioui.org/op/clip"
|
||||
@@ -29,27 +28,26 @@ func ProgressBar(th *Theme, progress float32) ProgressBarStyle {
|
||||
}
|
||||
|
||||
func (p ProgressBarStyle) Layout(gtx layout.Context) layout.Dimensions {
|
||||
shader := func(width float32, color color.NRGBA) layout.Dimensions {
|
||||
maxHeight := unit.Dp(4)
|
||||
rr := float32(gtx.Px(unit.Dp(2)))
|
||||
shader := func(width int, color color.NRGBA) layout.Dimensions {
|
||||
var maxHeight = unit.Dp(4)
|
||||
rr := gtx.Px(unit.Dp(2))
|
||||
|
||||
d := image.Point{X: int(width), Y: gtx.Px(maxHeight)}
|
||||
d := image.Point{X: width, Y: gtx.Px(maxHeight)}
|
||||
|
||||
height := float32(gtx.Px(maxHeight))
|
||||
defer clip.UniformRRect(f32.Rectangle{Max: f32.Pt(width, height)}, rr).Push(gtx.Ops).Pop()
|
||||
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 := float32(gtx.Constraints.Max.X)
|
||||
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 {
|
||||
fillWidth := progressBarWidth * clamp1(p.Progress)
|
||||
fillWidth := int(float32(progressBarWidth) * clamp1(p.Progress))
|
||||
fillColor := p.Color
|
||||
if gtx.Queue == nil {
|
||||
fillColor = f32color.Disabled(fillColor)
|
||||
|
||||
Reference in New Issue
Block a user