widget

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT, Unlicense Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GioCheckable

type GioCheckable struct {
	Label              string
	Color              color.NRGBA
	Font               font_gio.Font
	TextSize           unit_gio.Sp
	IconColor          color.NRGBA
	Size               unit_gio.Dp
	Shaper             *text_gio.Shaper
	CheckedStateIcon   *widget_gio.Icon
	UncheckedStateIcon *widget_gio.Icon
}

func (*GioCheckable) Layout

func (c *GioCheckable) Layout(gtx layout_gio.Context, checked, hovered bool) layout_gio.Dimensions

type GioEditor

type GioEditor struct {

	// Alignment controls the alignment of text within the editor.
	Alignment text.Alignment
	// LineHeight determines the gap between baselines of text. If zero, a sensible
	// default will be used.
	LineHeight unit.Sp
	// LineHeightScale is multiplied by LineHeight to determine the final gap
	// between baselines. If zero, a sensible default will be used.
	LineHeightScale float32
	// SingleLine force the text to stay on a single line.
	// SingleLine also sets the scrolling direction to
	// horizontal.
	SingleLine bool
	// ReadOnly controls whether the contents of the editor can be altered by
	// user interaction. If set to true, the editor will allow selecting text
	// and copying it interactively, but not modifying it.
	ReadOnly bool
	// Submit enabled translation of carriage return keys to SubmitEvents.
	// If not enabled, carriage returns are inserted as newlines in the text.
	Submit bool
	// Mask replaces the visual display of each rune in the contents with the given rune.
	// Newline characters are not masked. When non-zero, the unmasked contents
	// are accessed by Len, Text, and SetText.
	Mask rune
	// InputHint specifies the type of on-screen keyboard to be displayed.
	InputHint key_gio.InputHint
	// MaxLen limits the editor content to a maximum length. Zero means no limit.
	MaxLen int
	// Filter is the list of characters allowed in the Editor. If Filter is empty,
	// all characters are allowed.
	Filter string
	// WrapPolicy configures how displayed text will be broken into lines.
	WrapPolicy text.WrapPolicy
	// contains filtered or unexported fields
}

Editor implements an editable and scrollable text area.

func (*GioEditor) CaretCoords

func (e *GioEditor) CaretCoords() f32.Point

CaretCoords returns the coordinates of the caret, relative to the editor itself.

func (*GioEditor) CaretPos

func (e *GioEditor) CaretPos() (line, col int)

CaretPos returns the line & column numbers of the caret.

func (*GioEditor) ClearSelection

func (e *GioEditor) ClearSelection()

ClearSelection clears the selection, by setting the selection end equal to the selection start.

func (*GioEditor) Delete

func (e *GioEditor) Delete(graphemeClusters int)

Delete runes from the caret position. The sign of the argument specifies the direction to delete: positive is forward, negative is backward.

If there is a selection, it is deleted and counts as a single grapheme cluster.

func (*GioEditor) Focused

func (e *GioEditor) Focused() bool

Focused returns whether the editor is focused or not.

func (*GioEditor) Insert

func (e *GioEditor) Insert(s string)

func (*GioEditor) Layout

func (e *GioEditor) Layout(gtx layout_gio.Context, lt *text.Shaper, font font.Font, size unit.Sp, textMaterial, selectMaterial, cursorMaterial op_gio.CallOp) layout_gio.Dimensions

Layout lays out the editor using the provided textMaterial as the paint material for the text glyphs+caret and the selectMaterial as the paint material for the selection rectangle.

func (*GioEditor) Len

func (e *GioEditor) Len() int

Len is the length of the editor contents, in runes.

func (*GioEditor) MoveCaret

func (e *GioEditor) MoveCaret(startDelta, endDelta int)

MoveCaret moves the caret (aka selection start) and the selection end relative to their current positions. Positive distances moves forward, negative distances moves backward. Distances are in grapheme clusters, which closely match what users perceive as "characters" even when the characters are multiple code points long.

func (*GioEditor) PointerDragged

func (e *GioEditor) PointerDragged(evt pointer_gio.Event)

func (*GioEditor) PointerPressed

func (e *GioEditor) PointerPressed(evt pointer_gio.Event)

func (*GioEditor) PointerReleased

func (e *GioEditor) PointerReleased(evt pointer_gio.Event)

func (*GioEditor) ProcessKey

func (e *GioEditor) ProcessKey(evt key_gio.Event)

func (*GioEditor) Read

func (e *GioEditor) Read(p []byte) (int, error)

Read implements io.Reader.

func (*GioEditor) Regions

