mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
all: rename package ui to unit
Package ui is now only about units except for the Config.Now method. Remove Now and rename Config to Converter. Add layout.Config to replace the old ui.Config. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+8
-8
@@ -16,7 +16,7 @@ import (
|
||||
"gioui.org/layout"
|
||||
"gioui.org/op"
|
||||
"gioui.org/op/paint"
|
||||
"gioui.org/ui"
|
||||
"gioui.org/unit"
|
||||
|
||||
"golang.org/x/image/math/fixed"
|
||||
)
|
||||
@@ -88,7 +88,7 @@ const (
|
||||
// Event returns the next available editor event, or false if none are available.
|
||||
func (e *Editor) Event(gtx *layout.Context) (EditorEvent, bool) {
|
||||
// Crude configuration change detection.
|
||||
if scale := gtx.Px(ui.Sp(100)); scale != e.oldScale {
|
||||
if scale := gtx.Px(unit.Sp(100)); scale != e.oldScale {
|
||||
e.invalidate()
|
||||
e.oldScale = scale
|
||||
}
|
||||
@@ -102,7 +102,7 @@ func (e *Editor) Event(gtx *layout.Context) (EditorEvent, bool) {
|
||||
axis = gesture.Vertical
|
||||
smin, smax = sbounds.Min.Y, sbounds.Max.Y
|
||||
}
|
||||
sdist := e.scroller.Scroll(gtx.Config, gtx.Queue, axis)
|
||||
sdist := e.scroller.Scroll(gtx.Config, gtx.Queue, gtx.Now(), axis)
|
||||
var soff int
|
||||
if e.SingleLine {
|
||||
e.scrollOff.X += sdist
|
||||
@@ -167,8 +167,8 @@ func (e *Editor) editorEvent(gtx *layout.Context) (EditorEvent, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (e *Editor) caretWidth(c ui.Config) fixed.Int26_6 {
|
||||
oneDp := c.Px(ui.Dp(1))
|
||||
func (e *Editor) caretWidth(c unit.Converter) fixed.Int26_6 {
|
||||
oneDp := c.Px(unit.Dp(1))
|
||||
return fixed.Int26_6(oneDp * 64)
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ func (e *Editor) Layout(gtx *layout.Context) {
|
||||
cs := gtx.Constraints
|
||||
for _, ok := e.Event(gtx); ok; _, ok = e.Event(gtx) {
|
||||
}
|
||||
twoDp := gtx.Px(ui.Dp(2))
|
||||
twoDp := gtx.Px(unit.Dp(2))
|
||||
e.padLeft, e.padRight = twoDp, twoDp
|
||||
maxWidth := cs.Width.Max
|
||||
if e.SingleLine {
|
||||
@@ -275,7 +275,7 @@ func (e *Editor) Layout(gtx *layout.Context) {
|
||||
stack.Pop()
|
||||
|
||||
baseline := e.padTop + e.dims.Baseline
|
||||
pointerPadding := gtx.Px(ui.Dp(4))
|
||||
pointerPadding := gtx.Px(unit.Dp(4))
|
||||
r := image.Rectangle{Max: e.viewSize}
|
||||
r.Min.X -= pointerPadding
|
||||
r.Min.Y -= pointerPadding
|
||||
@@ -563,7 +563,7 @@ func (e *Editor) moveEnd() {
|
||||
e.carXOff = l.Width + a - x
|
||||
}
|
||||
|
||||
func (e *Editor) scrollToCaret(c ui.Config) {
|
||||
func (e *Editor) scrollToCaret(c unit.Converter) {
|
||||
carWidth := e.caretWidth(c)
|
||||
carLine, _, x, y := e.layoutCaret()
|
||||
l := e.lines[carLine]
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"gioui.org/op"
|
||||
"gioui.org/op/paint"
|
||||
"gioui.org/text"
|
||||
"gioui.org/ui"
|
||||
"gioui.org/unit"
|
||||
"golang.org/x/image/font"
|
||||
"golang.org/x/image/font/sfnt"
|
||||
"golang.org/x/image/math/fixed"
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
|
||||
// Faces is a cache of text layouts and paths.
|
||||
type Faces struct {
|
||||
config ui.Config
|
||||
config unit.Converter
|
||||
faceCache map[faceKey]*Face
|
||||
layoutCache map[layoutKey]cachedLayout
|
||||
pathCache map[pathKey]cachedPath
|
||||
@@ -53,19 +53,19 @@ type pathKey struct {
|
||||
|
||||
type faceKey struct {
|
||||
font *sfnt.Font
|
||||
size ui.Value
|
||||
size unit.Value
|
||||
}
|
||||
|
||||
// Face is a cached implementation of text.Face.
|
||||
type Face struct {
|
||||
faces *Faces
|
||||
size ui.Value
|
||||
size unit.Value
|
||||
font *opentype
|
||||
}
|
||||
|
||||
// Reset the cache, discarding any measures or paths that
|
||||
// haven't been used since the last call to Reset.
|
||||
func (f *Faces) Reset(c ui.Config) {
|
||||
func (f *Faces) Reset(c unit.Converter) {
|
||||
f.config = c
|
||||
f.init()
|
||||
for pk, p := range f.pathCache {
|
||||
@@ -87,7 +87,7 @@ func (f *Faces) Reset(c ui.Config) {
|
||||
}
|
||||
|
||||
// For returns a Face for the given font and size.
|
||||
func (f *Faces) For(fnt *sfnt.Font, size ui.Value) *Face {
|
||||
func (f *Faces) For(fnt *sfnt.Font, size unit.Value) *Face {
|
||||
f.init()
|
||||
fk := faceKey{fnt, size}
|
||||
if f, exist := f.faceCache[fk]; exist {
|
||||
|
||||
Reference in New Issue
Block a user