diff --git a/ui/app/os_macos.go b/ui/app/os_macos.go index 98c9821a..f7e2b3fb 100644 --- a/ui/app/os_macos.go +++ b/ui/app/os_macos.go @@ -216,8 +216,8 @@ func Main() { } cfg := getConfig() opts := singleWindow.opts - w := cfg.Val(opts.Width) - h := cfg.Val(opts.Height) + w := cfg.Pixels(opts.Width) + h := cfg.Pixels(opts.Height) title := C.CString(opts.Title) defer C.free(unsafe.Pointer(title)) C.gio_main(view, title, C.CGFloat(w), C.CGFloat(h)) diff --git a/ui/app/os_wayland.go b/ui/app/os_wayland.go index f4f6e83f..d796ac1b 100644 --- a/ui/app/os_wayland.go +++ b/ui/app/os_wayland.go @@ -237,8 +237,8 @@ func createNativeWindow(opts *WindowOptions) (*window, error) { C.free(unsafe.Pointer(title)) _, _, cfg := w.config() - w.width = cfg.Val(opts.Width) - w.height = cfg.Val(opts.Height) + w.width = cfg.Pixels(opts.Width) + w.height = cfg.Pixels(opts.Height) if conn.decor != nil { // Request server side decorations. w.decor = C.zxdg_decoration_manager_v1_get_toplevel_decoration(conn.decor, w.topLvl) diff --git a/ui/app/os_windows.go b/ui/app/os_windows.go index ef6ee6df..b0985189 100644 --- a/ui/app/os_windows.go +++ b/ui/app/os_windows.go @@ -220,8 +220,8 @@ func createNativeWindow(opts *WindowOptions) (*window, error) { } defer unregisterClass(cls, hInst) wr := rect{ - right: int32(cfg.Val(opts.Width) + .5), - bottom: int32(cfg.Val(opts.Height) + .5), + right: int32(cfg.Pixels(opts.Width)), + bottom: int32(cfg.Pixels(opts.Height)), } dwStyle := uint32(_WS_OVERLAPPEDWINDOW) dwExStyle := uint32(_WS_EX_APPWINDOW | _WS_EX_WINDOWEDGE) diff --git a/ui/gesture/gestures.go b/ui/gesture/gestures.go index 26e657be..237de5f9 100644 --- a/ui/gesture/gestures.go +++ b/ui/gesture/gestures.go @@ -165,9 +165,9 @@ func (s *Scroll) Scroll(cfg *ui.Config, q input.Events, axis Axis) int { break } fling := s.estimator.Estimate() - if slop, d := float32(cfg.Val(touchSlop)), fling.Distance; d >= slop || -slop >= d { - if min, v := float32(cfg.Val(minFlingVelocity)), fling.Velocity; v >= min || -min >= v { - max := float32(cfg.Val(maxFlingVelocity)) + if slop, d := float32(cfg.Pixels(touchSlop)), fling.Distance; d >= slop || -slop >= d { + if min, v := float32(cfg.Pixels(minFlingVelocity)), fling.Velocity; v >= min || -min >= v { + max := float32(cfg.Pixels(maxFlingVelocity)) if v > max { v = max } else if v < -max { @@ -200,7 +200,7 @@ func (s *Scroll) Scroll(cfg *ui.Config, q input.Events, axis Axis) int { v := int(math.Round(float64(val))) dist := s.last - v if e.Priority < pointer.Grabbed { - slop := cfg.Val(touchSlop) + slop := cfg.Pixels(touchSlop) if dist := dist; dist >= slop || -slop >= dist { s.grab = true } diff --git a/ui/layout/layout.go b/ui/layout/layout.go index 696f8172..aa44ff5d 100644 --- a/ui/layout/layout.go +++ b/ui/layout/layout.go @@ -4,7 +4,6 @@ package layout import ( "image" - "math" "gioui.org/ui" ) @@ -101,10 +100,10 @@ func (in *Insets) Begin(c *ui.Config, ops *ui.Ops, cs Constraints) Constraints { if in.begun { panic("must End before Begin") } - in.top = int(math.Round(float64(c.Val(in.Top)))) - in.right = int(math.Round(float64(c.Val(in.Right)))) - in.bottom = int(math.Round(float64(c.Val(in.Bottom)))) - in.left = int(math.Round(float64(c.Val(in.Left)))) + in.top = c.Pixels(in.Top) + in.right = c.Pixels(in.Right) + in.bottom = c.Pixels(in.Bottom) + in.left = c.Pixels(in.Left) in.begun = true in.ops = ops in.cs = cs diff --git a/ui/measure/measure.go b/ui/measure/measure.go index b1c87223..8bc66083 100644 --- a/ui/measure/measure.go +++ b/ui/measure/measure.go @@ -102,7 +102,7 @@ func (f *Faces) init() { } func (f *textFace) Layout(str string, opts text.LayoutOptions) *text.Layout { - ppem := fixed.Int26_6(f.faces.Config.Val(f.size) * 64) + ppem := fixed.Int26_6(f.faces.Config.Pixels(f.size) * 64) lk := layoutKey{ f: f.font.Font, ppem: ppem, @@ -120,7 +120,7 @@ func (f *textFace) Layout(str string, opts text.LayoutOptions) *text.Layout { } func (f *textFace) Path(str text.String) ui.BlockOp { - ppem := fixed.Int26_6(f.faces.Config.Val(f.size) * 64) + ppem := fixed.Int26_6(f.faces.Config.Pixels(f.size) * 64) pk := pathKey{ f: f.font.Font, ppem: ppem, diff --git a/ui/text/editor.go b/ui/text/editor.go index 2dea373a..d5a30734 100644 --- a/ui/text/editor.go +++ b/ui/text/editor.go @@ -153,7 +153,7 @@ func (e *Editor) Next() (EditorEvent, bool) { } func (e *Editor) caretWidth() fixed.Int26_6 { - oneDp := e.Config.Val(ui.Dp(1)) + oneDp := e.Config.Dp(1) return fixed.Int26_6(oneDp * 64) } @@ -167,7 +167,7 @@ func (e *Editor) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens { break } } - twoDp := e.Config.Val(ui.Dp(2)) + twoDp := e.Config.Dp(2) e.padLeft, e.padRight = twoDp, twoDp maxWidth := cs.Width.Max if e.SingleLine { diff --git a/ui/ui.go b/ui/ui.go index f8fd5c77..b17929c0 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -24,16 +24,16 @@ type Config struct { // Dp converts a value in dp units to pixels. func (c *Config) Dp(dp float32) int { - return c.Val(Dp(dp)) + return c.Pixels(Dp(dp)) } // Sp converts a value in sp units to pixels. func (c *Config) Sp(sp float32) int { - return c.Val(Sp(sp)) + return c.Pixels(Sp(sp)) } -// Val converts a value to pixels. -func (c *Config) Val(v Value) int { +// Pixels converts a value to pixels. +func (c *Config) Pixels(v Value) int { var r float32 switch v.U { case UnitPx: