gui

package
v0.0.0-...-c9d8584 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MouseStatus = &Mouse{}

SingleWallBorder displays a single line border

View Source
var UpdateMouseStatus func()
View Source
var ZeroFrameTitle = FrameTitle{
	// contains filtered or unexported fields
}
View Source
var ZeroWallBorder = FrameStyle{
	0, 0, 0, 0, 0, 0,
}

ZeroWallBorder displays no border

Functions

func PositionFromVec2

func PositionFromVec2(vector2 rl.Vector2) geom.Point

func StrToColour

func StrToColour(str string) rl.Color

tmp @todo replace with theme service

Types

type Button

type Button struct {
	Widget
	// contains filtered or unexported fields
}

func (*Button) ComputeSize

func (b *Button) ComputeSize()

func (Button) GetLabel

func (b Button) GetLabel() string

func (*Button) IsPressed

func (b *Button) IsPressed() bool

func (*Button) Render

func (b *Button) Render(iB IWidget)

func (*Button) SetLabel

func (b *Button) SetLabel(newLabel string)

type ButtonCallback

type ButtonCallback func(w *Button, userData interface{})

type Cell

type Cell struct {
	// contains filtered or unexported fields
}

type CellLayer

type CellLayer struct {
	// contains filtered or unexported fields
}

type CellMap

type CellMap map[geom.Point]*Cell

type Console

type Console struct {
	// contains filtered or unexported fields
}

func NewVirtualConsole

func NewVirtualConsole(w, h uint) *Console

You can create as many off-screen consoles as you want by using this function. Then use the blit function to draw content to a windowed virtual console such as RaylibConsole.

func (*Console) Blit

func (c *Console) Blit(xSrc, ySrc, wSrc, hSrc int, dst IConsole, xDst, yDst int, foregroundAlpha, backgroundAlpha float32)

This function allows you to blit a rectangular area of the source console at a specific position on a destination console. It can also simulate alpha transparency with the fade parameter.

func (*Console) Clear

func (c *Console) Clear()

Clear the console data

func (*Console) ClearDirty

func (c *Console) ClearDirty()

func (*Console) ClearRect

func (c *Console) ClearRect(pos geom.Point, w, h uint)

Reset cells within the Rectangular area to default

func (*Console) GetCellAtPos

func (c *Console) GetCellAtPos(pos geom.Point) *Cell

func (Console) GetChar

func (c Console) GetChar(pos geom.Point) uint

func (Console) GetCharBackground

func (c Console) GetCharBackground(pos geom.Point) rl.Color

TODO This will result in a panic if pos is out of bounds

func (Console) GetCharForeground

func (c Console) GetCharForeground(pos geom.Point) rl.Color

TODO This will result in a panic if pos is out of bounds

func (Console) GetData

func (c Console) GetData() CellMap

func (Console) GetDefaultBackground

func (c Console) GetDefaultBackground() rl.Color

func (Console) GetDefaultForeground

func (c Console) GetDefaultForeground() rl.Color

func (Console) GetDirty

func (c Console) GetDirty() DirtyMap

func (Console) GetHeight

func (c Console) GetHeight() uint

func (Console) GetWidth

func (c Console) GetWidth() uint

func (*Console) Hline

func (c *Console) Hline(pos geom.Point, l uint)

Hline draws a horizontal line using the default colors.

func (*Console) InBounds

func (c *Console) InBounds(pos geom.Point) bool

func (*Console) Print

func (c *Console) Print(pos geom.Point, str string)

Split str into individual runes and then loop over and set the char at that geom position.

<%FG:colour_name>Text<%/> <%BG:colour_name>Text<%/> <%FG:colour_name,BG:colour_name>Text<%/>

func (*Console) PrintFrame

func (c *Console) PrintFrame(pos geom.Point, w, h uint, style FrameStyle, title FrameTitle, filled, clear bool)

func (*Console) PutChar

func (c *Console) PutChar(r uint, p geom.Point)

TODO This will result in a panic if p is out of bounds

func (*Console) PutCharEx

