editorstyle

package
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 19 Imported by: 0

README

ui/internal/editorstyle

English | 简体中文

ui/el Drawing of the input box: Draw the selection background and cursor according to the visible glyph, keeping the cursor aligned with the placeholder text. Input events, selection ranges, scrolling, undo, and input methods are still handled by Gio's Editor.

  • Dependencies: Gio, Go standard image and time library, golang.org/x/image/math/fixed; does not depend on other Keel modules.
  • Used by: ui/el (the input box of kit is used by el).

Caret.Layout is only responsible for drawing; the caller must process Editor.Update first. The test covers both editing interaction and 1× / 2× actual rendered pixels.

The selection follows the horizontal range and baseline of Editor.Regions, and then calculates the height according to the glyph range. When drawing, first record the original editor operation, draw the selection background, and then play back the text; you cannot modify the selection by moving the text as a whole. For positioning steps, see Troubleshooting text and selection alignment.

Composition draws a combined underline using Regions typed by the editor and returns the combined range within the viewport; Caret.InputMethodCaret provides a baseline and glyph height consistent with the visible cursor. The input adaptation layer that consumes input method events by itself is called after Layout and is responsible for sending these coordinates to the platform. This internal layer does not maintain editing transactions.

InlineFont Constructs a whitespace font containing only private characters for a quoted block. The glyph's advance participates in Gio Editor's line wrapping, selection and cursor calculations, and the UI can draw additional content in the corresponding Regions. Fonts are only added to the shaper of a single editor and are not registered globally; the caller is responsible for selecting private characters that do not conflict with normal text, measuring widths, and layout caching. Input/Textarea reference typesetting has been connected; outlineless glyphs retain non-zero boundaries to prevent line endings from being ignored as whitespace.

Fonts are constructed in OpenType cmap format 12 and hmtx, including sfnt checksum; normal characters must fall back to normal fonts. The existing go-text uses signed advance, and the design unit limit for a single glyph is 32767; the caller needs to select UnitsPerEm according to the font size and maximum width, and should not directly use dp as the design unit.

Documentation

Overview

Package editorstyle supplies the shared input appearance for widget and el.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Composition

func Composition(g layout.Context, ed *widget.Editor, r key.Range, ink color.NRGBA) image.Rectangle

Composition paints the composing text's underline and returns its visible bounds in editor coordinates for the platform candidate window. Adapters that consume CompositionEvent themselves must call this after editor layout.

func InlineFont

func InlineFont(name font.Typeface, metrics InlineFontMetrics, glyphs []InlineGlyph) (font.FontFace, error)

InlineFont creates an owned, outline-free font containing only the supplied private-use runes. Include it ahead of normal text fonts in an editor-local shaper. Never register this font globally: rune mappings are document-local. Glyphs need not be sorted; duplicate/non-private runes and invalid metrics fail.

Types

type Caret

type Caret struct {
	// contains filtered or unexported fields
}

Caret retains blink, caret and selection ink measurements for one editor.

func (*Caret) InputMethodCaret

func (c *Caret) InputMethodCaret(ed *widget.Editor) key.Caret

InputMethodCaret uses the same ink metrics and baseline as the visible caret. Call after Layout, when the editor's scrolled geometry and font metrics exist.

func (*Caret) Layout

func (c *Caret) Layout(gtx layout.Context, style material.EditorStyle, shaper *text.Shaper) layout.Dimensions

Layout draws an editor with ink-height selection and caret at Gio's actual coordinates. The caller MUST drain Editor.Update first, handling its change and submit events. Gio 0.10 has no separate caret paint hook: ReadOnly is set only during drawing to suppress its font-line-height caret, then restored. Input, selection, scrolling, undo and IME still belong to the original Editor.

func (*Caret) LayoutDecorated

func (c *Caret) LayoutDecorated(gtx layout.Context, style material.EditorStyle, shaper *text.Shaper, decorate func(layout.Context)) layout.Dimensions

LayoutDecorated adds editor-coordinate backgrounds after text layout and before selection and glyph painting. The decoration must not change layout.

type InlineFontMetrics

type InlineFontMetrics struct {
	UnitsPerEm      uint16 // 16..16384
	Ascent, Descent int16  // positive distances above/below the baseline
}

type InlineGlyph

type InlineGlyph struct {
	Rune    rune
	Advance uint16 // font design units, at most 32767 for go-text's signed metrics
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL