Documentation ¶
Overview ¶
Package gui implements the GUI infrastructure and several widgets.
Index ¶
- Constants
- func InitManager(window IWindow)
- type Align
- type BasicStyle
- type Button
- func (b *Button) Dispose()
- func (b *Button) GetButtonState() ButtonState
- func (b *Button) GetExpandToLabel() bool
- func (b *Button) GetLabelAlignment() Align
- func (b *Button) GetStateTexture(state ButtonState) *texture.Texture2D
- func (b *Button) InitButton(text string)
- func (b *Button) SetExpandToLabel(expand bool)
- func (b *Button) SetLabelAlignment(align Align)
- func (b *Button) SetStateTexture(state ButtonState, tex *texture.Texture2D)
- type ButtonState
- type IPanel
- type IWindow
- type Image
- type Label
- func (l *Label) BgColor() math32.Color4
- func (l *Label) Color() math32.Color4
- func (l *Label) Font() *text.Font
- func (l *Label) FontDPI() float64
- func (l *Label) FontSize() float64
- func (l *Label) InitLabel(txt string, fnt *text.Font)
- func (l *Label) LineSpacing() float64
- func (l *Label) SetBgColor(color math32.Color4)
- func (l *Label) SetColor(color math32.Color4)
- func (l *Label) SetFont(f *text.Font)
- func (l *Label) SetFontDPI(dpi float64)
- func (l *Label) SetFontSize(size float64)
- func (l *Label) SetLineSpacing(spacing float64)
- func (l *Label) SetText(txt string)
- func (l *Label) Text() string
- type Manager
- type Panel
- func (p *Panel) Add(ichild IPanel) *Panel
- func (p *Panel) ApplyStyle(ps *PanelStyle)
- func (p *Panel) BorderColor() math32.Color4
- func (p *Panel) Borders() RectBounds
- func (p *Panel) Bounded() bool
- func (p *Panel) ContainsPosition(x, y float32) bool
- func (p *Panel) ContentArea() Rect
- func (p *Panel) ContentColor() math32.Color4
- func (p *Panel) ContentCoords(wx, wy float32) (float32, float32)
- func (p *Panel) ContentHeight() float32
- func (p *Panel) ContentWidth() float32
- func (p *Panel) Enabled() bool
- func (p *Panel) GetPanel() *Panel
- func (p *Panel) Height() float32
- func (p *Panel) InitPanel(ipan IPanel, width, height float32)
- func (p *Panel) InitializeGraphic(width, height float32, gr *graphic.Graphic)
- func (p *Panel) InsideBorders(x, y float32) bool
- func (p *Panel) Intersects(p2 *Panel) bool
- func (p *Panel) Margins() RectBounds
- func (p *Panel) Material() *material.Material
- func (p *Panel) MinHeight() float32
- func (p *Panel) MinWidth() float32
- func (p *Panel) Paddings() RectBounds
- func (p *Panel) Pospix() math32.Vector2
- func (p *Panel) Remove(ichild IPanel) bool
- func (p *Panel) RenderSetup(gl *gls.GLS, _ *core.RenderInfo)
- func (p *Panel) SetBorderColor(color math32.Color4)
- func (p *Panel) SetBorders(src RectBounds)
- func (p *Panel) SetBounded(bounded bool)
- func (p *Panel) SetColor(color math32.Color4) *Panel
- func (p *Panel) SetContentAspectHeight(height float32)
- func (p *Panel) SetContentAspectWidth(width float32)
- func (p *Panel) SetContentColor(color math32.Color4) *Panel
- func (p *Panel) SetContentHeight(height float32)
- func (p *Panel) SetContentSize(width, height float32)
- func (p *Panel) SetContentWidth(width float32)
- func (p *Panel) SetEnabled(state bool)
- func (p *Panel) SetHeight(height float32)
- func (p *Panel) SetMargins(src RectBounds)
- func (p *Panel) SetModelMatrix(gl *gls.GLS, mm *math32.Matrix4)
- func (p *Panel) SetPaddingColor(color math32.Color4)
- func (p *Panel) SetPaddings(src RectBounds)
- func (p *Panel) SetPosition(x, y float32)
- func (p *Panel) SetSize(width, height float32)
- func (p *Panel) SetTexture(tex *texture.Texture2D) *texture.Texture2D
- func (p *Panel) SetTopChild(ipan IPanel)
- func (p *Panel) SetWidth(width float32)
- func (p *Panel) SetZLayerDelta(zLayerDelta int)
- func (p *Panel) Size() (float32, float32)
- func (p *Panel) UpdateMatrixWorld()
- func (p *Panel) Width() float32
- func (p *Panel) ZLayerDelta() int
- type PanelStyle
- type Rect
- type RectBounds
- type Style
- type Table
- func (t *Table) AddRow(values map[string]any)
- func (t *Table) Cell(col string, ri int) any
- func (t *Table) Clear()
- func (t *Table) InsertRow(row int, values map[string]any)
- func (t *Table) RemoveRow(row int)
- func (t *Table) Row(ri int) map[string]any
- func (t *Table) RowCount() int
- func (t *Table) Rows(fi, li int) []map[string]any
- func (t *Table) SetCell(row int, colid string, value any)
- func (t *Table) SetColExpand(colid string, expand float32)
- func (t *Table) SetColFormat(id, format string)
- func (t *Table) SetColOrder(colid string, order int)
- func (t *Table) SetColWidth(colid string, width float32)
- func (t *Table) SetRow(row int, values map[string]any)
- func (t *Table) SetRows(values []map[string]any)
- func (t *Table) SetStatusText(text string)
- func (t *Table) ShowAllColumns()
- func (t *Table) ShowColumn(col string, show bool)
- func (t *Table) ShowHeader(show bool)
- func (t *Table) ShowStatus(show bool)
- func (t *Table) SortColumn(col string, asString bool, asc bool)
- type TableCell
- type TableColumn
- type TableFormatFunc
Constants ¶
const ( AlignNone = Align(iota) AlignLeftTop AlignLeftBottom AlignLeftCenter AlignRightTop AlignRightBottom AlignRightCenter AlignCenterTop AlignCenterBottom AlignCenterCenter )
Variables ¶
This section is empty.
Functions ¶
func InitManager ¶ added in v0.2.18
func InitManager(window IWindow)
InitManager creates the Manager singleton or panics if it's already been called.
Types ¶
type Align ¶
type Align int
Align specifies the alignment of an object inside another.
func (Align) CalculatePosition ¶ added in v0.2.51
func (a Align) CalculatePosition(outsideWidth, outsideHeight, insideWidth, insideHeight float32) (x float32, y float32)
CalculatePosition calculates where to place an element within another element.
outsideWidth and outsideHeight usually consist of a Panel's ContentSize. insideWidth and insideHeight usually consist of a Panel's Size.
AlignNone returns (0, 0).
type BasicStyle ¶
type BasicStyle struct { PanelStyle FgColor math32.Color4 }
BasicStyle extends PanelStyle by adding a foreground color. Many GUI components can be styled using BasicStyle or redeclared versions thereof (e.g. ButtonStyle).
type Button ¶
Button is a button UI element that extends Image and uses different textures for each ButtonState. There is also a Label for text on top.
func (*Button) Dispose ¶ added in v0.2.39
func (b *Button) Dispose()
Dispose disposes of the label and all button textures.
func (*Button) GetButtonState ¶ added in v0.2.39
func (b *Button) GetButtonState() ButtonState
GetButtonState returns present button state.
func (*Button) GetExpandToLabel ¶ added in v0.2.39
GetExpandToLabel returns whether this button resizes automatically make room for its label.
func (*Button) GetLabelAlignment ¶ added in v0.2.51
GetLabelAlignment returns how this button aligns its label within its content area.
func (*Button) GetStateTexture ¶ added in v0.2.39
func (b *Button) GetStateTexture(state ButtonState) *texture.Texture2D
GetStateTexture returns the texture used by the button in a given state.
func (*Button) InitButton ¶ added in v0.2.39
InitButton initializes the image and subscribes to events.
func (*Button) SetExpandToLabel ¶ added in v0.2.39
SetExpandToLabel sets whether this button resizes automatically make room for its label.
func (*Button) SetLabelAlignment ¶ added in v0.2.51
SetLabelAlignment sets how this button aligns its label within its content area.
func (*Button) SetStateTexture ¶ added in v0.2.39
func (b *Button) SetStateTexture(state ButtonState, tex *texture.Texture2D)
SetStateTexture changes the texture used by the button in a given state. Any prior texture for the state is disposed.
type ButtonState ¶
type ButtonState int
ButtonState identifies the state of a Button.
const ( ButtonNormal ButtonState = iota ButtonOver ButtonPressed ButtonDisabled )
type IWindow ¶ added in v0.2.18
type IWindow interface { core.IDispatcher[core.WindowEvent] GetScale() (x float64, y float64) SetCursor(cursor core.Cursor) }
IWindow is the interface that the manager uses to interact with the window.
type Image ¶
type Image struct { Panel // contains filtered or unexported fields }
Image is a Panel which resizes to match the texture size by default.
func (*Image) GetResizeToTexture ¶ added in v0.2.39
GetResizeToTexture returns whether this image resizes automatically to match its texture size.
func (*Image) InitImage ¶ added in v0.2.34
func (i *Image) InitImage()
InitImage initializes an image.
func (*Image) SetResizeToTexture ¶ added in v0.2.39
SetResizeToTexture sets whether this image resizes automatically to match its texture size.
type Label ¶
type Label struct { Image // contains filtered or unexported fields }
Label is a text only UI element.
func NewIconLabel ¶ added in v0.2.32
NewIconLabel creates a Label with the specified text using the default icon font.
func NewLabelWithFont ¶
NewLabelWithFont creates a Label with the specified text using the specified font.
func (*Label) LineSpacing ¶
LineSpacing returns the spacing between lines.
func (*Label) SetBgColor ¶
SetBgColor sets the background color.
func (*Label) SetFontDPI ¶
SetFontDPI sets the resolution of the font in dots per inch (DPI).
func (*Label) SetFontSize ¶
SetFontSize sets the point size of the font.
func (*Label) SetLineSpacing ¶
SetLineSpacing sets the spacing between lines.
type Manager ¶
type Manager struct { core.Dispatcher[core.GuiEvent] core.TimerManager // contains filtered or unexported fields }
Manager routes events to the appropriate GUI components or outside the GUI if not applicable.
func GetManager ¶ added in v0.2.18
func GetManager() *Manager
GetManager returns the GUI Manager singleton or panics if InitManager hasn't been called.
func (*Manager) SetCursorFocus ¶ added in v0.2.18
func (gm *Manager) SetCursorFocus(disp core.IDispatcher[core.GuiEvent])
SetCursorFocus sets the cursor-focused IDispatcher, which will exclusively receive cursor events.
func (*Manager) SetKeyFocus ¶ added in v0.2.18
func (gm *Manager) SetKeyFocus(disp core.IDispatcher[core.GuiEvent])
SetKeyFocus sets the key-focused IDispatcher, which will exclusively receive key and char events.
type Panel ¶
type Panel struct { *graphic.Graphic core.Dispatcher[core.GuiEvent] // contains filtered or unexported fields }
Panel is 2D rectangular graphic which by default has a quad geometry. When using the default geometry, a panel has margins, borders, paddings, and a content area. The content area can be associated with a texture. It is the building block of most GUI elements.
func (*Panel) Add ¶
Add adds a child panel to this one. This overrides the Node method to enforce that IPanels can only have IPanels as children.
func (*Panel) ApplyStyle ¶
func (p *Panel) ApplyStyle(ps *PanelStyle)
ApplyStyle applies the specified style to the panel.
func (*Panel) BorderColor ¶ added in v0.2.32
BorderColor returns the panel's border color.
func (*Panel) Borders ¶
func (p *Panel) Borders() RectBounds
Borders returns the panel's border sizes.
func (*Panel) ContainsPosition ¶
ContainsPosition returns whether this panel contains the specified screen position.
func (*Panel) ContentArea ¶ added in v0.2.59
ContentArea returns the whole content area.
func (*Panel) ContentColor ¶ added in v0.2.32
ContentColor returns the panel's content color.
func (*Panel) ContentCoords ¶
ContentCoords converts the specified absolute coordinates to the panel's relative content coordinates.
func (*Panel) ContentHeight ¶
ContentHeight returns the height of the content area.
func (*Panel) ContentWidth ¶
ContentWidth returns the width of the content area.
func (*Panel) InitPanel ¶ added in v0.2.32
InitPanel initializes this panel and is normally used by other types which embed a panel.
func (*Panel) InitializeGraphic ¶
InitializeGraphic initializes this panel with an alternative graphic.
func (*Panel) InsideBorders ¶
InsideBorders returns whether a screen position is inside the panel borders, including the border width. Unlike ContainsPosition, it does not consider the panel margins.
func (*Panel) Intersects ¶
Intersects returns whether this panel intersects with another panel.
func (*Panel) Margins ¶
func (p *Panel) Margins() RectBounds
Margins returns the panel's margin sizes.
func (*Panel) MinHeight ¶
MinHeight returns the minimum height of this panel (assuming content height was 0).
func (*Panel) MinWidth ¶
MinWidth returns the minimum width of this panel (assuming content width was 0).
func (*Panel) Paddings ¶
func (p *Panel) Paddings() RectBounds
Paddings returns the panel's padding sizes.
func (*Panel) RenderSetup ¶
func (p *Panel) RenderSetup(gl *gls.GLS, _ *core.RenderInfo)
RenderSetup is called by the engine before drawing the object.
func (*Panel) SetBorderColor ¶ added in v0.2.32
SetBorderColor sets the panel's border color.
func (*Panel) SetBorders ¶
func (p *Panel) SetBorders(src RectBounds)
SetBorders sets the panel's border sizes.
func (*Panel) SetBounded ¶
SetBounded sets the panel's bounded state.
func (*Panel) SetContentAspectHeight ¶
SetContentAspectHeight sets content height of this panel while maintaining the same aspect ratio.
func (*Panel) SetContentAspectWidth ¶
SetContentAspectWidth sets content width of this panel while maintaining the same aspect ratio.
func (*Panel) SetContentColor ¶ added in v0.2.32
SetContentColor sets the panel's content color.
func (*Panel) SetContentHeight ¶
SetContentHeight sets the panel's content height.
func (*Panel) SetContentSize ¶
SetContentSize sets the panel's content size.
func (*Panel) SetContentWidth ¶
SetContentWidth sets the panel's content width.
func (*Panel) SetEnabled ¶
SetEnabled sets the panel's enabled state. A disabled panel does not process events.
func (*Panel) SetMargins ¶
func (p *Panel) SetMargins(src RectBounds)
SetMargins sets the panel's margin sizes.
func (*Panel) SetModelMatrix ¶
SetModelMatrix calculates and sets the specified matrix with the model matrix for this panel.
func (*Panel) SetPaddingColor ¶ added in v0.2.32
SetPaddingColor sets the panel's padding color.
func (*Panel) SetPaddings ¶
func (p *Panel) SetPaddings(src RectBounds)
SetPaddings sets the panel's padding sizes.
func (*Panel) SetPosition ¶
SetPosition sets the panel's position in pixel coordinates from left to right and from top to bottom of the screen.
func (*Panel) SetTexture ¶ added in v0.2.34
SetTexture changes the panel's texture. It returns a pointer to the previous texture.
func (*Panel) SetTopChild ¶
SetTopChild moves the specified panel to be the last child of this panel.
func (*Panel) SetZLayerDelta ¶
SetZLayerDelta sets the Z-layer of this panel relative to its parent.
func (*Panel) UpdateMatrixWorld ¶
func (p *Panel) UpdateMatrixWorld()
UpdateMatrixWorld overrides the standard core.Node version which is called by the Engine before rendering the frame.
func (*Panel) ZLayerDelta ¶
ZLayerDelta returns the Z-layer of this panel relative to its parent.
type PanelStyle ¶
type PanelStyle struct { Margin RectBounds Border RectBounds Padding RectBounds BorderColor math32.Color4 BgColor math32.Color4 }
PanelStyle contains all the styling attributes of a Panel.
type RectBounds ¶
RectBounds specifies the size of the boundaries of a rectangle. It can represent the thickness of the borders, the margins, or the padding of a rectangle.
type Style ¶
Style contains the styles for all GUI elements
func StyleDefault ¶
func StyleDefault() *Style
StyleDefault returns a pointer to the current default style
type Table ¶
type Table struct { Panel // Embedded panel // contains filtered or unexported fields }
Table implements a panel which can contains child panels organized in rows and columns.
func NewTable ¶
func NewTable(width, height float32, cols []TableColumn) (*Table, error)
NewTable creates and returns a pointer to a new Table with the specified width, height and columns
func (*Table) InsertRow ¶
InsertRow inserts the specified values in a new row at the specified index
func (*Table) Rows ¶
Rows returns a slice of maps with the contents of the table rows specified by the rows first and last index. To get all the table rows, use Rows(0, -1)
func (*Table) SetCell ¶
SetCell sets the value of the cell specified by its row and column id The function panics if the passed row or column id is invalid
func (*Table) SetColExpand ¶
SetColExpand sets the column expand factor. When the table width is increased the columns widths are increased proportionally to their expand factor. A column with expand factor = 0 is not increased.
func (*Table) SetColFormat ¶
SetColFormat sets the formatting string (Printf) for the specified column Update must be called to update the table.
func (*Table) SetColOrder ¶
SetColOrder sets the exhibition order of the specified column. The previous column which has the specified order will have the original column order.
func (*Table) SetColWidth ¶
SetColWidth sets the specified column width and may change the widths of the columns to the right
func (*Table) SetRow ¶
SetRow sets the value of all the cells of the specified row from the specified map indexed by column id.
func (*Table) SetRows ¶
SetRows clears all current rows of the table and sets new rows from the specifying parameter. Each row is a map keyed by the colum id. The map value currently can be a string or any number type If a row column is not found it is ignored
func (*Table) SetStatusText ¶
SetStatusText sets the text of status line at the bottom of the table It does not change its current visibility
func (*Table) ShowAllColumns ¶
func (t *Table) ShowAllColumns()
ShowAllColumns shows all the table columns
func (*Table) ShowColumn ¶
ShowColumn sets the visibility of the column with the specified id If the column id does not exit the function panics.
func (*Table) ShowHeader ¶
ShowHeader shows or hides the table header
func (*Table) ShowStatus ¶
ShowStatus sets the visibility of the status lines at the bottom of the table
func (*Table) SortColumn ¶
SortColumn sorts the specified column interpreting its values as strings or numbers and sorting in ascending or descending order. This sorting is independent of the sort configuration of column set when the table was created
type TableCell ¶
type TableCell struct { Tab *Table // Pointer to table Row int // Row index Col string // Column id Value any // Cell value }
TableCell describes a table cell. It is used as a parameter for formatting function
type TableColumn ¶
type TableColumn struct { Id string // Column id used to reference the column. Must be unique Header string // Column name shown in the table header Width float32 // Initial column width in pixels Minwidth float32 // Minimum width in pixels for this column Hidden bool // Hidden flag Align Align // Cell content alignment Format string // Format string for formatting the columns' cells FormatFunc TableFormatFunc // Format function (overrides Format string) Expand float32 // Column width expansion factor (0 for no expansion) }
TableColumn describes a table column
type TableFormatFunc ¶
TableFormatFunc is the type for formatting functions