ui: rename Config.Val to Pixels

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-07-10 13:59:09 +02:00
parent e3ba84758c
commit 320579814f
8 changed files with 22 additions and 23 deletions
+2 -2
View File
@@ -216,8 +216,8 @@ func Main() {
} }
cfg := getConfig() cfg := getConfig()
opts := singleWindow.opts opts := singleWindow.opts
w := cfg.Val(opts.Width) w := cfg.Pixels(opts.Width)
h := cfg.Val(opts.Height) h := cfg.Pixels(opts.Height)
title := C.CString(opts.Title) title := C.CString(opts.Title)
defer C.free(unsafe.Pointer(title)) defer C.free(unsafe.Pointer(title))
C.gio_main(view, title, C.CGFloat(w), C.CGFloat(h)) C.gio_main(view, title, C.CGFloat(w), C.CGFloat(h))
+2 -2
View File
@@ -237,8 +237,8 @@ func createNativeWindow(opts *WindowOptions) (*window, error) {
C.free(unsafe.Pointer(title)) C.free(unsafe.Pointer(title))
_, _, cfg := w.config() _, _, cfg := w.config()
w.width = cfg.Val(opts.Width) w.width = cfg.Pixels(opts.Width)
w.height = cfg.Val(opts.Height) w.height = cfg.Pixels(opts.Height)
if conn.decor != nil { if conn.decor != nil {
// Request server side decorations. // Request server side decorations.
w.decor = C.zxdg_decoration_manager_v1_get_toplevel_decoration(conn.decor, w.topLvl) w.decor = C.zxdg_decoration_manager_v1_get_toplevel_decoration(conn.decor, w.topLvl)
+2 -2
View File
@@ -220,8 +220,8 @@ func createNativeWindow(opts *WindowOptions) (*window, error) {
} }
defer unregisterClass(cls, hInst) defer unregisterClass(cls, hInst)
wr := rect{ wr := rect{
right: int32(cfg.Val(opts.Width) + .5), right: int32(cfg.Pixels(opts.Width)),
bottom: int32(cfg.Val(opts.Height) + .5), bottom: int32(cfg.Pixels(opts.Height)),
} }
dwStyle := uint32(_WS_OVERLAPPEDWINDOW) dwStyle := uint32(_WS_OVERLAPPEDWINDOW)
dwExStyle := uint32(_WS_EX_APPWINDOW | _WS_EX_WINDOWEDGE) dwExStyle := uint32(_WS_EX_APPWINDOW | _WS_EX_WINDOWEDGE)
+4 -4
View File
@@ -165,9 +165,9 @@ func (s *Scroll) Scroll(cfg *ui.Config, q input.Events, axis Axis) int {
break break
} }
fling := s.estimator.Estimate() fling := s.estimator.Estimate()
if slop, d := float32(cfg.Val(touchSlop)), fling.Distance; d >= slop || -slop >= d { if slop, d := float32(cfg.Pixels(touchSlop)), fling.Distance; d >= slop || -slop >= d {
if min, v := float32(cfg.Val(minFlingVelocity)), fling.Velocity; v >= min || -min >= v { if min, v := float32(cfg.Pixels(minFlingVelocity)), fling.Velocity; v >= min || -min >= v {
max := float32(cfg.Val(maxFlingVelocity)) max := float32(cfg.Pixels(maxFlingVelocity))
if v > max { if v > max {
v = max v = max
} else if 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))) v := int(math.Round(float64(val)))
dist := s.last - v dist := s.last - v
if e.Priority < pointer.Grabbed { if e.Priority < pointer.Grabbed {
slop := cfg.Val(touchSlop) slop := cfg.Pixels(touchSlop)
if dist := dist; dist >= slop || -slop >= dist { if dist := dist; dist >= slop || -slop >= dist {
s.grab = true s.grab = true
} }
+4 -5
View File
@@ -4,7 +4,6 @@ package layout
import ( import (
"image" "image"
"math"
"gioui.org/ui" "gioui.org/ui"
) )
@@ -101,10 +100,10 @@ func (in *Insets) Begin(c *ui.Config, ops *ui.Ops, cs Constraints) Constraints {
if in.begun { if in.begun {
panic("must End before Begin") panic("must End before Begin")
} }
in.top = int(math.Round(float64(c.Val(in.Top)))) in.top = c.Pixels(in.Top)
in.right = int(math.Round(float64(c.Val(in.Right)))) in.right = c.Pixels(in.Right)
in.bottom = int(math.Round(float64(c.Val(in.Bottom)))) in.bottom = c.Pixels(in.Bottom)
in.left = int(math.Round(float64(c.Val(in.Left)))) in.left = c.Pixels(in.Left)
in.begun = true in.begun = true
in.ops = ops in.ops = ops
in.cs = cs in.cs = cs
+2 -2
View File
@@ -102,7 +102,7 @@ func (f *Faces) init() {
} }
func (f *textFace) Layout(str string, opts text.LayoutOptions) *text.Layout { 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{ lk := layoutKey{
f: f.font.Font, f: f.font.Font,
ppem: ppem, 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 { 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{ pk := pathKey{
f: f.font.Font, f: f.font.Font,
ppem: ppem, ppem: ppem,
+2 -2
View File
@@ -153,7 +153,7 @@ func (e *Editor) Next() (EditorEvent, bool) {
} }
func (e *Editor) caretWidth() fixed.Int26_6 { 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) return fixed.Int26_6(oneDp * 64)
} }
@@ -167,7 +167,7 @@ func (e *Editor) Layout(ops *ui.Ops, cs layout.Constraints) layout.Dimens {
break break
} }
} }
twoDp := e.Config.Val(ui.Dp(2)) twoDp := e.Config.Dp(2)
e.padLeft, e.padRight = twoDp, twoDp e.padLeft, e.padRight = twoDp, twoDp
maxWidth := cs.Width.Max maxWidth := cs.Width.Max
if e.SingleLine { if e.SingleLine {
+4 -4
View File
@@ -24,16 +24,16 @@ type Config struct {
// Dp converts a value in dp units to pixels. // Dp converts a value in dp units to pixels.
func (c *Config) Dp(dp float32) int { 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. // Sp converts a value in sp units to pixels.
func (c *Config) Sp(sp float32) int { func (c *Config) Sp(sp float32) int {
return c.Val(Sp(sp)) return c.Pixels(Sp(sp))
} }
// Val converts a value to pixels. // Pixels converts a value to pixels.
func (c *Config) Val(v Value) int { func (c *Config) Pixels(v Value) int {
var r float32 var r float32
switch v.U { switch v.U {
case UnitPx: case UnitPx: