widget

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT, Unlicense Imports: 34 Imported by: 2 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var WordSeparator func(rune) bool

WordSeparator, when non-nil, defines the rune class treated as word boundaries by double-click selection in Editor and Selectable.

Functions

This section is empty.

Types

type Bool

type Bool struct {
	Value bool
	// contains filtered or unexported fields
}

func (*Bool) History

func (b *Bool) History() []Press

func (*Bool) Hovered

func (b *Bool) Hovered() bool

func (*Bool) Layout

func (b *Bool) Layout(gtx layout.Context, w layout.Widget) layout.Dimensions

func (*Bool) Pressed

func (b *Bool) Pressed() bool

func (*Bool) Update

func (b *Bool) Update(gtx layout.Context) bool

type Border

type Border struct {
	Color        color.NRGBA
	CornerRadius unit.Dp
	Width        unit.Dp
}

func (Border) Layout

func (b Border) Layout(gtx layout.Context, w layout.Widget) layout.Dimensions

type ChangeEvent

type ChangeEvent struct{}

type Click

type Click struct {
	Modifiers key.Modifiers
	NumClicks int
}

type Clickable

type Clickable struct {
	// contains filtered or unexported fields
}
Example (Passthrough)
package main

import (
	"fmt"
	"image"

	"github.com/nanorele/gio/f32"
	"github.com/nanorele/gio/io/input"
	"github.com/nanorele/gio/io/pointer"
	"github.com/nanorele/gio/layout"
	"github.com/nanorele/gio/op"
	"github.com/nanorele/gio/widget"
)

func main() {

	var button1, button2 widget.Clickable
	var r input.Router
	gtx := layout.Context{
		Ops:         new(op.Ops),
		Constraints: layout.Exact(image.Pt(100, 100)),
		Source:      r.Source(),
	}

	widget := func() {
		content := func(gtx layout.Context) layout.Dimensions { return layout.Dimensions{Size: gtx.Constraints.Min} }
		button1.Layout(gtx, content)

		defer pointer.PassOp{}.Push(gtx.Ops).Pop()
		button2.Layout(gtx, content)
	}

	widget()
	r.Frame(gtx.Ops)

	r.Queue(
		pointer.Event{
			Source:   pointer.Mouse,
			Buttons:  pointer.ButtonPrimary,
			Kind:     pointer.Press,
			Position: f32.Pt(50, 50),
		},
		pointer.Event{
			Source:   pointer.Mouse,
			Buttons:  pointer.ButtonPrimary,
			Kind:     pointer.Release,
			Position: f32.Pt(50, 50),
		},
	)

	if button1.Clicked(gtx) {
		fmt.Println("button1 clicked!")
	}
	if button2.Clicked(gtx) {
		fmt.Println("button2 clicked!")
	}

}

func (*Clickable) Click

func (b *Clickable) Click()

func (*Clickable) Clicked

func (b *Clickable) Clicked(gtx layout.Context) bool

func (*Clickable) History

func (b *Clickable) History() []Press

func (*Clickable) Hovered

func (b *Clickable) Hovered() bool

func (*Clickable) Layout

func (*Clickable) Pressed

func (b *Clickable) Pressed() bool

func (*Clickable) Update

func (b *Clickable) Update(gtx layout.Context) (Click, bool)

type Decorations

type Decorations struct {
	Maximized bool
	// contains filtered or unexported fields
}

func (*Decorations) Clickable

func (d *Decorations) Clickable(action system.Action) *Clickable

func (*Decorations) LayoutMove

func (d *Decorations) LayoutMove(gtx layout.Context, w layout.Widget) layout.Dimensions

func (*Decorations) Update

func (d *Decorations) Update(gtx layout.Context) system.Action

type Draggable

type Draggable struct {
	Type string
	// contains filtered or unexported fields
}

func (*Draggable) Dragging

func (d *Draggable) Dragging() bool

func (*Draggable) Layout

func (d *Draggable) Layout(gtx layout.Context, w, drag layout.Widget) layout.Dimensions
Example
package main

import (
	"fmt"
	"image"
	"io"
	"strings"

	"github.com/nanorele/gio/f32"
	"github.com/nanorele/gio/io/event"
	"github.com/nanorele/gio/io/input"
	"github.com/nanorele/gio/io/pointer"
	"github.com/nanorele/gio/io/transfer"
	"github.com/nanorele/gio/layout"
	"github.com/nanorele/gio/op"
	"github.com/nanorele/gio/op/clip"
	"github.com/nanorele/gio/widget"
)