func (c *Console) PutCharEx(r uint, p geom.Point, fg, bg rl.Color)

TODO This will result in a panic if p is out of bounds

func (*Console) SetChar

func (c *Console) SetChar(r uint, pos geom.Point)

TODO This will result in a panic if pos is out of bounds

func (*Console) SetCharBackground

func (c *Console) SetCharBackground(pos geom.Point, colour rl.Color)

TODO This will result in a panic if pos is out of bounds

func (*Console) SetCharForeground

func (c *Console) SetCharForeground(pos geom.Point, colour rl.Color)

TODO This will result in a panic if pos is out of bounds

func (*Console) SetDefaultBackground

func (c *Console) SetDefaultBackground(colour rl.Color)

func (*Console) SetDefaultForeground

func (c *Console) SetDefaultForeground(colour rl.Color)

func (*Console) SetDirty

func (c *Console) SetDirty(pos geom.Point)

func (*Console) SetKeyColor

func (c *Console) SetKeyColor(colour rl.Color)

type Container

type Container struct {
	Widget
	// contains filtered or unexported fields
}

Container is a workspace for displaying Widgets within a particular "viewport"

func (*Container) AddWidget

func (c *Container) AddWidget(w IWidget)

func (*Container) Clear

func (c *Container) Clear()

func (*Container) Delete

func (c *Container) Delete()

func (*Container) RemoveWidget

func (c *Container) RemoveWidget(w IWidget)

func (*Container) Render

func (c *Container) Render(iW IWidget)

func (*Container) Update

func (c *Container) Update(iW IWidget)

type DirtyMap

type DirtyMap map[geom.Point]bool

type FrameStyle

type FrameStyle struct {
	V, H, NE, SE, SW, NW uint
}

FrameStyle defines a Widget's border. Those without a border will have it set to ZeroWallBorder.

func (FrameStyle) IsZeroWallBorder

func (f FrameStyle) IsZeroWallBorder() bool

IsZeroWallBorder is used to determine if a Widget's border should be drawn

type FrameTitle

type FrameTitle struct {
	// contains filtered or unexported fields
}

FrameTitle is complementary to FrameStyle, both are used by IConsole.PrintFrame

func (FrameTitle) IsVisible

func (f FrameTitle) IsVisible() bool

func (FrameTitle) Position

func (f FrameTitle) Position(homePos geom.Point, width, height uint) geom.Point

type Gui

type Gui struct {
	// contains filtered or unexported fields
}

func NewGui

func NewGui(console IConsole) *Gui

Construct a new Gui

func (*Gui) GetConsole

func (g *Gui) GetConsole() IConsole

func (*Gui) GetFocusedKeyboardWidget

func (g *Gui) GetFocusedKeyboardWidget() IWidget

Get the focused Widget for keyboard input

func (*Gui) GetFocusedWidget

func (g *Gui) GetFocusedWidget() IWidget

Get the focused Widget for mouse input

func (*Gui) IsFocused

func (g *Gui) IsFocused(w IWidget) bool

Set the focused Widget for mouse input

func (*Gui) IsKeyboardFocused

func (g *Gui) IsKeyboardFocused(w IWidget) bool

Set the focused Widget for keyboard input

func (*Gui) NewBasicButton

func (g *Gui) NewBasicButton(pos geom.Point, width, height uint, label string, borderStyle FrameStyle) *Button

func (*Gui) NewBasicRadioButton

func (g *Gui) NewBasicRadioButton(pos geom.Point, width, height uint, label string, borderStyle FrameStyle) *RadioButton

func (*Gui) NewBasicToggleButton

func (g *Gui) NewBasicToggleButton(pos geom.Point, width, height uint, label string, borderStyle FrameStyle) *ToggleButton

func (*Gui) NewButton

func (g *Gui) NewButton(pos geom.Point, width, height uint, label string, tip string, borderStyle FrameStyle, callback ButtonCallback, userData interface{}) *Button

func (*Gui) NewContainer

func (g *Gui) NewContainer(pos geom.Point, width, height uint) *Container

func (*Gui) NewHBox

