Documentation
¶
Index ¶
- type Base
- func (b *Base) ClearInvalid()
- func (c *Base) Draw(ctx *Context, dst *ebiten.Image) image.Rectangle
- func (c *Base) DrawBorder(ctx *Context, dst *ebiten.Image, r image.Rectangle)
- func (c *Base) DrawFocus(ctx *Context, dst *ebiten.Image, r image.Rectangle)
- func (c *Base) DrawInvalid(ctx *Context, dst *ebiten.Image, r image.Rectangle)
- func (c *Base) DrawRoundedBorder(dst *ebiten.Image, r image.Rectangle, radius int, borderW int, col color.RGBA)
- func (c *Base) DrawRoundedRect(dst *ebiten.Image, r image.Rectangle, radius int, col color.RGBA)
- func (c *Base) DrawSurface(ctx *Context, dst *ebiten.Image, r image.Rectangle)
- func (b *Base) ErrorRect() image.Rectangle
- func (b *Base) IsEnabled() bool
- func (b *Base) IsFocused() bool
- func (b *Base) IsHovered() bool
- func (b *Base) IsInvalid() (bool, string)
- func (b *Base) IsPressed() bool
- func (b *Base) IsVisible() bool
- func (b *Base) Measure(extended bool) image.Rectangle
- func (b *Base) SetEnabled(v bool)
- func (b *Base) SetFocused(v bool)
- func (b *Base) SetFrame(x, y, w int)
- func (b *Base) SetHovered(v bool)
- func (b *Base) SetInvalid(err string)
- func (b *Base) SetPressed(v bool)
- func (b *Base) SetVisible(v bool)
- func (c *Base) Theme() *Theme
- type Context
- func (c *Context) Add(w Widget)
- func (c *Context) Draw(dst *ebiten.Image)
- func (c *Context) Focused() Widget
- func (c *Context) IMEBridge() IMEBridge
- func (c *Context) Pointer() PointerStatus
- func (c *Context) Root() Layout
- func (c *Context) SetFocus(w Widget)
- func (c *Context) SetIMEBridge(b IMEBridge)
- func (c *Context) Theme() *Theme
- func (c *Context) Update()
- type Event
- type EventDispatcher
- type EventHandler
- type EventType
- type Hittable
- type IME
- type IMEBridge
- type IMEOptions
- type Layout
- type OverlayWidget
- type PointerStatus
- type ScrollbarMode
- type Scroller
- type TextStyle
- type TextStyles
- type Theme
- type ValidableWidget
- type Widget
- type WidgetBaseConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Base ¶
type Base struct {
EventDispatcher
HeightCalculator func() int
// contains filtered or unexported fields
}
Base contains shared widget state.
func NewBase ¶
func NewBase(cfg *WidgetBaseConfig) Base
func (*Base) ClearInvalid ¶
func (b *Base) ClearInvalid()
func (*Base) DrawBorder ¶
func (*Base) DrawInvalid ¶
func (*Base) DrawRoundedBorder ¶
func (*Base) DrawRoundedRect ¶
func (*Base) DrawSurface ¶
func (*Base) SetEnabled ¶
func (*Base) SetFocused ¶
func (*Base) SetFrame ¶
SetFrame sets the widget position (x,y) and width (w). The final height is computed from the theme and the widget state (e.g. error line, variable-height controls).
func (*Base) SetHovered ¶
func (*Base) SetInvalid ¶
func (*Base) SetPressed ¶
func (*Base) SetVisible ¶
type Context ¶
type Context struct {
// PointerMapper receives a coordinate pair consistent with
// Game.Layout and returns the corresponding offscreen position.
//
// This allows arbitrary pointer projections when the UI has to
// be drawn to an offscreen first and then projected.
PointerMapper func(image.Point) image.Point
// contains filtered or unexported fields
}
Context holds shared state for all widgets.
func (*Context) Pointer ¶
func (c *Context) Pointer() PointerStatus
func (*Context) SetIMEBridge ¶
SetIMEBridge sets/updates the IME bridge at runtime. It also synchronizes the IME visibility with the currently focused widget.
type Event ¶
type Event struct {
Widget Widget
Type EventType
Pointer *PointerStatus
Key ebiten.Key
}
Event is a UI event routed to a widget.
type EventDispatcher ¶
type EventDispatcher struct {
// contains filtered or unexported fields
}
EventDispatcher is a small event router that stores handlers per EventType and dispatches incoming events to them in registration order.
func NewEventDispatcher ¶
func NewEventDispatcher() EventDispatcher
NewEventDispatcher creates and returns a new EventDispatcher with no handlers registered.
func (*EventDispatcher) Dispatch ¶
func (d *EventDispatcher) Dispatch(e Event)
Dispatch sends the given event to all handlers registered for its EventType.
Handlers are invoked sequentially in registration order. If a handler returns true, the event propagation stops immediately.
func (*EventDispatcher) On ¶
func (d *EventDispatcher) On(t EventType, h EventHandler, clear bool)
On registers a new handler for the given event type.
Handlers are executed in the order they are registered. If clear is true, any previously registered handlers for the same type are removed before adding this one.
type EventHandler ¶
EventHandler is a function invoked when an event is dispatched. If it returns true, the event is considered handled and propagation stops.
type EventType ¶
type EventType int
EventType represents high-level UI events dispatched by the UI Context.
These events are intentionally kept generic so they can be used across widgets without depending on platform-specific details.
const ( // EventNone is a zero/default value and should generally not be dispatched. EventNone EventType = iota // EventFocusGained is fired when a widget becomes the focused element. EventFocusGained // EventFocusLost is fired when a widget stops being the focused element. EventFocusLost // EventPointerDown is fired when a pointer (mouse/touch) is pressed down // over a widget. The event carries pointer coordinates in pixels. EventPointerDown // EventPointerUp is fired when a pointer (mouse/touch) is released. // The event carries pointer coordinates in pixels. EventPointerUp // EventClick is fired when a full click/tap gesture is detected // (typically PointerDown followed by PointerUp on the same widget). // The event carries pointer coordinates in pixels. EventClick // EventKeyDown is fired when a keyboard key is pressed while the widget // is focused. The event carries the key code (as int). EventKeyDown // EventKeyUp is fired when a keyboard key is released while the widget // is focused. The event carries the key code (as int). EventKeyUp // EventValueChange is fired when a widget's value changes due to user // interaction (e.g. text changed, checkbox toggled, slider moved, select // changed). EventValueChange )
type IME ¶
type IME interface {
// IME returns the IME's input type and options. Changes to this value
// only take effect when restarting the IME.
IME() IMEOptions
// IMESyncID must change when externally modifying text or cursor
// position. This will restart the IME and flush composition.
IMESyncID() uint64
// IMEFlush is invoked before hiding or restarting the IME, and receives
// any remaining composing text.
IMEFlush(string)
}
IME marks widgets that should trigger IME when focused.
type IMEBridge ¶
type IMEBridge interface {
// Show restarts the IME input and makes it show up if not already visible.
//
// Android values can be derived with [IMEOptions.AndroidParameters]().
Show(inputType, imeOptions int32)
// Hide hides the IME if currently visible.
Hide()
// Composing returns the text in composition. This text is not yet
// committed, so it might suddenly be dropped, completed or converted
// (e.g. kana to kanji). Text should ideally be displayed underlined.
Composing() string
}
IMEBridge is implemented on the Java side and registered from your mobile package.
type IMEOptions ¶
type IMEOptions int32
IMEOptions control the IME input type and options. There are three parts that can be controlled: the keyboard type, the submit/action icon and capitalization. Options can be combined with bitwise ORs:
opts := KeyboardEmail // keyboard includes @ and .com more prominently opts := KeyboardURI | ActionSearch // combine two options opts := KeyboardText | CapSentences // add capitalization opts := KeyboardText | ActionSend | CapsSentences // all options
const ( // keyboard Types KeyboardRaw IMEOptions = 0x000 // no configuration, most compatible with key events KeyboardText IMEOptions = 0x100 KeyboardMultiline IMEOptions = 0x200 KeyboardNumber IMEOptions = 0x300 KeyboardPhone IMEOptions = 0x400 KeyboardEmail IMEOptions = 0x500 KeyboardURI IMEOptions = 0x600 KeyboardPassword IMEOptions = 0x700 // action type, typically affects the icon (defaults to return key) ActionGo IMEOptions = 0x010 ActionSearch IMEOptions = 0x020 ActionSend IMEOptions = 0x030 ActionNext IMEOptions = 0x040 ActionDone IMEOptions = 0x050 // capitalization (defaults to none) CapsSentences IMEOptions = 0x001 CapsWords IMEOptions = 0x002 CapsAll IMEOptions = 0x003 // NoSuggestions is intended only for KeyboardText, // and is ignored by most IMEs in practice. NoSuggestions IMEOptions = 0x1000 // NoPersonalizedLearning enters an "incognito" mode, often // including icons or a color change to reflect it. NoPersonalizedLearning IMEOptions = 0x2000 )
IMEOptions constants.
func (IMEOptions) AndroidParameters ¶
func (o IMEOptions) AndroidParameters() (int32, int32)
AndroidParameters returns the inputType and imeOptions to be sent to IMEBridge.Show().
type Layout ¶
type Layout interface {
Widget
DrawOverlay(ctx *Context, dst *ebiten.Image)
SetHeight(int)
SetPadding(int, int)
Children() []Widget
SetChildren([]Widget)
Add(...Widget)
Clear()
}
Layout is a Widget that owns children.
type OverlayWidget ¶
OverlayWidget can draw an overlay above all other widgets (e.g. Select dropdown).
type PointerStatus ¶
type ScrollbarMode ¶
type ScrollbarMode int
ScrollbarMode controls when the scrollbar is rendered.
const ( ScrollbarNever ScrollbarMode = iota ScrollbarAlways // ScrollbarOnMove shows the bar only while scrolling/dragging, and for a short // time after the last scroll input. ScrollbarOnMove )
type Scroller ¶
type Scroller struct {
ScrollY int
Scrollbar ScrollbarMode
// contains filtered or unexported fields
}
Scroller is a small helper that manages vertical scrolling and a simple scrollbar. It is intentionally simple and relies on clipping via SubImage when drawing.
func NewScroller ¶
func NewScroller() Scroller
func (*Scroller) Clamp ¶
Clamp clamps ScrollY to the valid range for the given viewport height and content height.
func (*Scroller) DrawBar ¶
DrawBar draws a simple vertical scrollbar inside a clipped target (dst should already be a SubImage of the viewport). viewportW/H should match dst's size.
func (*Scroller) IsScrolling ¶
type TextStyle ¶
type TextStyle string
TextStyle identifies a font variant within a theme. Applications may define additional variants, such as "italic" or "narrow".
type TextStyles ¶
TextStyles maps font variants to their faces. Font size is shared by all variants through Theme.FontPx.
type Theme ¶
type Theme struct {
TextStyles TextStyles
FontPx int
ControlH int
PadX int
PadY int
Radius int
BorderW int
FocusRingW int
FocusRingGap int
SpaceS int
SpaceM int
SpaceL int
CheckSize int // checkbox square size
// Validation
ErrorFontPx int
ErrorGap int
// Colors
TextColor color.RGBA
MutedTextColor color.RGBA
BackgroundColor color.RGBA
SurfaceColor color.RGBA
SurfaceHoverColor color.RGBA
SurfacePressedColor color.RGBA
BorderColor color.RGBA
FocusColor color.RGBA
DisabledColor color.RGBA
ErrorTextColor color.RGBA
ErrorBorderColor color.RGBA
Scrollbar color.RGBA
CaretColor color.RGBA
// Scrollbar
ScrollbarRadius int
ScrollbarMinH int
ScrollbarW int
// Caret
CaretWidthPx int
CaretBlink time.Duration
CaretMarginPx int
// contains filtered or unexported fields
}
Theme is the single source of truth for widget proportions. Only the font and font size are inputs; everything else derives from them.
func DefaultTheme ¶
func DefaultTheme() *Theme
type ValidableWidget ¶
type Widget ¶
type Widget interface {
SetFrame(x, y, w int)
IsHovered() bool
SetHovered(bool)
IsPressed() bool
SetPressed(bool)
IsFocused() bool
SetFocused(bool)
IsEnabled() bool
SetEnabled(bool)
IsVisible() bool
SetVisible(bool)
Focusable() bool
Measure(bool) image.Rectangle
Update(ctx *Context)
Draw(ctx *Context, dst *ebiten.Image)
On(t EventType, cb EventHandler, clear bool)
Dispatch(e Event)
}
type WidgetBaseConfig ¶
type WidgetBaseConfig struct {
Theme *Theme
DrawSurface bool
DrawBorder bool
DrawFocus bool
DrawInvalid bool
}
func NewWidgetBaseConfig ¶
func NewWidgetBaseConfig(theme *Theme) *WidgetBaseConfig