func (e *GioEditor) Regions(start, end int, regions []Region) []Region

Regions returns visible regions covering the rune range [start,end).

func (*GioEditor) Seek

func (e *GioEditor) Seek(offset int64, whence int) (int64, error)

Seek implements io.Seeker.

func (*GioEditor) SelectedText

func (e *GioEditor) SelectedText() string

SelectedText returns the currently selected text (if any) from the editor.

func (*GioEditor) Selection

func (e *GioEditor) Selection() (start, end int)

Selection returns the start and end of the selection, as rune offsets. start can be > end.

func (*GioEditor) SelectionLen

func (e *GioEditor) SelectionLen() int

SelectionLen returns the length of the selection, in runes; it is equivalent to utf8.RuneCountInString(e.SelectedText()).

func (*GioEditor) SetCaret

func (e *GioEditor) SetCaret(start, end int)

SetCaret moves the caret to start, and sets the selection end to end. start and end are in runes, and represent offsets into the editor text.

func (*GioEditor) SetFocused

func (e *GioEditor) SetFocused(focus bool)

SetFocused sets the editor focused or not.

func (*GioEditor) SetText

func (e *GioEditor) SetText(s string)

func (*GioEditor) Text

func (e *GioEditor) Text() string

Text returns the contents of the editor.

func (*GioEditor) Update

func (e *GioEditor) Update(gtx layout_gio.Context)

Update the state of the editor in response to input events. Update consumes editor input events until there are no remaining events or an editor event is generated. To fully update the state of the editor, callers should call Update until it returns false.

func (*GioEditor) WriteTo

func (e *GioEditor) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo.

type GioEnum added in v0.0.3

type GioEnum struct {
	Value string
	// contains filtered or unexported fields
}

func (*GioEnum) Focused added in v0.0.3

func (e *GioEnum) Focused() (string, bool)

Focused reports the focused key, or false if no key is focused.

func (*GioEnum) Hovered added in v0.0.3

func (e *GioEnum) Hovered() (string, bool)

Hovered returns the key that is highlighted, or false if none are.

func (*GioEnum) Layout added in v0.0.3

func (e *GioEnum) Layout(gtx layout.Context, k string, content layout.Widget) layout.Dimensions

Layout adds the event handler for the key k.

func (*GioEnum) Update added in v0.0.3

func (e *GioEnum) Update(gtx layout.Context) bool

r Value has changed by user interaction.

type GioFloat added in v0.0.3

type GioFloat struct {
	// Value is the value of the Float, in the [0; 1] range.
	Value float32
	// contains filtered or unexported fields
}

Float is for selecting a value in a range.

func (*GioFloat) Dragging added in v0.0.3

func (f *GioFloat) Dragging() bool

Dragging returns whether the value is being interacted with.

func (*GioFloat) Layout added in v0.0.3

func (f *GioFloat) Layout(gtx layout.Context, axis layout.Axis, pointerMargin unit.Dp) layout.Dimensions

func (*GioFloat) Update added in v0.0.3

func (f *GioFloat) Update(gtx layout.Context) bool

Update the Value according to drag events along the f's main axis. The return value reports whether the value was changed.

The range of f is set by the minimum constraints main axis value.

type GioLabel

type GioLabel struct {
	// Alignment specifies the text alignment.
	Alignment text.Alignment
	// MaxLines limits the number of lines. Zero means no limit.
	MaxLines int
	// Truncator is the text that will be shown at the end of the final
	// line if MaxLines is exceeded. Defaults to "…" if empty.
	Truncator string
	// WrapPolicy configures how displayed text will be broken into lines.
	WrapPolicy text.WrapPolicy
	// LineHeight controls the distance between the baselines of lines of text.
	// If zero, a sensible default will be used.
	LineHeight unit.Sp
	// LineHeightScale applies a scaling factor to the LineHeight. If zero, a
	// sensible default will be used.
	LineHeightScale float32
}

Label is a widget for laying out and drawing text. Labels are always non-interactive text. They cannot be selected or copied.

func (GioLabel) Layout

func (l GioLabel) Layout(gtx layout.Context, lt *text.Shaper, font font.Font, size unit.Sp, txt string, textMaterial op.CallOp) layout.Dimensions

Layout the label with the given shaper, font, size, text, and material.

func (GioLabel) LayoutDetailed

func (l GioLabel) LayoutDetailed(gtx layout.Context, lt *text.Shaper, font font.Font, size unit.Sp, txt string, textMaterial op.CallOp) (layout.Dimensions, TextInfo)