func main() {
	var r input.Router
	gtx := layout.Context{
		Ops:         new(op.Ops),
		Constraints: layout.Exact(image.Pt(100, 100)),
		Source:      r.Source(),
	}

	const mime = "MyMime"
	drag := &widget.Draggable{Type: mime}
	var drop int

	widget := func() {

		w := func(gtx layout.Context) layout.Dimensions {
			sz := image.Pt(10, 10)
			return layout.Dimensions{Size: sz}
		}
		drag.Layout(gtx, w, w)

		if m, ok := drag.Update(gtx); ok {
			drag.Offer(gtx, m, io.NopCloser(strings.NewReader("hello world")))
		}

		ds := clip.Rect{
			Min: image.Pt(20, 20),
			Max: image.Pt(40, 40),
		}.Push(gtx.Ops)
		event.Op(gtx.Ops, &drop)
		ds.Pop()

		for {
			ev, ok := gtx.Event(transfer.TargetFilter{Target: &drop, Type: mime})
			if !ok {
				break
			}
			switch e := ev.(type) {
			case transfer.DataEvent:
				data := e.Open()
				defer data.Close() //nolint:errcheck // Example code; close error not actionable.
				content, _ := io.ReadAll(data)
				fmt.Println(string(content))
			}
		}
	}

	widget()
	r.Frame(gtx.Ops)

	r.Queue(
		pointer.Event{
			Kind:     pointer.Press,
			Position: f32.Pt(5, 5),
		},
		pointer.Event{
			Kind:     pointer.Move,
			Position: f32.Pt(5, 5),
		},
		pointer.Event{
			Kind:     pointer.Release,
			Position: f32.Pt(30, 30),
		},
	)

	widget()
	r.Frame(gtx.Ops)

	widget()

}

func (*Draggable) Offer

func (d *Draggable) Offer(gtx layout.Context, mime string, data io.ReadCloser)

func (*Draggable) Pos

func (d *Draggable) Pos() f32.Point

func (*Draggable) Update

func (d *Draggable) Update(gtx layout.Context) (mime string, requested bool)

type Editor

type Editor struct {
	Alignment text.Alignment

	LineHeight unit.Sp

	LineHeightScale float32

	SingleLine bool

	ReadOnly bool

	Submit bool

	Mask rune

	InputHint key.InputHint

	MaxLen int

	Filter string

	WrapPolicy text.WrapPolicy
	// contains filtered or unexported fields
}

func (*Editor) CaretCoords

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

func (*Editor) CaretPos

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

func (*Editor) ClearSelection

func (e *Editor) ClearSelection()

func (*Editor) Delete

func (e *Editor) Delete(graphemeClusters int) (deletedRunes int)

func (*Editor) GetScrollBounds

func (e *Editor) GetScrollBounds() image.Rectangle

func (*Editor) GetScrollX

func (e *Editor) GetScrollX() int

func (*Editor) GetScrollY

func (e *Editor) GetScrollY() int

func (*Editor) Insert

func (e *Editor) Insert(s string) (insertedRunes int)

func (*Editor) Layout

func (e *Editor) Layout(gtx layout.Context, lt *text.Shaper, font font.Font, size unit.Sp, textMaterial, selectMaterial op.CallOp) layout.Dimensions

func (*Editor) Len

func (e *Editor) Len() int

func (*Editor) MoveCaret

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

func (*Editor) Read

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

func (*Editor) Regions

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

func (*Editor) Revision added in v1.4.0

func (e *Editor) Revision() uint64

Revision changes whenever the editor's text does. Callers deriving state from Text can key a cache on it instead of reading the text back — Text allocates a copy of the whole content on every call.

func (*Editor) Seek

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

func (*Editor) SelectedText

func (e *Editor) SelectedText() string

func (*Editor) Selection

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

func (*Editor) SelectionLen

func (e *Editor) SelectionLen() int

func (*Editor) SetCaret

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

func (*Editor) SetScrollCaret added in v1.0.11

func (e *Editor) SetScrollCaret(b bool)

func (*Editor) SetScrollY

func (e *Editor) SetScrollY(y int)

func (*Editor) SetText

func (e *Editor) SetText(s string)

func (*Editor) Text

