gui

package
v0.2.66 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2024 License: BSD-2-Clause Imports: 15 Imported by: 0

Documentation

Overview

Package gui implements the GUI infrastructure and several widgets.

Index

Constants

View Source
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

type Button struct {
	Image
	Label *Label
	// contains filtered or unexported fields
}

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 NewButton

func NewButton(text string) *Button

NewButton creates a new Button with the specified text the button label.

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

func (b *Button) GetExpandToLabel() bool

GetExpandToLabel returns whether this button resizes automatically make room for its label.

func (*Button) GetLabelAlignment added in v0.2.51

func (b *Button) GetLabelAlignment() Align

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

func (b *Button) InitButton(text string)

InitButton initializes the image and subscribes to events.

func (*Button) SetExpandToLabel added in v0.2.39

func (b *Button) SetExpandToLabel(expand bool)

SetExpandToLabel sets whether this button resizes automatically make room for its label.

func (*Button) SetLabelAlignment added in v0.2.51

func (b *Button) SetLabelAlignment(align Align)

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 IPanel

type IPanel interface {
	graphic.IGraphic
	core.IDispatcher[core.GuiEvent]
	GetPanel() *Panel
}

IPanel is the interface for all panel types.

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 NewImage

func NewImage() *Image

NewImage creates a new Image.

func (*Image) GetResizeToTexture added in v0.2.39

func (i *Image) GetResizeToTexture() bool

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

func (i *Image) SetResizeToTexture(resize bool)

SetResizeToTexture sets whether this image resizes automatically to match its texture size.

func (*Image) SetTexture

func (i *Image) SetTexture(tex *texture.Texture2D) *texture.Texture2D

SetTexture changes the image's texture and resizes the panel. It returns a pointer to the previous texture.

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

func NewIconLabel(txt string) *Label

NewIconLabel creates a Label with the specified text using the default icon font.

func NewLabel

func NewLabel(txt string) *Label

NewLabel creates a Label with the specified text using the default font.

func NewLabelWithFont

func NewLabelWithFont(txt string, fnt *text.Font) *Label

NewLabelWithFont creates a Label with the specified text using the specified font.

func (*Label) BgColor

func (l *Label) BgColor() math32.Color4

BgColor returns the background color.

func (*Label) Color

func (l *Label) Color() math32.Color4

Color returns the text color.

func (*Label) Font

func (l *Label) Font() *text.Font

Font returns the font.

func (*Label) FontDPI

func (l *Label) FontDPI() float64

FontDPI returns the resolution of the font in dots per inch (DPI).

func (*Label) FontSize

func (l *Label) FontSize() float64

FontSize returns the point size of the font.

func (*Label) InitLabel added in v0.2.32

func (l *Label) InitLabel(txt string, fnt *text.Font)

InitLabel initializes this Label.

func (*Label) LineSpacing

func (l *Label) LineSpacing() float64

LineSpacing returns the spacing between lines.

func (*Label) SetBgColor

func (l *Label) SetBgColor(color math32.Color4)

SetBgColor sets the background color.

func (*Label) SetColor

func (l *Label) SetColor(color math32.Color4)

SetColor sets the text color.

func (*Label) SetFont

func (l *Label) SetFont(f *text.Font)

SetFont sets the font.

func (*Label) SetFontDPI

func (l *Label) SetFontDPI(dpi float64)

SetFontDPI sets the resolution of the font in dots per inch (DPI).

func (*Label) SetFontSize

func (l *Label) SetFontSize(size float64)

SetFontSize sets the point size of the font.

func (*Label) SetLineSpacing

func (l *Label) SetLineSpacing(spacing float64)

SetLineSpacing sets the spacing between lines.

func (*Label) SetText

func (l *Label) SetText(txt string)

SetText sets and redraws the label text.

func (*Label) Text

func (l *Label) Text() string

Text returns the label text.

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.

func (*Manager) SetScene added in v0.2.52

func (gm *Manager) SetScene(scene core.INode)

SetScene sets the INode to watch for 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 NewPanel

func NewPanel(width, height float32) *Panel

NewPanel a new panel with the specified dimensions.

func (*Panel) Add

func (p *Panel) Add(ichild IPanel) *Panel

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