func (g *Gui) NewHBox(pos geom.Point, padding uint) *HBox

func (*Gui) NewRadioButton

func (g *Gui) NewRadioButton(pos geom.Point, width, height uint, label string, tip string, borderStyle FrameStyle, callback RadioButtonCallback, userData interface{}) *RadioButton

func (*Gui) NewSeparator

func (g *Gui) NewSeparator(text, tip string) *Separator

func (*Gui) NewToggleButton

func (g *Gui) NewToggleButton(pos geom.Point, width, height uint, label string, tip string, borderStyle FrameStyle, callback ToggleButtonCallback, userData interface{}) *ToggleButton

func (*Gui) NewToolbar

func (g *Gui) NewToolbar(pos geom.Point, width uint, name string) *Toolbar

func (*Gui) NewVBox

func (g *Gui) NewVBox(pos geom.Point, padding uint) *VBox

func (*Gui) Register

func (g *Gui) Register(w IWidget)

Add a Widget to the Gui

func (*Gui) RenderWidgets

func (g *Gui) RenderWidgets()

func (*Gui) SetConsole

func (g *Gui) SetConsole(console IConsole)

Set the Console the Gui should render to

func (*Gui) Unregister

func (g *Gui) Unregister(w IWidget)

Remove a Widget from the Gui

func (*Gui) UpdateWidgets

func (g *Gui) UpdateWidgets(dt float32)

type HBox

type HBox struct {
	VBox
}

HBox is an extension to Container that ensures Widget's added to it are presented in a row

func (*HBox) ComputeSize

func (h *HBox) ComputeSize()

type IConsole

type IConsole interface {
	InBounds(pos geom.Point) bool
	GetData() CellMap
	GetDirty() DirtyMap
	ClearDirty()
	GetCellAtPos(pos geom.Point) *Cell
	GetDefaultBackground() rl.Color
	GetDefaultForeground() rl.Color
	SetDefaultForeground(colour rl.Color)
	SetDefaultBackground(colour rl.Color)
	Clear()
	GetCharBackground(pos geom.Point) rl.Color
	GetCharForeground(pos geom.Point) rl.Color
	SetCharBackground(pos geom.Point, colour rl.Color)
	SetCharForeground(pos geom.Point, colour rl.Color)
	SetChar(r uint, pos geom.Point)
	PutChar(r uint, p geom.Point)
	PutCharEx(r uint, p geom.Point, fg, bg rl.Color)
	Print(pos geom.Point, str string)
	//PrintRect(x, y, w, h int, fmts string, v ...interface{}) int
	ClearRect(pos geom.Point, w, h uint)

	// TODO: Rename PrintFrame to DrawFrame ??
	PrintFrame(pos geom.Point, w, h uint, boxStyle FrameStyle, title FrameTitle, filled, clear bool)
	//PrintRectEx(x, y, w, h int, flag BkgndFlag, alignment Alignment, fmts string, v ...interface{}) int
	//HeightRect(x, y, w, h int, fmts string, v ...interface{}) int
	//SetBackgroundFlag(flag BkgndFlag)
	//GetBackgroundFlag() BkgndFlag
	//SetAlignment(alignment Alignment)
	//GetAlignment() Alignment
	//Rect(x, y, w, h int, clear bool, flag BkgndFlag)
	Hline(pos geom.Point, l uint)
	//Vline(x, y, l int, flag BkgndFlag)
	GetChar(pos geom.Point) uint
	GetWidth() uint
	GetHeight() uint
	SetKeyColor(colour rl.Color)
	Blit(xSrc, ySrc, wSrc, hSrc int, dst IConsole, xDst, yDst int, foregroundAlpha, backgroundAlpha float32)
}

type IWidget

