ui: use ints for unit conversions to pixels

The dp and sp units are approximate and mostly used for layout
dimensions that operate in whole pixels. This change alters the
Config methods to return pixels in ints instead of floats, which
results in smoother use for layout and emphasize the inexactness of
the device independent units.

Clients can still access to raw PxPrDp and PxPrSp factors from
Config.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-07-10 13:23:20 +02:00
parent bde04c68a2
commit ad4215a7eb
6 changed files with 26 additions and 22 deletions
+2 -2
View File
@@ -153,7 +153,7 @@ func (e *Editor) Next() (EditorEvent, bool) {
}
func (e *Editor) caretWidth() fixed.Int26_6 {
oneDp := int(e.Config.Val(ui.Dp(1)) + .5)
oneDp := e.Config.Val(ui.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 := int(e.Config.Val(ui.Dp(2)) + 0.5)
twoDp := e.Config.Val(ui.Dp(2))
e.padLeft, e.padRight = twoDp, twoDp
maxWidth := cs.Width.Max
if e.SingleLine {