func (p *Panel) BorderColor() math32.Color4

BorderColor returns the panel's border color.

func (*Panel) Borders

func (p *Panel) Borders() RectBounds

Borders returns the panel's border sizes.

func (*Panel) Bounded

func (p *Panel) Bounded() bool

Bounded returns the panel's bounded state.

func (*Panel) ContainsPosition

func (p *Panel) ContainsPosition(x, y float32) bool

ContainsPosition returns whether this panel contains the specified screen position.

func (*Panel) ContentArea added in v0.2.59

func (p *Panel) ContentArea() Rect

ContentArea returns the whole content area.

func (*Panel) ContentColor added in v0.2.32

func (p *Panel) ContentColor() math32.Color4

ContentColor returns the panel's content color.

func (*Panel) ContentCoords

func (p *Panel) ContentCoords(wx, wy float32) (float32, float32)

ContentCoords converts the specified absolute coordinates to the panel's relative content coordinates.

func (*Panel) ContentHeight

func (p *Panel) ContentHeight() float32

ContentHeight returns the height of the content area.

func (*Panel) ContentWidth

func (p *Panel) ContentWidth() float32

ContentWidth returns the width of the content area.

func (*Panel) Enabled

func (p *Panel) Enabled() bool

Enabled returns the enabled state of this panel.

func (*Panel) GetPanel

func (p *Panel) GetPanel() *Panel

GetPanel satisfies the IPanel interface and returns pointer to this panel.

func (*Panel) Height

func (p *Panel) Height() float32

Height returns the panel external height.

func (*Panel) InitPanel added in v0.2.32

func (p *Panel) InitPanel(ipan IPanel, width, height float32)

InitPanel initializes this panel and is normally used by other types which embed a panel.

func (*Panel) InitializeGraphic

func (p *Panel) InitializeGraphic(width, height float32, gr *graphic.Graphic)

InitializeGraphic initializes this panel with an alternative graphic.

func (*Panel) InsideBorders

func (p *Panel) InsideBorders(x, y float32) bool

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

func (p *Panel) Intersects(p2 *Panel) bool

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) Material

func (p *Panel) Material() *material.Material

Material returns a pointer for the panel's material.

func (*Panel) MinHeight

func (p *Panel) MinHeight() float32

MinHeight returns the minimum height of this panel (assuming content height was 0).

func (*Panel) MinWidth

func (p *Panel) MinWidth() float32

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) Pospix

func (p *Panel) Pospix() math32.Vector2

Pospix returns the panel's absolute coordinate.

func (*Panel) Remove

func (p *Panel) Remove(ichild IPanel) bool

Remove removes the specified child from this panel.

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

func (p *Panel) SetBorderColor(color math32.Color4)

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

func (p *Panel) SetBounded(bounded bool)

SetBounded sets the panel's bounded state.

func (*Panel) SetColor

func (p *Panel) SetColor(color math32.Color4) *Panel

SetColor sets the panel's padding and content color.

func (*Panel) SetContentAspectHeight

func (p *Panel) SetContentAspectHeight(height float32)

SetContentAspectHeight sets content height of this panel while maintaining the same aspect ratio.

func (*Panel) SetContentAspectWidth

func (p *Panel) SetContentAspectWidth(width float32)

SetContentAspectWidth sets content width of this panel while maintaining the same aspect ratio.

func (*Panel) SetContentColor added in v0.2.32

func (p *Panel) SetContentColor(color math32.Color4) *Panel

SetContentColor sets the panel's content color.

func (*Panel) SetContentHeight

func (p *Panel) SetContentHeight(height float32)

SetContentHeight sets the panel's content height.

func (*Panel) SetContentSize

func (p *Panel) SetContentSize(width, height float32)

SetContentSize sets the panel's content size.

func (*Panel) SetContentWidth

func (p *Panel) SetContentWidth(width float32)

SetContentWidth sets the panel's content width.

func (*Panel) SetEnabled

func (p *Panel) SetEnabled(state bool)

SetEnabled sets the panel's enabled state. A disabled panel does not process events.

func (*Panel) SetHeight

func (p *Panel) SetHeight(height float32)

SetHeight sets this panel external height.

func (*Panel) SetMargins

func (p *Panel) SetMargins(src RectBounds)

