widget/material: [API] move widget.Float.{Axis,Invert} into material.SliderStyle

Signed-off-by: Gordon Klaus <gordon.klaus@gmail.com>
This commit is contained in:
Gordon Klaus
2023-01-24 08:04:45 +01:00
committed by Elias Naur
parent 22aa00f476
commit db6b4de0f7
2 changed files with 12 additions and 12 deletions
+7 -9
View File
@@ -13,9 +13,7 @@ import (
// Float is for selecting a value in a range.
type Float struct {
Value float32
Axis layout.Axis
Invert bool
Value float32
drag gesture.Drag
pos float32 // position normalized to [0, 1]
@@ -29,12 +27,12 @@ func (f *Float) Dragging() bool { return f.drag.Dragging() }
// Layout updates the value according to drag events along the f's main axis.
//
// The range of f is set by the minimum constraints main axis value.
func (f *Float) Layout(gtx layout.Context, pointerMargin int, min, max float32) layout.Dimensions {
func (f *Float) Layout(gtx layout.Context, axis layout.Axis, min, max float32, invert bool, pointerMargin int) layout.Dimensions {
size := gtx.Constraints.Min
f.length = float32(f.Axis.Convert(size).X)
f.length = float32(axis.Convert(size).X)
var de *pointer.Event
for _, e := range f.drag.Events(gtx.Metric, gtx, gesture.Axis(f.Axis)) {
for _, e := range f.drag.Events(gtx.Metric, gtx, gesture.Axis(axis)) {
if e.Type == pointer.Press || e.Type == pointer.Drag {
de = &e
}
@@ -43,10 +41,10 @@ func (f *Float) Layout(gtx layout.Context, pointerMargin int, min, max float32)
value := f.Value
if de != nil {
xy := de.Position.X
if f.Axis == layout.Vertical {
if axis == layout.Vertical {
xy = f.length - de.Position.Y
}
if f.Invert {
if invert {
xy = f.length - xy
}
f.pos = xy / f.length
@@ -63,7 +61,7 @@ func (f *Float) Layout(gtx layout.Context, pointerMargin int, min, max float32)
f.pos = 1
}
margin := f.Axis.Convert(image.Pt(pointerMargin, 0))
margin := axis.Convert(image.Pt(pointerMargin, 0))
rect := image.Rectangle{
Min: margin.Mul(-1),
Max: size.Add(margin),