Layout the label with the given shaper, font, size, text, and material, returning metadata about the shaped text.

type GioSelectable

type GioSelectable struct {
	// Alignment controls the alignment of the text.
	Alignment text.Alignment
	// MaxLines is the maximum number of lines of text to be displayed.
	MaxLines int
	// Truncator is the symbol to use at the end of the final line of text
	// if text was cut off. Defaults to "…" if left empty.
	Truncator string
	// WrapPolicy configures how displayed text will be broken into lines.
	WrapPolicy text.WrapPolicy
	// LineHeight controls the distance between the baselines of lines of text.
	// If zero, a sensible default will be used.
	LineHeight unit.Sp
	// LineHeightScale applies a scaling factor to the LineHeight. If zero, a
	// sensible default will be used.
	LineHeightScale float32
	// contains filtered or unexported fields
}

Selectable displays selectable text.

func (*GioSelectable) ClearSelection

func (l *GioSelectable) ClearSelection()

ClearSelection clears the selection, by setting the selection end equal to the selection start.

func (*GioSelectable) Focused

func (l *GioSelectable) Focused() bool

Focused returns whether the label is focused or not.

func (*GioSelectable) Layout

func (l *GioSelectable) Layout(gtx layout.Context, lt *text.Shaper, font font.Font, size unit.Sp, textMaterial, selectionMaterial op.CallOp) layout.Dimensions

Layout clips to the dimensions of the selectable, updates the shaped text, configures input handling, and paints the text and selection rectangles. The provided textMaterial and selectionMaterial ops are used to set the paint material for the text and selection rectangles, respectively.

func (*GioSelectable) PaintSelection

func (l *GioSelectable) PaintSelection(gtx layout.Context, material op.CallOp)

paintSelection paints the contrasting background for selected text.

func (*GioSelectable) PaintText

func (l *GioSelectable) PaintText(gtx layout.Context, material op.CallOp)

paintText paints the text glyphs with the provided material.

func (*GioSelectable) PointerDoubleClicked

func (l *GioSelectable) PointerDoubleClicked(evt pointer_gio.Event)

func (*GioSelectable) PointerDragged

func (l *GioSelectable) PointerDragged(evt pointer_gio.Event)

func (*GioSelectable) PointerPressed

func (l *GioSelectable) PointerPressed(evt pointer_gio.Event)

func (*GioSelectable) PointerReleased

func (l *GioSelectable) PointerReleased(evt pointer_gio.Event)

func (*GioSelectable) Regions

func (l *GioSelectable) Regions(start, end int, regions []Region) []Region

Regions returns visible regions covering the rune range [start,end).

func (*GioSelectable) SelectedText

func (l *GioSelectable) SelectedText() string

SelectedText returns the currently selected text (if any) from the editor.

func (*GioSelectable) Selection

func (l *GioSelectable) Selection() (start, end int)

Selection returns the start and end of the selection, as rune offsets. start can be > end.

func (*GioSelectable) SelectionLen

func (l *GioSelectable) SelectionLen() int

SelectionLen returns the length of the selection, in runes; it is equivalent to utf8.RuneCountInString(e.SelectedText()).

func (*GioSelectable) SetCaret

func (l *GioSelectable) SetCaret(start, end int)

SetCaret moves the caret to start, and sets the selection end to end. start and end are in runes, and represent offsets into the editor text.

func (*GioSelectable) SetFocused

func (l *GioSelectable) SetFocused(focus bool)

SetFocused sets the label focused to true or false.

func (*GioSelectable) SetText

func (l *GioSelectable) SetText(s string)

SetText updates the text to s if it does not already contain s. Updating the text will clear the selection unless the selectable already contains s.

func (*GioSelectable) Text

func (l *GioSelectable) Text() string

Text returns the contents of the label.

func (*GioSelectable) TextView

func (l *GioSelectable) TextView() *GioTextView

Text returns the contents of the label.

func (*GioSelectable) Truncated

func (l *GioSelectable) Truncated() bool

Truncated returns whether the text has been truncated by the text shaper to fit within available constraints.

func (*GioSelectable) Update

func (l *GioSelectable) Update(gtx layout.Context)

Update the state of the selectable in response to input events.

type GioTextView

