mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 23:55:39 +00:00
ui: rename Config.Val to Pixels
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+2
-2
@@ -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))
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
+4
-5
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
+2
-2
@@ -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 {
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user