SetMargins sets the panel's margin sizes.

func (*Panel) SetModelMatrix

func (p *Panel) SetModelMatrix(gl *gls.GLS, mm *math32.Matrix4)

SetModelMatrix calculates and sets the specified matrix with the model matrix for this panel.

func (*Panel) SetPaddingColor added in v0.2.32

func (p *Panel) SetPaddingColor(color math32.Color4)

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

func (p *Panel) SetPosition(x, y float32)

SetPosition sets the panel's position in pixel coordinates from left to right and from top to bottom of the screen.

func (*Panel) SetSize

func (p *Panel) SetSize(width, height float32)

SetSize sets this panel external width and height.

func (*Panel) SetTexture added in v0.2.34

func (p *Panel) SetTexture(tex *texture.Texture2D) *texture.Texture2D

SetTexture changes the panel's texture. It returns a pointer to the previous texture.

func (*Panel) SetTopChild

func (p *Panel) SetTopChild(ipan IPanel)

SetTopChild moves the specified panel to be the last child of this panel.

func (*Panel) SetWidth

func (p *Panel) SetWidth(width float32)

SetWidth sets this panel external width.

func (*Panel) SetZLayerDelta

func (p *Panel) SetZLayerDelta(zLayerDelta int)

SetZLayerDelta sets the Z-layer of this panel relative to its parent.

func (*Panel) Size

func (p *Panel) Size() (float32, float32)

Size returns this panel external width and height.

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) Width

func (p *Panel) Width() float32

Width returns the panel external width.

func (*Panel) ZLayerDelta

func (p *Panel) ZLayerDelta() int

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 Rect

type Rect struct {
	X      float32
	Y      float32
	Width  float32
	Height float32
}

Rect represents a rectangle.

type RectBounds

type RectBounds struct {
	Top    float32
	Right  float32
	Bottom float32
	Left   float32
}

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

type Style struct {
	Font     *text.Font
	FontIcon *text.Font
}

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) AddRow

func (t *Table) AddRow(values map[string]any)

AddRow adds a new row at the end of the table with the specified values

func (*Table) Cell

func (t *Table) Cell(col string, ri int) any

Cell returns the current content of the specified cell

func (*Table) Clear

func (t *Table) Clear()

Clear removes all rows from the table

func (*Table) InsertRow

func (t *Table) InsertRow(row int, values map[string]any)

InsertRow inserts the specified values in a new row at the specified index

func (*Table) RemoveRow

func (t *Table) RemoveRow(row int)

RemoveRow removes from the specified row from the table

func (*Table) Row

func (t *Table) Row(ri int) map[string]any

Row returns a map with the current contents of the specified row index

func (*Table) RowCount

func (t *Table) RowCount() int

RowCount returns the current number of rows in the table

func (*Table) Rows

func (t *Table) Rows(fi, li int) []map[string]any

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

func (t *Table) SetCell(row int, colid string, value any)

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

func (t *Table) SetColExpand(colid string, expand float32)

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

func (t *Table) SetColFormat(id, format string)

SetColFormat sets the formatting string (Printf) for the specified column Update must be called to update the table.

func (*Table) SetColOrder

func (t *Table) SetColOrder(colid string, order int)

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

func (t *Table) SetColWidth(colid string, width float32)

SetColWidth sets the specified column width and may change the widths of the columns to the right

func (*Table) SetRow

func (t *Table) SetRow(row int, values map[string]any)

SetRow sets the value of all the cells of the specified row from the specified map indexed by column id.

func (*Table) SetRows

func (t *Table) SetRows(values []map[string]any)

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

func (t *Table) SetStatusText(text string)

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

func (t *Table) ShowColumn(col string, show bool)

ShowColumn sets the visibility of the column with the specified id If the column id does not exit the function panics.

func (*Table) ShowHeader

func (t *Table) ShowHeader(show bool)

ShowHeader shows or hides the table header

func (*Table) ShowStatus

func (t *Table) ShowStatus(show bool)

ShowStatus sets the visibility of the status lines at the bottom of the table

func (*Table) SortColumn

func (t *Table) SortColumn(col string, asString bool, asc bool)

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

type TableFormatFunc func(cell TableCell) string

TableFormatFunc is the type for formatting functions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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