Documentation
¶
Index ¶
- Constants
- Variables
- func MenuDebug(message string)
- type Alignment
- type Formatable
- type FormatableType
- type Label
- func (label *Label) Draw()
- func (label *Label) Follow() bool
- func (label *Label) GetPadding() Padding
- func (label *Label) GetPosition() mgl32.Vec2
- func (label *Label) Height() float32
- func (label *Label) InsidePoint() (P Point)
- func (label *Label) IsClicked(xPos, yPos float64, button MouseClick)
- func (label *Label) IsHovered(xPos, yPos float64)
- func (label *Label) IsNoop() bool
- func (label *Label) IsReleased(xPos, yPos float64, button MouseClick)
- func (label *Label) NavigateAway() bool
- func (label *Label) NavigateTo()
- func (label *Label) OrthoToScreenCoord() (X1 Point, X2 Point)
- func (label *Label) Reset()
- func (label *Label) SetPosition(v mgl32.Vec2)
- func (label *Label) SetString(str string, argv ...interface{})
- func (label *Label) Type() FormatableType
- func (label *Label) Width() float32
- type LabelAction
- type LabelConfig
- type LabelInteraction
- type Menu
- func (menu *Menu) Draw() bool
- func (menu *Menu) Finalize(align Alignment)
- func (menu *Menu) Hide()
- func (menu *Menu) KeyRelease(key glfw.Key, withShift bool)
- func (menu *Menu) MouseClick(xPos, yPos float64, button MouseClick)
- func (menu *Menu) MouseHover(xPos, yPos float64)
- func (menu *Menu) MouseRelease(xPos, yPos float64, button MouseClick)
- func (menu *Menu) NewLabel(str string, config LabelConfig) *Label
- func (menu *Menu) NewMenuTexture(imagePath string, dimensions mgl32.Vec2) (mt *MenuTexture, err error)
- func (menu *Menu) NewTextBox(str string, width, height float32, borderWidth int32) *TextBox
- func (menu *Menu) Release()
- func (menu *Menu) ResizeWindow(width float32, height float32)
- func (menu *Menu) Show()
- func (menu *Menu) Toggle()
- type MenuDefaults
- type MenuImage
- type MenuLogger
- type MenuManager
- func (mm *MenuManager) Draw() bool
- func (mm *MenuManager) Finalize(align Alignment) error
- func (mm *MenuManager) Hide()
- func (mm *MenuManager) IsVisible() bool
- func (mm *MenuManager) KeyRelease(key glfw.Key, withShift bool)
- func (mm *MenuManager) MouseClick(xPos, yPos float64, button MouseClick)
- func (mm *MenuManager) MouseHover(xPos, yPos float64)
- func (mm *MenuManager) MouseRelease(xPos, yPos float64, button MouseClick)
- func (mm *MenuManager) NewMenu(window *glfw.Window, name string, menuDefaults MenuDefaults, ...) (*Menu, error)
- func (mm *MenuManager) Release()
- func (mm *MenuManager) SetText(name string, index int, text string) error
- func (mm *MenuManager) Show(name string) error
- func (mm *MenuManager) Toggle(name string) error
- type MenuTexture
- type MouseClick
- type Navigation
- type Padding
- type Point
- type ScreenPosition
- type TextBox
- func (textbox *TextBox) Backspace()
- func (textbox *TextBox) Draw()
- func (textbox *TextBox) Edit(key glfw.Key, withShift bool)
- func (textbox *TextBox) Follow() bool
- func (textbox *TextBox) GetBoundingBox() (X1, X2 Point)
- func (textbox *TextBox) GetPadding() Padding
- func (textbox *TextBox) GetPosition() mgl32.Vec2
- func (textbox *TextBox) Height() float32
- func (textbox *TextBox) ImmediateCursorDraw()
- func (textbox *TextBox) InsidePoint() (P Point)
- func (textbox *TextBox) IsClicked(xPos, yPos float64, button MouseClick)
- func (textbox *TextBox) IsNoop() bool
- func (textbox *TextBox) IsReleased(xPos, yPos float64, button MouseClick)
- func (textbox *TextBox) KeyRelease(key glfw.Key, withShift bool)
- func (textbox *TextBox) Load(menu *Menu, width, height float32, borderWidth int32) (err error)
- func (textbox *TextBox) MoveCursor(offset int)
- func (textbox *TextBox) NavigateAway() bool
- func (textbox *TextBox) NavigateTo()
- func (textbox *TextBox) OrthoToScreenCoord() (X1 Point, X2 Point)
- func (textbox *TextBox) SetColor(color mgl32.Vec3)
- func (textbox *TextBox) SetPosition(v mgl32.Vec2)
- func (textbox *TextBox) SetString(str string, argv ...interface{})
- func (textbox *TextBox) Type() FormatableType
- func (textbox *TextBox) Width() float32
- type TextBoxInteraction
Constants ¶
const ( FormatableLabel = 0 FormatableTextbox = 1 )
const ( MouseUnclicked MouseClick = iota MouseLeft MouseRight MouseCenter AlignCenter Alignment = 0 AlignRight = 1 AlignLeft = 2 ScreenCenter ScreenPosition = 0 ScreenTopLeft = 1 ScreenTopCenter = 2 ScreenTopRight = 3 ScreenLeft = 4 ScreenRight = 5 ScreenLowerLeft = 6 ScreenLowerCenter = 7 ScreenLowerRight = 8 ScreenPadding = float32(10) // used by screen positioning calculations )
Variables ¶
var IsDebug = false
Functions ¶
Types ¶
type Formatable ¶
type Formatable interface {
// perform click action as appropriate
// if formatable has no reasonable click action (TextBox) returns false
Follow() bool
// up/down key navigation
// is the this object something that can be interacted with by the user
IsNoop() bool
// rendering
GetPosition() mgl32.Vec2
SetPosition(v mgl32.Vec2)
GetPadding() Padding
Height() float32
Width() float32
Type() FormatableType
}
type FormatableType ¶
type FormatableType int
type Label ¶
type Label struct {
Config LabelConfig
Menu *Menu
Text *v41.Text
IsHover bool
IsClick bool
// public methods are expected to be defined by the user and run before the private method are called
// if a public method is undefined, it is skipped. Currently I have only defined onRelease as private.
OnClick LabelInteraction
StopOnRelease bool // set to true in order to prevent onRelease being called
OnRelease LabelInteraction
OnHover LabelInteraction
OnNotHover func()
// contains filtered or unexported fields
}
func (*Label) GetPadding ¶
func (*Label) GetPosition ¶
func (*Label) InsidePoint ¶
InsidePoint returns a point nearby the center of the label Used to locate a screen position where clicking can be simulated
func (*Label) IsClicked ¶
func (label *Label) IsClicked(xPos, yPos float64, button MouseClick)
IsClicked uses a bounding box to determine clicks
func (*Label) IsReleased ¶
func (label *Label) IsReleased(xPos, yPos float64, button MouseClick)
IsReleased is checked for all labels in a menu when mouseup occurs
func (*Label) NavigateAway ¶
NavigateAway if we end up needing to navigate away from this item then let the caller know because it might need that information. return value of 'true'
func (*Label) NavigateTo ¶
func (label *Label) NavigateTo()
func (*Label) OrthoToScreenCoord ¶
func (*Label) SetPosition ¶
func (*Label) Type ¶
func (label *Label) Type() FormatableType
type LabelAction ¶
type LabelAction int
const ( NOOP LabelAction = iota GOTO_MENU EXIT_MENU EXIT_GAME )
type LabelConfig ¶
type LabelConfig struct {
Padding Padding
Action LabelAction
Goto string
}
type LabelInteraction ¶
type LabelInteraction func( xPos, yPos float64, button MouseClick, isInBoundingBox bool, )
type Menu ¶
type Menu struct {
// parent MenuManager
*MenuManager
Name string
// trigger
OnShow func()
OnComplete func()
OnEnterRelease func()
// options
Defaults MenuDefaults
IsVisible bool
ShowOnKey glfw.Key
Height float32
Width float32
IsAutoCenter bool
// interactive objects
Font *v41.Font
Labels []*Label
TextBoxes []*TextBox
Formatable []Formatable // all labels and textboxes
// Up/Down keypress -> NavigationVia set to "Key"
// When in "Key", mouse navigation only happens once the mouse has been moved enough from LastMousePosition
LastMousePosition mgl32.Vec2
// opengl oriented
ScreenPosition ScreenPosition
Window *glfw.Window
WindowWidth float32
WindowHeight float32
// contains filtered or unexported fields
}
func NewMenu ¶
func NewMenu(window *glfw.Window, name string, font *v41.Font, defaults MenuDefaults, screenPosition ScreenPosition) (*Menu, error)
NewMenu creates a new menu object with a background centered on the screen or positioned using offsetBy
func (*Menu) MouseClick ¶
func (menu *Menu) MouseClick(xPos, yPos float64, button MouseClick)
func (*Menu) MouseHover ¶
func (*Menu) MouseRelease ¶
func (menu *Menu) MouseRelease(xPos, yPos float64, button MouseClick)
func (*Menu) NewLabel ¶
func (menu *Menu) NewLabel(str string, config LabelConfig) *Label
NewLabel handles spacing layout as defined on the menu level
func (*Menu) NewMenuTexture ¶
func (menu *Menu) NewMenuTexture(imagePath string, dimensions mgl32.Vec2) (mt *MenuTexture, err error)
NewMenuTexture accepts an image location and the internal dimensions of the smaller images embedded within the texture. The image will be subdivided into evenly spaced rectangles based on the dimensions given. This is very beta.
func (*Menu) NewTextBox ¶
NewTextBox handles vertical spacing
func (*Menu) ResizeWindow ¶
type MenuDefaults ¶
type MenuImage ¶
type MenuImage struct {
MenuTexture *MenuTexture
MenuTextureIndex int
// X1, X2: the lower left and upper right points of a box that bounds the text with a center point (0,0)
// lower left
X1 Point
// upper right
X2 Point
// Screen position away from center
Position mgl32.Vec2
// contains filtered or unexported fields
}
type MenuLogger ¶
func NewMenuLogger ¶
func NewMenuLogger(location string) (*MenuLogger, error)
func (*MenuLogger) Close ¶
func (nm *MenuLogger) Close() error
type MenuManager ¶
type MenuManager struct {
Font *v41.Font
StartKey glfw.Key // they key that, when pressed, will display the StartMenu
StartMenu string // the name passed to each NewMenu call
Menus map[string]*Menu
IsFinalized bool
}
func NewMenuManager ¶
func NewMenuManager(font *v41.Font, startKey glfw.Key, startMenu string) *MenuManager
NewMenuManager handles a tree of menus that interact with one another
func (*MenuManager) Draw ¶
func (mm *MenuManager) Draw() bool
func (*MenuManager) Finalize ¶
func (mm *MenuManager) Finalize(align Alignment) error
Finalize connects menus together and performs final formatting steps this must be run after all menus are prepared
func (*MenuManager) Hide ¶
func (mm *MenuManager) Hide()
func (*MenuManager) IsVisible ¶
func (mm *MenuManager) IsVisible() bool
func (*MenuManager) KeyRelease ¶
func (mm *MenuManager) KeyRelease(key glfw.Key, withShift bool)
func (*MenuManager) MouseClick ¶
func (mm *MenuManager) MouseClick(xPos, yPos float64, button MouseClick)
Clicked resolves menus that have been clicked
func (*MenuManager) MouseHover ¶
func (mm *MenuManager) MouseHover(xPos, yPos float64)
func (*MenuManager) MouseRelease ¶
func (mm *MenuManager) MouseRelease(xPos, yPos float64, button MouseClick)
func (*MenuManager) NewMenu ¶
func (mm *MenuManager) NewMenu(window *glfw.Window, name string, menuDefaults MenuDefaults, screenPosition ScreenPosition) (*Menu, error)
func (*MenuManager) Release ¶
func (mm *MenuManager) Release()
func (*MenuManager) SetText ¶
func (mm *MenuManager) SetText(name string, index int, text string) error
func (*MenuManager) Show ¶
func (mm *MenuManager) Show(name string) error
func (*MenuManager) Toggle ¶
func (mm *MenuManager) Toggle(name string) error
type MenuTexture ¶
type MenuTexture struct {
Menu *Menu
Dimensions mgl32.Vec2
OrthographicMatrix mgl32.Mat4
WindowWidth float32
WindowHeight float32
Image *image.NRGBA
// contains filtered or unexported fields
}
func (*MenuTexture) Release ¶
func (mt *MenuTexture) Release()
func (*MenuTexture) ResizeWindow ¶
func (mt *MenuTexture) ResizeWindow(width float32, height float32)
type MouseClick ¶
type MouseClick int
type Navigation ¶
type Navigation int
type ScreenPosition ¶
type ScreenPosition int
type TextBox ¶
type TextBox struct {
Menu *Menu
Text *v41.Text
Cursor *v41.Text
CursorIndex int // position of the cursor within the text
CursorBarFrequency int64 // how long does each flash cycle last (visible -> invisible -> visible)
MaxLength int
Time time.Time
IsEdit bool
IsClick bool
// user defined
OnClick TextBoxInteraction
OnRelease TextBoxInteraction
FilterRune func(r rune) bool
// X1, X2: the lower left and upper right points of a box that bounds the text
X1 Point
X2 Point
BorderWidth int32
Position mgl32.Vec2
// contains filtered or unexported fields
}
func (*TextBox) GetBoundingBox ¶
func (*TextBox) GetPadding ¶
func (*TextBox) GetPosition ¶
func (*TextBox) ImmediateCursorDraw ¶
func (textbox *TextBox) ImmediateCursorDraw()
func (*TextBox) InsidePoint ¶
InsidePoint returns a point nearby the center of the label Used to locate a screen position where clicking can be simulated Click on the right side in order to place the cursor to the very right of any text
func (*TextBox) IsClicked ¶
func (textbox *TextBox) IsClicked(xPos, yPos float64, button MouseClick)
func (*TextBox) IsReleased ¶
func (textbox *TextBox) IsReleased(xPos, yPos float64, button MouseClick)
func (*TextBox) MoveCursor ¶
func (*TextBox) NavigateAway ¶
func (*TextBox) NavigateTo ¶
func (textbox *TextBox) NavigateTo()
func (*TextBox) OrthoToScreenCoord ¶
func (*TextBox) SetPosition ¶
func (*TextBox) Type ¶
func (textbox *TextBox) Type() FormatableType
type TextBoxInteraction ¶
type TextBoxInteraction func( textbox *TextBox, xPos, yPos float64, button MouseClick, isInBoundingBox bool, )