type GioTextView struct {
	Alignment text.Alignment
	// LineHeight controls the distance between the baselines of lines of text.
	// If zero, a sensible default will be used.
	LineHeight unit.Sp
	// LineHeightScale applies a scaling factor to the LineHeight. If zero, a
	// sensible default will be used.
	LineHeightScale float32
	// SingleLine forces the text to stay on a single line.
	// SingleLine also sets the scrolling direction to
	// horizontal.
	SingleLine bool
	// MaxLines limits the shaped text to a specific quantity of shaped lines.
	MaxLines int
	// Truncator is the text that will be shown at the end of the final
	// line if MaxLines is exceeded. Defaults to "…" if empty.
	Truncator string
	// WrapPolicy configures how displayed text will be broken into lines.
	WrapPolicy text.WrapPolicy
	// Mask replaces the visual display of each rune in the contents with the given rune.
	// Newline characters are not masked. When non-zero, the unmasked contents
	// are accessed by Len, Text, and SetText.
	Mask rune
	// contains filtered or unexported fields
}

textView provides efficient shaping and indexing of interactive text. When provided with a TextSource, textView will shape and cache the runes within that source. It provides methods for configuring a viewport onto the shaped text which can be scrolled, and for configuring and drawing text selection boxes.

func (*GioTextView) ByteOffset

func (e *GioTextView) ByteOffset(runeOffset int) int64

ByteOffset returns the start byte of the rune at the given rune offset, clamped to the size of the text.

func (*GioTextView) CaretCoords

func (e *GioTextView) CaretCoords() f32.Point

CaretCoords returns the coordinates of the caret, relative to the editor itself.

func (*GioTextView) CaretInfo

func (e *GioTextView) CaretInfo() (pos image.Point, ascent, descent int)

func (*GioTextView) CaretPos

func (e *GioTextView) CaretPos() (line, col int)

CaretPos returns the line & column numbers of the caret.

func (*GioTextView) Changed

func (e *GioTextView) Changed() bool

func (*GioTextView) ClearSelection

func (e *GioTextView) ClearSelection()

ClearSelection clears the selection, by setting the selection end equal to the selection start.

func (*GioTextView) Dimensions

func (e *GioTextView) Dimensions() layout.Dimensions

Dimensions returns the dimensions of the visible text.

func (*GioTextView) FullDimensions

func (e *GioTextView) FullDimensions() layout.Dimensions

FullDimensions returns the dimensions of all shaped text, including text that isn't visible within the current viewport.

func (*GioTextView) Layout

func (e *GioTextView) Layout(gtx layout.Context, lt *text.Shaper, font font.Font, size unit.Sp)

Layout the text, reshaping it as necessary.

func (*GioTextView) Len

func (e *GioTextView) Len() int

Len is the length of the editor contents, in runes.

func (*GioTextView) MoveCaret

func (e *GioTextView) MoveCaret(startDelta, endDelta int)

MoveCaret moves the caret (aka selection start) and the selection end relative to their current positions. Positive distances moves forward, negative distances moves backward. Distances are in grapheme clusters which better match the expectations of users than runes.

func (*GioTextView) MoveCoord

func (e *GioTextView) MoveCoord(pos image.Point)

MoveCoord moves the caret to the position closest to the provided point that is aligned to a grapheme cluster boundary.

func (*GioTextView) MoveEnd

func (e *GioTextView) MoveEnd(selAct selectionAction)

MoveEnd moves the caret to the end of the current line, ensuring that the resulting cursor position is on a grapheme cluster boundary.

func (*GioTextView) MoveLines

func (e *GioTextView) MoveLines(distance int, selAct selectionAction)

MaxLines moves the cursor the specified number of lines vertically, ensuring that the resulting position is aligned to a grapheme cluster.

func (*GioTextView) MovePages

func (e *GioTextView) MovePages(pages int, selAct selectionAction)

MovePages moves the caret position by vertical pages of text, ensuring that the final position is aligned to a grapheme cluster boundary.

func (*GioTextView) MoveStart

func (e *GioTextView) MoveStart(selAct selectionAction)

MoveStart moves the caret to the start of the current line, ensuring that the resulting cursor position is on a grapheme cluster boundary.

func (*GioTextView) MoveWord

func (e *GioTextView) MoveWord(distance int, selAct selectionAction)

MoveWord moves the caret to the next word in the specified direction. Positive is forward, negative is backward. Absolute values greater than one will skip that many words. The final caret position will be aligned to a grapheme cluster boundary. BUG(whereswaldon): this method's definition of a "word" is currently whitespace-delimited. Languages that do not use whitespace to delimit words will experience counter-intuitive behavior when navigating by word.

func (*GioTextView) PaintCaret

func (e *GioTextView) PaintCaret(gtx layout.Context, material op.CallOp)

PaintCaret clips and paints the caret rectangle, adding material immediately before painting to set the appropriate paint material.

