Documentation
¶
Overview ¶
Package minigui is a tiny immediate-mode GUI toolkit for Ebitengine. Each frame the caller builds an Input, runs Begin, calls widgets, then End; widgets process input and append draw commands that Render flushes. Keeping the logic separate from rendering makes the toolkit testable without a window and keeps a consistent look across the host application.
Index ¶
- Variables
- type Context
- func (c *Context) Begin(in Input, x, y float64)
- func (c *Context) BeginPanel(title string, x, y float64)
- func (c *Context) BeginWindow(w *Window) bool
- func (c *Context) Button(id ID, label string) bool
- func (c *Context) ClearFocus()
- func (c *Context) Dragging() bool
- func (c *Context) End()
- func (c *Context) EndPanel() image.Rectangle
- func (c *Context) EndWindow() image.Rectangle
- func (c *Context) Focus(id ID)
- func (c *Context) HasFocus() bool
- func (c *Context) Label(s string)
- func (c *Context) List(id ID, items []string, selected *int) bool
- func (c *Context) ListWithIcons(id ID, items []string, selected *int, iconPx float64) (changed bool, clicked int, icons []IconSlot)
- func (c *Context) Render(dst *ebiten.Image)
- func (c *Context) SameLine()
- func (c *Context) SetFace(f Face)
- func (c *Context) SetItemWidth(w float64)
- func (c *Context) SetStyle(s Style)
- func (c *Context) Slider(id ID, val *float64, lo, hi float64) bool
- func (c *Context) Style() Style
- func (c *Context) Submitted(id ID) bool
- func (c *Context) Swatch(id ID, col color.RGBA, selected bool) bool
- func (c *Context) TextArea(id ID, s *string, rows int) bool
- func (c *Context) TextField(id ID, s *string) bool
- func (c *Context) Toggle(id ID, label string, on bool) bool
- type Face
- type ID
- type IconSlot
- type Input
- type Style
- type Window
Constants ¶
This section is empty.
Variables ¶
var VGAPalette = []string{
"#000000", "#0000aa", "#00aa00", "#00aaaa",
"#aa0000", "#aa00aa", "#aa5500", "#aaaaaa",
"#555555", "#5555ff", "#55ff55", "#55ffff",
"#ff5555", "#ff55ff", "#ffff55", "#ffffff",
}
VGAPalette is the classic 16-color IBM VGA text palette, as hex strings. It is offered as a convenient default for the color pickers callers build with Swatch; the palette lives here so there is one source of truth for it.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context holds immediate-mode state that persists across frames (focus, caret) plus this frame's input, layout cursor and draw-command buffer.
func (*Context) BeginPanel ¶
BeginPanel starts a titled panel at (x, y): a fixed background box with a title bar that frames the widgets drawn until EndPanel, like a small simulated window. The box is sized automatically to its content. Panels do not nest. For a movable, closable window backed by caller state, use BeginWindow.
func (*Context) BeginWindow ¶
BeginWindow starts the window w. It returns false when w is closed (w.Open is false): skip its contents and do not call EndWindow. When it returns true, draw widgets and call EndWindow.
func (*Context) Button ¶
Button draws a clickable button and reports whether it was clicked this frame.
func (*Context) ClearFocus ¶
func (c *Context) ClearFocus()
ClearFocus drops keyboard focus, e.g. when the panel owning the field is hidden.
func (*Context) Dragging ¶
Dragging reports whether a window is currently being dragged, so a click-through host can keep grabbing the mouse until the drag ends, even if the cursor briefly outruns the title bar.
func (*Context) End ¶
func (c *Context) End()
End finishes the frame, clearing focus when the click missed every field.
func (*Context) EndPanel ¶
EndPanel finishes the panel and returns its screen rectangle, useful for hit-testing the whole panel (e.g. to keep it interactive in a click-through overlay).
func (*Context) EndWindow ¶
EndWindow finishes the current window: it draws the close box, handles dragging the title bar and clicking the close box (mutating the caller's Window), and returns the window's screen rectangle.
func (*Context) Focus ¶
Focus gives keyboard focus to the field with the given id, e.g. to focus a text field as soon as its window opens, with the caret at the start of the text. It marks the click as handled so End does not clear the focus on the same frame as the click that triggered the focusing.
func (*Context) HasFocus ¶
HasFocus reports whether a text field owns keyboard input, so the caller can suspend single-key shortcuts while the user types.
func (*Context) List ¶
List draws a scrollable, selectable list bound to *selected (the chosen index) and reports whether the selection changed this frame. Click an item to select it; scroll the wheel while hovering to move through a longer list.
func (*Context) ListWithIcons ¶
func (c *Context) ListWithIcons(id ID, items []string, selected *int, iconPx float64) (changed bool, clicked int, icons []IconSlot)
ListWithIcons behaves like List but reserves a square icon column of iconPx on the left of each row, insetting the text. It also returns the index clicked this frame (-1 if none, even when it equals the current selection, so callers can detect double-clicks) and the icon rect of each visible row so the caller can draw into it after Render; the slices/values are valid until the next frame.
func (*Context) SameLine ¶
func (c *Context) SameLine()
SameLine places the next widget to the right of the one just drawn, on the same row, instead of on a new line below it.
func (*Context) SetFace ¶
SetFace sets the text face used to measure and draw widget labels, leaving the rest of the style untouched. Pass nil to fall back to Ebitengine's built-in debug font (a fixed 6x16 cell, ASCII only). A real face also lets non-Latin text (e.g. Japanese) render. It persists across frames.
func (*Context) SetItemWidth ¶
SetItemWidth fixes the width of subsequent buttons and toggles so a column of them can share one size (0 sizes each to its text). Reset every frame by Begin.
func (*Context) SetStyle ¶
SetStyle sets the colors, metrics and face used to draw widgets. Start from DefaultStyle and override what you need. It persists across frames.
func (*Context) Slider ¶ added in v0.1.6
Slider draws a horizontal draggable track that edits *val within [lo, hi], reporting whether the value changed this frame. Clicking anywhere on the row jumps the value to the cursor and starts a drag that keeps following the mouse until the button is released, even if the cursor leaves the row. The width is the style's FieldW; a label and a formatted value are composed by the caller with Label and SameLine, like the other widgets.
func (*Context) Style ¶
Style returns the Context's current style, initializing it to DefaultStyle if it has not been set, so callers can read or tweak individual fields.
func (*Context) Submitted ¶
Submitted reports whether Enter was pressed this frame while the field with the given id had keyboard focus — handy to run a command typed into a TextField. Call it after the field so focus reflects this frame's clicks.
func (*Context) Swatch ¶
Swatch draws a clickable color square, highlighted when selected, and reports whether it was clicked this frame.
func (*Context) TextArea ¶
TextArea draws an editable multi-line field bound to *s, showing rows lines, and reports whether the text changed this frame. It supports the same selection and clipboard shortcuts as TextField, plus Enter for a newline and Up/Down to move between lines; long lines scroll horizontally (no wrap).
func (*Context) TextField ¶
TextField draws an editable single-line field bound to *s and reports whether the text changed this frame. Clicking it gives it focus; while focused it edits the text, supports a selection (Shift + arrows, Ctrl/Cmd+A) and clipboard copy/cut/paste (Ctrl/Cmd+C/X/V) via the system clipboard.
type Face ¶
Face is the text face used to render widget labels. It is an alias for Ebitengine's text/v2 Face, so a caller can supply any font: a system font (see SystemFace), an embedded TTF, or a bitmap face. When a Context has no face it falls back to Ebitengine's built-in debug font.
func SystemFace ¶
SystemFace loads a text face from a well-known operating-system font at the given size in pixels, ready to pass to (*Context).SetFace. It tries a small, per-OS list of font paths (CJK-capable ones first, so Japanese and other non-Latin text render) and returns the first that loads. When none load it returns an error, so the caller can fall back to the built-in debug font by leaving the Context's face unset.
It depends only on the standard library and Ebitengine; it does no font-config discovery, so the lists are best-effort and can miss unusual installations.
type IconSlot ¶
IconSlot is the screen-space square reserved for one visible row's icon, returned by ListWithIcons. The toolkit only draws fills, borders and text, so the caller renders the icon (e.g. an asset thumbnail) into this rect itself.
type Input ¶
type Input struct {
MouseX, MouseY float64
MouseDown bool // left button held
MouseClicked bool // left button pressed this frame
WheelY float64 // vertical scroll this frame (ebiten wheel dy)
Chars []rune
Backspace bool
Left, Right bool
Up, Down bool
Home, End bool
Enter bool
Shift bool // shift held, to extend the selection with Left/Right/Home/End
Copy bool // Ctrl/Cmd+C this frame
Cut bool // Ctrl/Cmd+X this frame
Paste bool // Ctrl/Cmd+V this frame
SelectAll bool // Ctrl/Cmd+A this frame
Undo bool // Ctrl/Cmd+Z this frame
}
Input is the per-frame input snapshot. It is plain data so the toolkit can be driven from tests; InputFromEbiten builds it from the live ebiten state.
func InputFromEbiten ¶
func InputFromEbiten() Input
InputFromEbiten samples the live ebiten input into an Input snapshot.
type Style ¶
type Style struct {
Face Face // text face; nil uses the built-in debug font
Text color.RGBA // label and field text
Border color.RGBA // widget outline
Button color.RGBA // button/toggle background
ButtonHot color.RGBA // hovered button background
ButtonOn color.RGBA // active toggle background
Field color.RGBA // text field and list background
Focus color.RGBA // focused outline, caret and selection accent
Selection color.RGBA // background of selected text
RowH float64 // height of a standard widget row
Pad float64 // inner padding
Gap float64 // gap between adjacent widgets
FieldW float64 // width of text fields and lists
}
Style holds the look of a Context: the text face, the widget colors and the layout metrics. Start from DefaultStyle, override the fields you want, then apply it with (*Context).SetStyle, so a host application can give the toolkit its own palette and sizing.
func DefaultStyle ¶
func DefaultStyle() Style
DefaultStyle returns the toolkit's built-in look: a dark, cyan-tinted scheme with the v1 metrics. A zero-value Context uses it until SetStyle is called.
type Window ¶
type Window struct {
Title string
X, Y float64
Open bool
NoClose bool // hide the close box, e.g. for an always-present toolbar
}
Window is the persistent state of a draggable, closable window. The caller owns it: X/Y and Open survive across frames. minigui moves X/Y while the title bar is dragged and clears Open when the close box is clicked (unless NoClose is set).
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
minigui-demo
command
Command minigui-demo is a sandbox for the minigui package: a panel with a label, a button and an editable text field, so the immediate-mode toolkit can be exercised on its own.
|
Command minigui-demo is a sandbox for the minigui package: a panel with a label, a button and an editable text field, so the immediate-mode toolkit can be exercised on its own. |