type IWidget interface {
	SetGui(*Gui)
	GetGui() *Gui
	Delete()
	SetX(int)
	SetY(int)
	GetWidth() uint
	SetWidth(width uint)
	GetHeight() uint
	SetHeight(height uint)
	GetPosition() geom.Point
	Move(pos geom.Point)
	IsVisible() bool
	SetVisible(visible bool)
	GetUserData() interface{}
	SetUserData(data interface{})
	SetDisabled(d bool)
	GetDisabled() bool
	GetTip() string
	SetTip(tip string)
	GetMouseIn() bool
	SetMouseIn(mouseIn bool)
	GetMouseL() bool
	SetMouseL(mouseL bool)
	ComputeSize()
	Update(w IWidget)
	Render(w IWidget)
	SetDefaultBackground(col, colFocus rl.Color)
	SetDefaultForeground(col, colFocus rl.Color)
	GetDefaultBackground() (col, colFocus rl.Color)
	GetDefaultForeground() (col, colFocus rl.Color)
	GetCurrentColors() (fore, back rl.Color)
	GetBorderStyle() FrameStyle
	SetBorderStyle(f FrameStyle)
	// contains filtered or unexported methods
}

IWidget is an interface based upon the libtcod widget toolkit. It's partially implemented by the base Widget struct, which itself is extended by the GUI components such as Button and VBox.

type Mouse

type Mouse struct {
	Pos            geom.Point
	LButton        bool
	RButton        bool
	MButton        bool
	LButtonPressed bool
	RButtonPressed bool
	MButtonPressed bool
	WheelUp        bool
	WheelDown      bool
	WindowFocus    bool
	Visible        bool
	Supported      bool
}

type RadioButton

type RadioButton struct {
	Button
	// contains filtered or unexported fields
}

func (*RadioButton) IsSelected

func (b *RadioButton) IsSelected() bool

func (*RadioButton) Render

func (b *RadioButton) Render(iB IWidget)

func (*RadioButton) Select

func (b *RadioButton) Select()

func (*RadioButton) SetGroup

func (b *RadioButton) SetGroup(group uint)

func (*RadioButton) UnSelect

func (b *RadioButton) UnSelect()

type RadioButtonCallback

type RadioButtonCallback func(w *RadioButton, userData interface{})

type RadioButtonGroups

type RadioButtonGroups struct {
	// contains filtered or unexported fields
}

func NewRadioButtonGroups

func NewRadioButtonGroups() *RadioButtonGroups

func (*RadioButtonGroups) SetDefaultGroup

func (g *RadioButtonGroups) SetDefaultGroup(group uint)

func (*RadioButtonGroups) SetGroupSelection

func (g *RadioButtonGroups) SetGroupSelection(btn *RadioButton)

func (*RadioButtonGroups) UnSelectGroup

func (g *RadioButtonGroups) UnSelectGroup(group uint)

type RaylibConsole

type RaylibConsole struct {
	Console
	// contains filtered or unexported fields
}

func NewRaylibConsole

func NewRaylibConsole(w, h uint, fps uint, title string, fontProps sprites.TileSetProperties, fullscreen bool) *RaylibConsole

Create a new Virtual console wrapped in a Raylib window; only one of these should be used per application. In libtcod parlance this is a root console.

For a Windowed console the width/height of Console is equivalent to columns/rows.

@todo check and return error if division by zero when tile width/height is zero

func (RaylibConsole) Draw

func (c RaylibConsole) Draw(dt float32)

func (*RaylibConsole) SetDebug

func (c *RaylibConsole) SetDebug(b bool)

func (RaylibConsole) Unload

func (c RaylibConsole) Unload()

type Separator

type Separator struct {
	Widget
	// contains filtered or unexported fields
}

func (*Separator) ComputeSize

func (s *Separator) ComputeSize()

func (*Separator) Render

func (s *Separator) Render(iW IWidget)

type TextAlignment

type TextAlignment uint
const (
	AlignTextLeft TextAlignment = iota
	AlignTextCenter
	AlignTextRight
)

type ToggleButton

type ToggleButton struct {
	Button
	// contains filtered or unexported fields
}

func (ToggleButton) IsToggled

func (b ToggleButton) IsToggled() bool

func (*ToggleButton) Render

func (b *ToggleButton) Render(iB IWidget)

func (*ToggleButton) SetToggled

func (b *ToggleButton) SetToggled(value bool)

type ToggleButtonCallback

