mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 09:25:38 +00:00
all: make unit.Converter concrete and rename to Metric
An interface for scaling dp and sp is overkill, at least for all current uses. Make it a concrete struct type, and rename it to the shorter and more precise Metric. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+4
-9
@@ -3,7 +3,6 @@
|
||||
package layout
|
||||
|
||||
import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"gioui.org/io/event"
|
||||
@@ -20,7 +19,7 @@ type Context struct {
|
||||
// layout.
|
||||
Constraints Constraints
|
||||
|
||||
Config system.Config
|
||||
Metric unit.Metric
|
||||
// By convention, a nil Queue is a signal to widgets to draw themselves
|
||||
// in a disabled state.
|
||||
Queue event.Queue
|
||||
@@ -47,18 +46,14 @@ func NewContext(ops *op.Ops, e system.FrameEvent) Context {
|
||||
Ops: ops,
|
||||
Now: e.Now,
|
||||
Queue: e.Queue,
|
||||
Config: e.Config,
|
||||
Metric: e.Metric,
|
||||
Constraints: Exact(e.Size),
|
||||
}
|
||||
}
|
||||
|
||||
// Px maps the value to pixels. If no configuration is set,
|
||||
// Px returns the rounded value of v.
|
||||
// Px maps the value to pixels.
|
||||
func (c Context) Px(v unit.Value) int {
|
||||
if c.Config == nil {
|
||||
return int(math.Round(float64(v.V)))
|
||||
}
|
||||
return c.Config.Px(v)
|
||||
return c.Metric.Px(v)
|
||||
}
|
||||
|
||||
// Events returns the events available for the key. If no
|
||||
|
||||
+1
-1
@@ -121,7 +121,7 @@ func (l *List) Dragging() bool {
|
||||
}
|
||||
|
||||
func (l *List) update() {
|
||||
d := l.scroll.Scroll(l.ctx, l.ctx, l.ctx.Now, gesture.Axis(l.Axis))
|
||||
d := l.scroll.Scroll(l.ctx.Metric, l.ctx, l.ctx.Now, gesture.Axis(l.Axis))
|
||||
l.scrollDelta = d
|
||||
l.Position.Offset += d
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user