mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 01:45:36 +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:
@@ -6,7 +6,6 @@ package window
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
|
||||
"gioui.org/gpu/backend"
|
||||
"gioui.org/io/event"
|
||||
@@ -71,29 +70,6 @@ type windowAndOptions struct {
|
||||
opts *Options
|
||||
}
|
||||
|
||||
// config implements the system.Config interface.
|
||||
type config struct {
|
||||
// Device pixels per dp.
|
||||
pxPerDp float32
|
||||
// Device pixels per sp.
|
||||
pxPerSp float32
|
||||
}
|
||||
|
||||
func (c *config) Px(v unit.Value) int {
|
||||
var r float32
|
||||
switch v.U {
|
||||
case unit.UnitPx:
|
||||
r = v.V
|
||||
case unit.UnitDp:
|
||||
r = c.pxPerDp * v.V
|
||||
case unit.UnitSp:
|
||||
r = c.pxPerSp * v.V
|
||||
default:
|
||||
panic("unknown unit")
|
||||
}
|
||||
return int(math.Round(float64(r)))
|
||||
}
|
||||
|
||||
func newWindowRendezvous() *windowRendezvous {
|
||||
wr := &windowRendezvous{
|
||||
in: make(chan windowAndOptions),
|
||||
|
||||
Reference in New Issue
Block a user