Redesign selection handles (teardrop + 48dp grab); place menu above selection
- Handles are now teardrops (stem + filled circle) like the native Android selector: 20dp circle normally, 28dp while dragging. - The grab region is a 48dp box around the circle centre, independent of the visual size; the old 16dp target was not grabbable by finger. - The copy/cut/paste menu is placed ABOVE the selected line (native behaviour), flipping below only when there is no room above. The menu is drawn last (top of the z-order) and Gio routes a touch to the topmost op whose clip contains it, so a below-placed menu covered the handles' grab boxes and silently stole every handle-drag press. - Regressions: menu above-placement arithmetic, first-line flip-below, and the existing tracking/clamp tests updated for the new policy. - On-device verified: handle drags work with the menu up (previously dead lower grab region), first-line handles still grabbable from the uncovered top strip, menu taps and tap-to-clear unchanged. - doc/development_plan.md section 15 records the z-order/placement contract.
This commit is contained in:
+58
-17
@@ -120,18 +120,23 @@ type Renderer struct {
|
||||
selDragsOn [4]bool
|
||||
selDragEmitting [4]bool
|
||||
selDragHandler func(any)
|
||||
// selDraggingWhich is which handle drag (0-3) is currently in flight
|
||||
// (-1 = none), set by CheckGestures and read by drawWrappedText to
|
||||
// enlarge the grabbed handle, as the framework does while dragging.
|
||||
selDraggingWhich int
|
||||
}
|
||||
|
||||
// New creates a new Renderer.
|
||||
func New(th Theme, shp *text.Shaper) *Renderer {
|
||||
r := &Renderer{
|
||||
theme: th,
|
||||
shp: shp,
|
||||
icons: make(map[string]image.Image),
|
||||
clicks: make(map[string]*clickReg),
|
||||
Keys: make(map[string]keyReg),
|
||||
scrolls: make(map[string]scrollReg),
|
||||
gioEditors: make(map[string]*widget.Editor),
|
||||
theme: th,
|
||||
shp: shp,
|
||||
icons: make(map[string]image.Image),
|
||||
clicks: make(map[string]*clickReg),
|
||||
Keys: make(map[string]keyReg),
|
||||
scrolls: make(map[string]scrollReg),
|
||||
gioEditors: make(map[string]*widget.Editor),
|
||||
selDraggingWhich: -1,
|
||||
}
|
||||
r.loadIcons()
|
||||
return r
|
||||
@@ -350,6 +355,7 @@ func (r *Renderer) CheckGestures(q input.Source, m unit.Metric) []InputEvent {
|
||||
switch e.Kind {
|
||||
case pointer.Drag:
|
||||
r.selDragEmitting[which] = true
|
||||
r.selDraggingWhich = which
|
||||
events = append(events, InputEvent{
|
||||
Handler: r.selDragHandler,
|
||||
Data: SelectionDragEvent{Which: which, X: r.toDp(Px(e.Position.X)), Y: r.toDp(Px(e.Position.Y))},
|
||||
@@ -362,6 +368,9 @@ func (r *Renderer) CheckGestures(q input.Source, m unit.Metric) []InputEvent {
|
||||
})
|
||||
}
|
||||
r.selDragEmitting[which] = false
|
||||
if r.selDraggingWhich == which {
|
||||
r.selDraggingWhich = -1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -820,10 +829,20 @@ func (r *Renderer) drawWrappedText(gtx layout.Context, str string, reg Region, w
|
||||
n := len(layout.X) - 1
|
||||
return reg.X + layout.X[n] + layout.Advance[n], reg.Y - scrollOffset + layout.Y[n] - ascent
|
||||
}
|
||||
// The visual handle (drawHandle) is a ~20dp teardrop centred at
|
||||
// (hx, hy+lineH+handleRadius); the GRAB region is a 48dp box around
|
||||
// that centre — Android's own handles are small but their touch
|
||||
// targets are not (framework slop + 48dp minimum touch target), and
|
||||
// 16dp was far too small to grab reliably by finger.
|
||||
const handleRadius = Dp(10)
|
||||
registerDrag := func(d *gesture.Drag, hx, hy Dp) {
|
||||
cy := hy + lineH + handleRadius
|
||||
const grab = Dp(24) // 48dp box
|
||||
minx, miny := int(r.toPx(hx-grab)), int(r.toPx(cy-grab))
|
||||
maxx, maxy := int(r.toPx(hx+grab)), int(r.toPx(cy+grab))
|
||||
hc := clip.Rect{
|
||||
Min: image.Point{X: int(r.toPx(hx - 8)), Y: int(r.toPx(hy - 6))},
|
||||
Max: image.Point{X: int(r.toPx(hx + 8)), Y: int(r.toPx(hy + lineH + 6))},
|
||||
Min: image.Point{X: minx, Y: miny},
|
||||
Max: image.Point{X: maxx, Y: maxy},
|
||||
}.Push(gtx.Ops)
|
||||
d.Add(gtx.Ops)
|
||||
hc.Pop()
|
||||
@@ -879,14 +898,14 @@ func (r *Renderer) drawWrappedText(gtx layout.Context, str string, reg Region, w
|
||||
bc.Pop()
|
||||
r.selDragsOn[2] = true
|
||||
}
|
||||
r.drawHandle(gtx, sx, sy, lineH)
|
||||
r.drawHandle(gtx, ex, ey, lineH)
|
||||
r.drawHandle(gtx, sx, sy, lineH, r.selDraggingWhich == 0)
|
||||
r.drawHandle(gtx, ex, ey, lineH, r.selDraggingWhich == 1)
|
||||
} else {
|
||||
// Caret drag (long press on blank space): a single handle on the caret.
|
||||
cx, cy := handleAt(cursorPos)
|
||||
registerDrag(&r.selDragCaret, cx, cy)
|
||||
r.selDragsOn[3] = true
|
||||
r.drawHandle(gtx, cx, cy, lineH)
|
||||
r.drawHandle(gtx, cx, cy, lineH, r.selDraggingWhich == 3)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -899,12 +918,34 @@ func (r *Renderer) drawWrappedText(gtx layout.Context, str string, reg Region, w
|
||||
}
|
||||
}
|
||||
|
||||
// drawHandle draws a selection handle: a short vertical stem with a filled
|
||||
// square foot at the line's bottom (v1 approximation of Android's circle).
|
||||
func (r *Renderer) drawHandle(gtx layout.Context, x, y, lineH Dp) {
|
||||
// drawHandle draws a selection handle mimicking the native Android
|
||||
// teardrop: a filled circle below the line with a short stem reaching up
|
||||
// toward the line, in the system selection blue. (x, y) is the insertion
|
||||
// point at the top of the line, as returned by handleAt. While the handle
|
||||
// is being dragged it is drawn enlarged, as the framework does.
|
||||
func (r *Renderer) drawHandle(gtx layout.Context, x, y, lineH Dp, dragging bool) {
|
||||
col := Color{R: 51, G: 153, B: 255, A: 255}
|
||||
r.drawBg(gtx, Region{X: x - 1, Y: y, W: 2, H: lineH}, col)
|
||||
r.drawBg(gtx, Region{X: x - 5, Y: y + lineH - 2, W: 10, H: 10}, col)
|
||||
radius, stemW, stemLen := Dp(10), Dp(3), Dp(12)
|
||||
if dragging {
|
||||
radius, stemW, stemLen = Dp(13), Dp(4), Dp(15)
|
||||
}
|
||||
// Stem: from just below the line's bottom up into the line, meeting the
|
||||
// top of the circle (2dp overlap avoids a seam between the two shapes).
|
||||
circleTop := y + lineH
|
||||
r.drawBg(gtx, Region{X: x - stemW/2, Y: circleTop - stemLen, W: stemW, H: stemLen + 2}, col)
|
||||
r.drawCircle(gtx, x, circleTop+radius, radius, col)
|
||||
}
|
||||
|
||||
// drawCircle draws a filled circle of radius r centred at (cx, cy), as a
|
||||
// square RRect clip with all corner radii at half the side.
|
||||
func (r *Renderer) drawCircle(gtx layout.Context, cx, cy, rad Dp, col Color) {
|
||||
rr := clip.UniformRRect(image.Rectangle{
|
||||
Min: image.Point{X: int(r.toPx(cx - rad)), Y: int(r.toPx(cy - rad))},
|
||||
Max: image.Point{X: int(r.toPx(cx + rad)), Y: int(r.toPx(cy + rad))},
|
||||
}, int(r.toPx(rad))).Push(gtx.Ops)
|
||||
paint.ColorOp{Color: color.NRGBA{R: col.R, G: col.G, B: col.B, A: col.A}}.Add(gtx.Ops)
|
||||
paint.PaintOp{}.Add(gtx.Ops)
|
||||
rr.Pop()
|
||||
}
|
||||
|
||||
func (r *Renderer) drawPng(gtx layout.Context, img image.Image, reg Region, width, height Dp) {
|
||||
|
||||
Reference in New Issue
Block a user