Documentation
¶
Index ¶
- func DispatchEvent(widget Widget, eventKey EventKey, args ...any)
- func OnFocusChanged(widget Widget, onfocus func(context *Context, focused bool))
- func RequestRebuild(widget Widget)
- func RequestRedraw(widget Widget)
- func Run(root Widget, options *RunOptions) error
- func RunWithCustomFunc(root Widget, options *RunOptions, ...) error
- func SetEventHandler(widget Widget, eventKey EventKey, handler any)
- type ChildAdder
- type ChildLayouter
- type Constraints
- type Context
- func (c *Context) AppBounds() image.Rectangle
- func (c *Context) AppScale() float64
- func (c *Context) AppendAppLocales(locales []language.Tag) []language.Tag
- func (c *Context) AppendLocales(locales []language.Tag) []language.Tag
- func (c *Context) ColorMode() ebiten.ColorMode
- func (c *Context) Data(widget Widget, key DataKey) any
- func (c *Context) DelegateFocus(widget Widget, delegate Widget)
- func (c *Context) DeviceScale() float64
- func (c *Context) IsEnabled(widget Widget) bool
- func (c *Context) IsFocused(widget Widget) bool
- func (c *Context) IsFocusedOrHasFocusedChild(widget Widget) bool
- func (c *Context) IsVisible(widget Widget) bool
- func (c *Context) Opacity(widget Widget) float64
- func (c *Context) Passthrough(widget Widget) bool
- func (c *Context) ResolvedColorMode() ebiten.ColorMode
- func (c *Context) Scale() float64
- func (c *Context) SetAppLocales(locales []language.Tag)
- func (c *Context) SetAppScale(scale float64)
- func (c *Context) SetClipChildren(widget Widget, clip bool)
- func (c *Context) SetColorMode(mode ebiten.ColorMode)
- func (c *Context) SetEnabled(widget Widget, enabled bool)
- func (c *Context) SetFocused(widget Widget, focused bool)
- func (c *Context) SetOpacity(widget Widget, opacity float64)
- func (c *Context) SetPassthrough(widget Widget, passthrough bool)
- func (c *Context) SetVisible(widget Widget, visible bool)
- func (c *Context) SetWindowTitle(title string)
- type DataKey
- type DefaultWidget
- func (*DefaultWidget) Build(context *Context, adder *ChildAdder) error
- func (*DefaultWidget) CursorShape(context *Context, widgetBounds *WidgetBounds) (ebiten.CursorShapeType, bool)
- func (*DefaultWidget) Data(context *Context, key DataKey) any
- func (*DefaultWidget) Draw(context *Context, widgetBounds *WidgetBounds, dst *ebiten.Image)
- func (*DefaultWidget) HandleButtonInput(context *Context, widgetBounds *WidgetBounds) HandleInputResult
- func (*DefaultWidget) HandlePointingInput(context *Context, widgetBounds *WidgetBounds) HandleInputResult
- func (*DefaultWidget) Layout(context *Context, widgetBounds *WidgetBounds, layouter *ChildLayouter)
- func (d *DefaultWidget) Measure(context *Context, constraints Constraints) image.Point
- func (*DefaultWidget) Tick(context *Context, widgetBounds *WidgetBounds) error
- type EventKey
- type HandleInputResult
- type LayerWidget
- func (l *LayerWidget[T]) BringToFrontLayer(context *Context)
- func (l *LayerWidget[T]) Build(context *Context, adder *ChildAdder) error
- func (l *LayerWidget[T]) Layout(context *Context, widgetBounds *WidgetBounds, layouter *ChildLayouter)
- func (l *LayerWidget[T]) Measure(context *Context, constraints Constraints) image.Point
- func (l *LayerWidget[T]) Widget() T
- type LayoutDirection
- type LinearLayout
- func (l LinearLayout) AppendItemBounds(boundsArr []image.Rectangle, context *Context, bounds image.Rectangle) []image.Rectangle
- func (l LinearLayout) LayoutWidgets(context *Context, bounds image.Rectangle, layouter WidgetLayouter)
- func (l LinearLayout) Measure(context *Context, constraints Constraints) image.Point
- type LinearLayoutItem
- type Padding
- type RunOptions
- type Size
- type Widget
- type WidgetBounds
- type WidgetLayouter
- type WidgetSlice
- type WidgetWithPadding
- func (w *WidgetWithPadding[T]) Build(context *Context, adder *ChildAdder) error
- func (w *WidgetWithPadding[T]) Layout(context *Context, widgetBounds *WidgetBounds, layouter *ChildLayouter)
- func (w *WidgetWithPadding[T]) Measure(context *Context, constraints Constraints) image.Point
- func (w *WidgetWithPadding[T]) SetPadding(padding Padding)
- func (w *WidgetWithPadding[T]) Widget() T
- type WidgetWithSize
- func (w *WidgetWithSize[T]) Build(context *Context, adder *ChildAdder) error
- func (w *WidgetWithSize[T]) Layout(context *Context, widgetBounds *WidgetBounds, layouter *ChildLayouter)
- func (w *WidgetWithSize[T]) Measure(context *Context, constraints Constraints) image.Point
- func (w *WidgetWithSize[T]) SetFixedHeight(height int)
- func (w *WidgetWithSize[T]) SetFixedSize(size image.Point)
- func (w *WidgetWithSize[T]) SetFixedWidth(width int)
- func (w *WidgetWithSize[T]) SetIntrinsicSize()
- func (w *WidgetWithSize[T]) SetMeasureFunc(f func(context *Context, constraints Constraints) image.Point)
- func (w *WidgetWithSize[T]) Widget() T
- type WidgetsLayouter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DispatchEvent ¶
func OnFocusChanged ¶
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 ¶
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) AppendAppLocales ¶
func (*Context) AppendLocales ¶
func (*Context) ColorMode ¶
ColorMode returns the color mode set by SetColorMode.
ColorMode might return ebiten.ColorModeUnknown if the color mode is not set.
func (*Context) DelegateFocus ¶
DelegateFocus delegates the focus to another widget.
func (*Context) DeviceScale ¶
func (*Context) IsFocusedOrHasFocusedChild ¶
func (*Context) Passthrough ¶
func (*Context) ResolvedColorMode ¶
ResolvedColorMode returns the color mode.
ResolvedColorMode never returns ebiten.ColorModeUnknown.
func (*Context) SetAppLocales ¶
func (*Context) SetAppScale ¶
func (*Context) SetClipChildren ¶
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 ¶
SetColorMode sets the color mode.
If mode is ebiten.ColorModeUnknown, SetColorMode specifies the default system color mode.
func (*Context) SetEnabled ¶
func (*Context) SetFocused ¶
func (*Context) SetOpacity ¶
func (*Context) SetPassthrough ¶
func (*Context) SetVisible ¶
func (*Context) SetWindowTitle ¶
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) 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 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 (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 Size ¶
type Size struct {
// contains filtered or unexported fields
}
Size represents the size of a layout item.
func FlexibleSize ¶
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]) 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.

