WIP baseline: Termux open-file bridge + word-wrap-aware viewport/scroll

- JNI: open_file_in_termux via ACTION_SEND intent (text/plain + file:// uri),
  global context ref kept from registerFragment
- impl_android.go: OpenFile(path) attaches current thread if needed
- NewLogic takes openfunc; State.open + ui.OpenFile now func(string)
- ChunkedBuffer.VisibleByteRange: word-wrap path using
  GlyphLayout.VisualLineStarts (+byteOffset, lineHeight, visual index param)
- GlyphLayout gains LineHeight; drawWrappedText records VisualLineStarts
- WordWrap default true; State.ByteOffset tracks first visible line
- types: VisualLineIndex
- scroll_fix_test.go (new)
- debug prints left in place (WIP; cleanup in later phase)
This commit is contained in:
gmp
2026-08-16 00:31:26 -04:00
parent def4cec498
commit 7240b62a61
14 changed files with 512 additions and 45 deletions
+1 -1
View File
@@ -713,7 +713,7 @@ func NewGioEditor(id string, region Region, editor *widget.Editor) GioEditor {
// OpenFile is called by the browser list when a file row is tapped.
// Set by the editor package after initialization.
var OpenFile func(any)
var OpenFile func(string)
// Color is an RGBA color.
type Color struct {
+4
View File
@@ -237,6 +237,7 @@ func (r *Renderer) LastLineY() Dp {
// drawWrappedText call. Used by the logic goroutine to position the cursor
// and navigate by glyph instead of byte offset.
func (r *Renderer) GlyphLayout() GlyphLayout {
log.Printf("VisualLineStarts = %v", r.glyphLayout.VisualLineStarts)
return r.glyphLayout
}
@@ -494,7 +495,9 @@ func (r *Renderer) drawWrappedText(gtx layout.Context, str string, reg Region, w
// Capture per-glyph layout data for cursor positioning and navigation.
var layout GlyphLayout
layout.LineHeight = Dp(float32(lineHeightSp))
byteOffset := 0
layout.VisualLineStarts = append(layout.VisualLineStarts,byteOffset)
for g, ok := r.shp.NextGlyph(); ok; g, ok = r.shp.NextGlyph() {
// Record layout data for this glyph.
// g.X is in fixed.Int26_6 — shift >> 6 for device pixels, divide by scale for Dp.
@@ -516,6 +519,7 @@ func (r *Renderer) drawWrappedText(gtx layout.Context, str string, reg Region, w
line = line[:0]
if g.Flags&text.FlagLineBreak != 0 {
lineCount++
layout.VisualLineStarts = append(layout.VisualLineStarts,byteOffset)
}
}
}
+39 -1
View File
@@ -1,6 +1,9 @@
package ui
import "gioui.org/unit"
import (
"gioui.org/unit"
"pad/internal/io/pool/types"
)
// Dp represents device-independent pixels. Use for all element positions,
// sizes, and spacing in the logic/layout layer.
@@ -69,9 +72,44 @@ func FromDp(r Region, scale float32) RegionPx {
// ByteOffsets[i] is the byte position in the buffer, (X[i], Y[i]) is the
// glyph's screen location in Dp (X relative to text region origin, Y is the
// shaper baseline), and Advance[i] is the glyph's width in Dp.
// LineHeight is the shaper's actual baseline-to-baseline line height in Dp,
// derived from consecutive lines' Y values.
type GlyphLayout struct {
ByteOffsets []int // byte offset of each glyph in the buffer
X []Dp // screen X (Dp) of each glyph, relative to text region origin
Y []Dp // screen Y (Dp) baseline of each glyph (shaper value)
Advance []Dp // advance width (Dp) of each glyph
LineHeight Dp // shaper's actual baseline-to-baseline line height in Dp
VisualLineStarts []int // byte offsets where each visual line starts (for word wrap)
VisualLineIndex *types.VisualLineIndex // Optional: pre-computed visual line index for this layout
}
// VisualLineOffsets returns the byte offset of each visual line start.
// Uses pre-captured VisualLineStarts if available, otherwise computes from glyph data.
func (gl GlyphLayout) VisualLineOffsets() []int32 {
if len(gl.VisualLineStarts) > 0 {
// Use pre-captured visual line starts (more accurate for word wrap)
offsets := make([]int32, len(gl.VisualLineStarts))
for i, v := range gl.VisualLineStarts {
offsets[i] = int32(v)
}
return offsets
}
// Fallback: compute from glyph data (less accurate for word wrap)
var offsets []int32
if len(gl.ByteOffsets) == 0 {
return offsets
}
// The first line always starts at byte 0
offsets = append(offsets, int32(gl.ByteOffsets[0]))
// Add byte offset for each new Y coordinate
for i := 1; i < len(gl.Y); i++ {
if gl.Y[i] != gl.Y[i-1] {
offsets = append(offsets, int32(gl.ByteOffsets[i]))
}
}
return offsets
}