func (*GioTextView) PaintSelection

func (e *GioTextView) PaintSelection(gtx layout.Context, material op.CallOp)

PaintSelection clips and paints the visible text selection rectangles using the provided material to fill the rectangles.

func (*GioTextView) PaintText

func (e *GioTextView) PaintText(gtx layout.Context, material op.CallOp)

PaintText clips and paints the visible text glyph outlines using the provided material to fill the glyphs.

func (*GioTextView) Read

func (e *GioTextView) Read(p []byte) (int, error)

Read implements io.Reader.

func (*GioTextView) ReadAt

func (e *GioTextView) ReadAt(p []byte, offset int64) (int, error)

ReadAt implements io.ReaderAt.

func (*GioTextView) ReadRuneAt

func (e *GioTextView) ReadRuneAt(off int64) (rune, int, error)

ReadRuneAt reads the rune starting at the given byte offset, if any.

func (*GioTextView) ReadRuneBefore

func (e *GioTextView) ReadRuneBefore(off int64) (rune, int, error)

ReadRuneAt reads the run prior to the given byte offset, if any.

func (*GioTextView) Regions

func (e *GioTextView) Regions(start, end int, regions []Region) []Region

Regions returns visible regions covering the rune range [start,end).

func (*GioTextView) Replace

func (e *GioTextView) Replace(start, end int, s string) int

Replace the text between start and end with s. Indices are in runes. It returns the number of runes inserted.

func (*GioTextView) ScrollBounds

func (e *GioTextView) ScrollBounds() image.Rectangle

func (*GioTextView) ScrollOff

func (e *GioTextView) ScrollOff() image.Point

ScrollOff returns the scroll offset of the text viewport.

func (*GioTextView) ScrollRel

func (e *GioTextView) ScrollRel(dx, dy int)

func (*GioTextView) ScrollToCaret

func (e *GioTextView) ScrollToCaret()

func (*GioTextView) Seek

func (e *GioTextView) Seek(offset int64, whence int) (int64, error)

Seek implements io.Seeker.

func (*GioTextView) SelectedText

func (e *GioTextView) SelectedText(buf []byte) []byte

SelectedText returns the currently selected text (if any) from the editor, filling the provided byte slice if it is large enough or allocating and returning a new byte slice if the provided one is insufficient. Callers can guarantee that the buf is large enough by providing a buffer with capacity e.SelectionLen()*utf8.UTFMax.

func (*GioTextView) Selection

func (e *GioTextView) Selection() (start, end int)

Selection returns the start and end of the selection, as rune offsets. start can be > end.

func (*GioTextView) SelectionLen

func (e *GioTextView) SelectionLen() int

SelectionLen returns the length of the selection, in runes; it is equivalent to utf8.RuneCountInString(e.SelectedText()).

func (*GioTextView) SetCaret

func (e *GioTextView) SetCaret(start, end int)

SetCaret moves the caret to start, and sets the selection end to end. Then the two ends are clamped to the nearest grapheme cluster boundary. start and end are in runes, and represent offsets into the editor text.

func (*GioTextView) SetSource

func (e *GioTextView) SetSource(source textSource)

SetSource initializes the underlying data source for the Text. This must be done before invoking any other methods on Text.

func (*GioTextView) Text

func (e *GioTextView) Text(buf []byte) []byte

Text returns the contents of the editor. If the provided buf is large enough, it will be filled and returned. Otherwise a new buffer will be allocated. Callers can guarantee that buf is large enough by giving it capacity e.Len()*utf8.UTFMax.

func (*GioTextView) Truncated

func (e *GioTextView) Truncated() bool

Truncated returns whether the text in the textView is currently truncated due to a restriction on the number of lines.

func (*GioTextView) WriteTo

func (e *GioTextView) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo.

type Region

type Region struct {
	// Bounds is the coordinates of the bounding box relative to the containing
	// widget.
	Bounds image.Rectangle
	// Baseline is the quantity of vertical pixels between the baseline and
	// the bottom of bounds.
	Baseline int
}

Region describes the position and baseline of an area of interest within shaped text.

type TextInfo

type TextInfo struct {
	// Truncated contains the number of runes of text that are represented by a truncator
	// symbol in the text. If zero, there is no truncator symbol.
	Truncated int
}

TextInfo provides metadata about shaped text.

Notes

Bugs

  • this method's definition of a "word" is currently whitespace-delimited. Languages that do not use whitespace to delimit words will experience counter-intuitive behavior when navigating by word.

Jump to

Keyboard shortcuts

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