func (e *Editor) Text() string

func (*Editor) TextEqual added in v1.4.0

func (e *Editor) TextEqual(s string) bool

TextEqual reports whether the editor's content equals s. It compares in place — no copy of the content is made, and nothing is allocated.

func (*Editor) TextInto added in v1.4.0

func (e *Editor) TextInto(dst []byte) []byte

TextInto appends the editor's content to dst and returns the extended slice. Unlike Text it does not materialize a string, so with a reused dst reading the content allocates nothing. Combine with Editor.Revision to skip even the copy while the content is unchanged.

func (*Editor) Update

func (e *Editor) Update(gtx layout.Context) (EditorEvent, bool)

func (*Editor) WriteTo

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

type EditorEvent

type EditorEvent interface {
	// contains filtered or unexported methods
}

type Enum

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

func (*Enum) Focused

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

func (*Enum) Hovered

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

func (*Enum) Layout

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

func (*Enum) Update

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

type Fit

type Fit uint8
const (
	Unscaled Fit = iota

	Contain

	Cover

	ScaleDown

	Fill
)

type Float

type Float struct {
	Value float32
	// contains filtered or unexported fields
}

func (*Float) Dragging

func (f *Float) Dragging() bool

func (*Float) Layout

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

func (*Float) Update

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

type Icon

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

func NewIcon

func NewIcon(data []byte) (*Icon, error)

func (*Icon) Layout

func (ic *Icon) Layout(gtx layout.Context, color color.NRGBA) layout.Dimensions

type Image

type Image struct {
	Src paint.ImageOp

	Fit Fit

	Position layout.Direction

	Scale float32
}

func (Image) Layout

func (im Image) Layout(gtx layout.Context) layout.Dimensions

type Label

type Label struct {
	Alignment text.Alignment

	MaxLines int

	Truncator string

	WrapPolicy text.WrapPolicy

	LineHeight unit.Sp

	LineHeightScale float32
}

func (Label) Layout

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

func (Label) LayoutDetailed

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

type List

type List struct {
	Scrollbar
	layout.List
}

type Press

type Press struct {
	Position image.Point

	Start time.Time

	End time.Time

	Cancelled bool
}

type Region

type Region struct {
	Bounds image.Rectangle

	Baseline int
}

type Scrollbar

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

func (*Scrollbar) AddDrag

func (s *Scrollbar) AddDrag(ops *op.Ops)

func (*Scrollbar) AddIndicator

func (s *Scrollbar) AddIndicator(ops *op.Ops)

func (*Scrollbar) AddTrack

func (s *Scrollbar) AddTrack(ops *op.Ops)

func (*Scrollbar) Dragging

func (s *Scrollbar) Dragging() bool

func (*Scrollbar) IndicatorHovered

func (s *Scrollbar) IndicatorHovered() bool

func (*Scrollbar) ScrollDistance

func (s *Scrollbar) ScrollDistance() float32

func (*Scrollbar) TrackHovered

func (s *Scrollbar) TrackHovered() bool

func (*Scrollbar) Update

func (s *Scrollbar) Update(gtx layout.Context, axis layout.Axis, viewportStart, viewportEnd float32)

type SelectEvent

type SelectEvent struct{}

type Selectable

type Selectable struct {
	Alignment text.Alignment

	MaxLines int

	Truncator string

	WrapPolicy text.WrapPolicy

	LineHeight unit.Sp

	LineHeightScale float32
	// contains filtered or unexported fields
}

func (*Selectable) ClearSelection

func (l *Selectable) ClearSelection()

func (*Selectable) Focused

func (l *Selectable) Focused() bool

func (*Selectable) Layout

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

func (*Selectable) Regions

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

func (*Selectable) SelectedText

func (l *Selectable) SelectedText() string

func (*Selectable) Selection

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

func (*Selectable) SelectionLen

func (l *Selectable) SelectionLen() int

func (*Selectable) SetCaret

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

func (*Selectable) SetText

func (l *Selectable) SetText(s string)

func (*Selectable) Text

func (l *Selectable) Text() string

func (*Selectable) Truncated

func (l *Selectable) Truncated() bool

func (*Selectable) Update

func (l *Selectable) Update(gtx layout.Context) bool

type SubmitEvent

type SubmitEvent struct {
	Text string
}

type TextInfo

type TextInfo struct {
	Truncated int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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