guigui

package module
v0.0.0-...-19e92d7 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

README

Guigui (ぐいぐい)

An immediate-mode-like GUI framework for Go

[!CAUTION] This project is an alpha version, and everything may change in the future.

[!WARNING] Except for minor changes like typo fixes, we have not yet established a development policy for accepting changes. For new features, please file an issue or make your proposal in Discussion.

  • Pure Go implementation without any use of HTML, CSS, or JavaScript
  • Hi-DPI support for clear visuals on modern displays
  • Built-in internationalization (I18N) support for multiple languages
  • Efficient rendering with optimized draw calls for better performance
Light Mode Dark Mode
Light Mode Dark Mode
git clone https://github.com/guigui-gui/guigui.git
cd guigui
go run ./example/gallery

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DispatchEvent

func DispatchEvent(widget Widget, eventKey EventKey, args ...any)

func OnFocusChanged

func OnFocusChanged(widget Widget, onfocus func(context *Context, focused bool))

TODO: For focus delegation, create a new function (#340).

func RequestRebuild

func RequestRebuild(widget Widget)

func RequestRedraw

func RequestRedraw(widget Widget)

func Run

func Run(root Widget, options *RunOptions) error

func RunWithCustomFunc

func RunWithCustomFunc(root Widget, options *RunOptions, f func(game ebiten.Game, options *ebiten.RunGameOptions) error) error

func SetEventHandler

func SetEventHandler(widget Widget, eventKey EventKey, handler any)

Types

type ChildAdder

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

func (*ChildAdder) AddWidget

func (c *ChildAdder) AddWidget(widget Widget)

TODO: Rename this to AddWidget.

type ChildLayouter

type ChildLayouter struct {
}

func (*ChildLayouter) LayoutWidget

func (c *ChildLayouter) LayoutWidget(widget Widget, bounds image.Rectangle)

type Constraints

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

func FixedHeightConstraints

func FixedHeightConstraints(h int) Constraints

func FixedWidthConstraints

func FixedWidthConstraints(w int) Constraints

func (*Constraints) FixedHeight

func (c *Constraints) FixedHeight() (int, bool)

func (*Constraints) FixedWidth

func (c *Constraints) FixedWidth() (int, bool)

type Context

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

func (*Context) AppBounds

func (c *Context) AppBounds() image.Rectangle

func (*Context) AppScale

func (c *Context) AppScale() float64

func (*Context) AppendAppLocales

func (c *Context) AppendAppLocales(locales []language.Tag) []language.Tag

func (*Context) AppendLocales

func (c *Context) AppendLocales(locales []language.Tag) []language.Tag

func (*Context) ColorMode

func (c *Context) ColorMode() ebiten.ColorMode

ColorMode returns the color mode set by SetColorMode.

ColorMode might return ebiten.ColorModeUnknown if the color mode is not set.

func (*Context) Data

func (c *Context) Data(widget Widget, key DataKey) any

func (*Context) DelegateFocus

func (c *Context) DelegateFocus(widget Widget, delegate Widget)

DelegateFocus delegates the focus to another widget.

func (*Context) DeviceScale

func (c *Context) DeviceScale() float64

func (*Context) IsEnabled

func (c *Context) IsEnabled(widget Widget) bool

func (*Context) IsFocused

func (c *Context) IsFocused(widget Widget) bool

func (*Context) IsFocusedOrHasFocusedChild

func (c *Context) IsFocusedOrHasFocusedChild(widget Widget) bool

func (*Context) IsVisible

func (c *Context) IsVisible(widget Widget) bool

func (*Context) Opacity

func (c *Context) Opacity(widget Widget) float64

func (*Context) Passthrough

func (c *Context) Passthrough(widget Widget) bool

func (*Context) ResolvedColorMode

func (c *Context) ResolvedColorMode() ebiten.ColorMode

ResolvedColorMode returns the color mode.

ResolvedColorMode never returns ebiten.ColorModeUnknown.

func (*Context) Scale

func (c *Context) Scale() float64

func (*Context) SetAppLocales

func (c *Context) SetAppLocales(locales []language.Tag)

func (*Context) SetAppScale

func (c *Context) SetAppScale(scale float64)

func (*Context) SetClipChildren

func (c *Context) SetClipChildren(widget Widget, clip bool)

SetClipChildren sets whether the children on the same layer are clipped by the widget's bounds. The default value is false.

If the child widget is on a different layer from the parent, it is not clipped. Note that a widget layer can be controlled by LayerWidget.

func (*Context) SetColorMode

func (c *Context) SetColorMode(mode ebiten.ColorMode)

SetColorMode sets the color mode.

If mode is ebiten.ColorModeUnknown, SetColorMode specifies the default system color mode.

func (*Context) SetEnabled

func (c *Context) SetEnabled(widget Widget, enabled bool)

func (*Context) SetFocused

func (c *Context) SetFocused(widget Widget, focused bool)

func (*Context) SetOpacity

func (c *Context) SetOpacity(widget Widget, opacity float64)

func (*Context) SetPassthrough

func (c *Context) SetPassthrough(widget Widget, passthrough bool)

func (*Context) SetVisible

func (c *Context) SetVisible(widget Widget, visible bool)

func (*Context) SetWindowTitle

func (c *Context) SetWindowTitle(title string)

type DataKey

type DataKey uniqueKey

DataKey is a unique identifier for a model.

func GenerateDataKey

func GenerateDataKey() DataKey

GenerateDataKey generates a new DataKey.

type DefaultWidget

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

func (*DefaultWidget) Build

func (*DefaultWidget) Build(context *Context, adder *ChildAdder) error

func (*DefaultWidget) CursorShape

func (*DefaultWidget) CursorShape(context *Context, widgetBounds *WidgetBounds) (ebiten.CursorShapeType, bool)

func (*DefaultWidget) Data

func (*DefaultWidget) Data(context *Context, key DataKey) any

func (*DefaultWidget) Draw

func (*DefaultWidget) Draw(context *Context, widgetBounds *WidgetBounds, dst *ebiten.Image)

func (*DefaultWidget) HandleButtonInput

func (*DefaultWidget) HandleButtonInput(context *Context, widgetBounds *WidgetBounds) HandleInputResult

func (*DefaultWidget) HandlePointingInput

func (*DefaultWidget) HandlePointingInput(context *Context, widgetBounds *WidgetBounds) HandleInputResult

func (*DefaultWidget) Layout

func (*DefaultWidget) Layout(context *Context, widgetBounds *WidgetBounds, layouter *ChildLayouter)

func (*DefaultWidget) Measure

func (d *DefaultWidget) Measure(context *Context, constraints Constraints) image.Point

func (*DefaultWidget) Tick

func (*DefaultWidget) Tick(context *Context, widgetBounds *WidgetBounds) error

type EventKey

type EventKey uniqueKey

EventKey is a unique identifier for an event.

func GenerateEventKey

func GenerateEventKey() EventKey

GenerateEventKey generates a new EventKey.

type HandleInputResult

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

func AbortHandlingInputByWidget

func AbortHandlingInputByWidget(widget Widget) HandleInputResult

func HandleInputByWidget

func HandleInputByWidget(widget Widget) HandleInputResult

type LayerWidget

type LayerWidget[T Widget] struct {
	DefaultWidget
	// contains filtered or unexported fields
}

LayerWidget is a widget that can be in a different layer from its parent. LayerWidget is on the same layer as its parent by default.

func (*LayerWidget[T]) BringToFrontLayer

func (l *LayerWidget[T]) BringToFrontLayer(context *Context)

BringToFrontLayer brings the widget to the front layer. After this call, the widget will be in a different layer from its parent.

Lyaers affect the order of rendering and input handling. Usually, a widget's visible bounds are constrained by its parent's visible bounds, which means a widget cannot be rendered outside of its parent's visible bounds. If a widget is in a different layer from its parent, the widget can be rendered regardless of its parent's visible bounds.

Input is handled in the order of layers from top to bottom. Also, layers affect the result of [WidgetBounds.IsCursorHitAt].

func (*LayerWidget[T]) Build

func (l *LayerWidget[T]) Build(context *Context, adder *ChildAdder) error

Build implements [Widget.Build].

func (*LayerWidget[T]) Layout

func (l *LayerWidget[T]) Layout(context *Context, widgetBounds *WidgetBounds, layouter *ChildLayouter)

Layout implements [Widget.Layout].

func (*LayerWidget[T]) Measure

func (l *LayerWidget[T]) Measure(context *Context, constraints Constraints) image.Point

Measure implements [Widget.Measure].

func (*LayerWidget[T]) Widget

func (l *LayerWidget[T]) Widget() T

Widget returns the content widget.

type LayoutDirection

type LayoutDirection int

LayoutDirection is the direction of the layout.

const (
	// LayoutDirectionHorizontal arranges widgets horizontally.
	LayoutDirectionHorizontal LayoutDirection = iota
	// LayoutDirectionVertical arranges widgets vertically.
	LayoutDirectionVertical
)

type LinearLayout

type LinearLayout struct {
	// Direction is the direction of the layout.
	Direction LayoutDirection

	// Items is the list of items to layout.
	Items []LinearLayoutItem

	// Gap is the gap in pixels between items.
	Gap int

	// Padding is the padding around the layout.
	Padding Padding
}

LinearLayout arranges widgets in a linear fashion.

func (LinearLayout) AppendItemBounds

func (l LinearLayout) AppendItemBounds(boundsArr []image.Rectangle, context *Context, bounds image.Rectangle) []image.Rectangle

func (LinearLayout) LayoutWidgets

func (l LinearLayout) LayoutWidgets(context *Context, bounds image.Rectangle, layouter WidgetLayouter)

func (LinearLayout) Measure

func (l LinearLayout) Measure(context *Context, constraints Constraints) image.Point

type LinearLayoutItem

type LinearLayoutItem struct {
	Widget Widget
	Size   Size
	Layout WidgetsLayouter
}

type Padding

type Padding struct {
	// Start is the padding in pixels at the start (left for LTR, right for RTL) of the layout.
	//
	// TODO: Support LTR/RTL.
	Start int

	// Top is the padding in pixels at the top of the layout.
	Top int

	// End is the padding in pixels at the end (right for LTR, left for RTL) of the layout.
	//
	// TODO: Support LTR/RTL.
	End int

	// Bottom is the padding in pixels at the bottom of the layout.
	Bottom int
}

Padding represents the padding around a layout.

type RunOptions

type RunOptions struct {
	Title          string
	WindowSize     image.Point
	WindowMinSize  image.Point
	WindowMaxSize  image.Point
	WindowFloating bool
	AppScale       float64

	RunGameOptions *ebiten.RunGameOptions
}

type Size

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

Size represents the size of a layout item.

func FixedSize

func FixedSize(value int) Size

FixedSize represents a fixed size in pixels.

func FlexibleSize

func FlexibleSize(value int) Size

FlexibleSize represents a flexible size. The size is distributed proportionally to the values of the flexible items.

type Widget

type Widget interface {
	Data(context *Context, key DataKey) any
	Build(context *Context, adder *ChildAdder) error
	Layout(context *Context, widgetBounds *WidgetBounds, layouter *ChildLayouter)
	HandlePointingInput(context *Context, widgetBounds *WidgetBounds) HandleInputResult
	HandleButtonInput(context *Context, widgetBounds *WidgetBounds) HandleInputResult
	Tick(context *Context, widgetBounds *WidgetBounds) error
	CursorShape(context *Context, widgetBounds *WidgetBounds) (ebiten.CursorShapeType, bool)
	Draw(context *Context, widgetBounds *WidgetBounds, dst *ebiten.Image)
	Measure(context *Context, constraints Constraints) image.Point
	// contains filtered or unexported methods
}

type WidgetBounds

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

func (*WidgetBounds) Bounds

func (w *WidgetBounds) Bounds() image.Rectangle

func (*WidgetBounds) IsHitAtCursor

func (w *WidgetBounds) IsHitAtCursor() bool

func (*WidgetBounds) VisibleBounds

func (w *WidgetBounds) VisibleBounds() image.Rectangle

type WidgetLayouter

type WidgetLayouter interface {
	// LayoutWidget lays out the given widget in the given bounds.
	LayoutWidget(widget Widget, bounds image.Rectangle)
}

WidgetLayouter is an interface for laying out a single widget.

type WidgetSlice

type WidgetSlice[T Widget] struct {
	// contains filtered or unexported fields
}

WidgetSlice is a collection of widgets.

As Widget implementation (DefaultWidget) must not be copied by value, a plain slice of widgets is very risky to use. Use this instead.

func (*WidgetSlice[T]) At

func (w *WidgetSlice[T]) At(index int) T

At returns the widget at the specified index.

func (*WidgetSlice[T]) Len

func (w *WidgetSlice[T]) Len() int

Len returns the number of widgets.

func (*WidgetSlice[T]) SetLen

func (w *WidgetSlice[T]) SetLen(l int)

SetLen sets the length of the slice.

If the length is increased, the new elements are zero-cleared values. The existing elements are kept.

If the length is decreased, the elements are dropped. The remaining elements are kept.

type WidgetWithPadding

type WidgetWithPadding[T Widget] struct {
	DefaultWidget
	// contains filtered or unexported fields
}

func (*WidgetWithPadding[T]) Build

func (w *WidgetWithPadding[T]) Build(context *Context, adder *ChildAdder) error

func (*WidgetWithPadding[T]) Layout

func (w *WidgetWithPadding[T]) Layout(context *Context, widgetBounds *WidgetBounds, layouter *ChildLayouter)

func (*WidgetWithPadding[T]) Measure

func (w *WidgetWithPadding[T]) Measure(context *Context, constraints Constraints) image.Point

func (*WidgetWithPadding[T]) SetPadding

func (w *WidgetWithPadding[T]) SetPadding(padding Padding)

func (*WidgetWithPadding[T]) Widget

func (w *WidgetWithPadding[T]) Widget() T

type WidgetWithSize

type WidgetWithSize[T Widget] struct {
	DefaultWidget
	// contains filtered or unexported fields
}

func (*WidgetWithSize[T]) Build

func (w *WidgetWithSize[T]) Build(context *Context, adder *ChildAdder) error

func (*WidgetWithSize[T]) Layout

func (w *WidgetWithSize[T]) Layout(context *Context, widgetBounds *WidgetBounds, layouter *ChildLayouter)

func (*WidgetWithSize[T]) Measure

func (w *WidgetWithSize[T]) Measure(context *Context, constraints Constraints) image.Point

func (*WidgetWithSize[T]) SetFixedHeight

func (w *WidgetWithSize[T]) SetFixedHeight(height int)

func (*WidgetWithSize[T]) SetFixedSize

func (w *WidgetWithSize[T]) SetFixedSize(size image.Point)

func (*WidgetWithSize[T]) SetFixedWidth

func (w *WidgetWithSize[T]) SetFixedWidth(width int)

func (*WidgetWithSize[T]) SetIntrinsicSize

func (w *WidgetWithSize[T]) SetIntrinsicSize()

func (*WidgetWithSize[T]) SetMeasureFunc

func (w *WidgetWithSize[T]) SetMeasureFunc(f func(context *Context, constraints Constraints) image.Point)

func (*WidgetWithSize[T]) Widget

func (w *WidgetWithSize[T]) Widget() T

type WidgetsLayouter

type WidgetsLayouter interface {
	// LayoutWidgets lays out the given widgets in the given bounds.
	LayoutWidgets(context *Context, bounds image.Rectangle, layouter WidgetLayouter)

	// Measure measures the size of the layout.
	Measure(context *Context, constraints Constraints) image.Point
}

WidgetsLayouter is an interface for laying out multiple widgets.

Directories

Path Synopsis
example
counter command
drawer command
expander command
gallery command
gridlayout command
panels command
todo command
internal
vettool command

Jump to

Keyboard shortcuts

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