type ToggleButtonCallback func(w *ToggleButton, userData interface{})

type Toolbar

type Toolbar struct {
	Container
	// contains filtered or unexported fields
}

func (*Toolbar) AddSeparator

func (t *Toolbar) AddSeparator(txt, tip string)

func (*Toolbar) ComputeSize

func (t *Toolbar) ComputeSize()

func (*Toolbar) Render

func (t *Toolbar) Render(iW IWidget)

func (*Toolbar) SetName

func (t *Toolbar) SetName(name string)

type VBox

type VBox struct {
	Container
	// contains filtered or unexported fields
}

VBox is an extension to Container that ensures Widget's added to it are presented in a column.

func (*VBox) ComputeSize

func (v *VBox) ComputeSize()

ComputeSize calculates the VBox dimensions and updates each of its child Widget's position to be stacked within those bounds.

type Widget

type Widget struct {
	// contains filtered or unexported fields
}

Widget is the base struct extended by all GUI components. It implements all but eight of the methods defined by IWidget leaving them as "abstract" to be extended by GUI components.

func (*Widget) ComputeSize

func (w *Widget) ComputeSize()

func (*Widget) Delete

func (w *Widget) Delete()

func (Widget) GetBorderStyle

func (w Widget) GetBorderStyle() FrameStyle

func (*Widget) GetCurrentColors

func (w *Widget) GetCurrentColors() (fore, back rl.Color)

func (*Widget) GetDefaultBackground

func (w *Widget) GetDefaultBackground() (col, colFocus rl.Color)

func (*Widget) GetDefaultForeground

func (w *Widget) GetDefaultForeground() (col, colFocus rl.Color)

func (Widget) GetDisabled

func (w Widget) GetDisabled() bool

func (Widget) GetGui

func (w Widget) GetGui() *Gui

func (Widget) GetHeight

func (w Widget) GetHeight() uint

func (Widget) GetMouseIn

func (w Widget) GetMouseIn() bool

func (Widget) GetMouseL

func (w Widget) GetMouseL() bool

func (Widget) GetPosition

func (w Widget) GetPosition() geom.Point

func (Widget) GetTip

func (w Widget) GetTip() string

func (*Widget) GetUserData

func (w *Widget) GetUserData() interface{}

func (Widget) GetWidth

func (w Widget) GetWidth() uint

func (Widget) IsVisible

func (w Widget) IsVisible() bool

func (*Widget) Move

func (w *Widget) Move(pos geom.Point)

func (Widget) Render

func (w Widget) Render(iW IWidget)

func (*Widget) SetBorderStyle

func (w *Widget) SetBorderStyle(f FrameStyle)

func (*Widget) SetDefaultBackground

func (w *Widget) SetDefaultBackground(col, colFocus rl.Color)

func (*Widget) SetDefaultForeground

func (w *Widget) SetDefaultForeground(col, colFocus rl.Color)

func (*Widget) SetDisabled

func (w *Widget) SetDisabled(d bool)

func (*Widget) SetGui

func (w *Widget) SetGui(g *Gui)

func (*Widget) SetHeight

func (w *Widget) SetHeight(height uint)

func (*Widget) SetMouseIn

func (w *Widget) SetMouseIn(mouseIn bool)

func (*Widget) SetMouseL

func (w *Widget) SetMouseL(mouseL bool)

func (*Widget) SetTip

func (w *Widget) SetTip(tip string)

func (*Widget) SetUserData

func (w *Widget) SetUserData(data interface{})

func (*Widget) SetVisible

func (w *Widget) SetVisible(visible bool)

func (*Widget) SetWidth

func (w *Widget) SetWidth(width uint)

func (*Widget) SetX

func (w *Widget) SetX(x int)

func (*Widget) SetY

func (w *Widget) SetY(y int)

func (*Widget) Update

func (w *Widget) Update(iW IWidget)

Update gets called by Gui in order to update the mouse meta for each Widget. In this functions scope `w` is the base Widget struct while iW is any of the inheriting widgets for example Button.

Jump to

Keyboard shortcuts

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