This is not intended as a serious project, but instead a way to quickly teach myself Go.
A basic openGL based GUI framework for desktop Golang applications.
- Window and Canvas
- Important Interface
- Constants
- Components
- Compositions
- Events
- Mouse Handler
- Key Handler
go get github.com/ryan-n-may/Gooi/gooi/
import gooi/base/windows
windows.NewWindow(title string, width, height float32) *intf.Window_Interface
Window Methods
(A *ApplicationWindow).CloseWindow() (A *ApplicationWindow).OpenWindow() (A *ApplicationWindow).RunWindow()(A *ApplicationWindow).SetWindow(w *glfw.Window) (A *ApplicationWindow).GetWindow() *glfw.Window(A *ApplicationWindow).SetWindowHeight(h float32) (A *ApplicationWindow).GetWindowHeight() float32(A *ApplicationWindow).SetWindowWidth(w float32) (A *ApplicationWindow).GetWindowWidth() float32(A *ApplicationWindow).SetBackgroundColour(colour [3]float32)(A *ApplicationWindow).SetResizable(r int) (A *ApplicationWindow).GetResizable() int(A *ApplicationWindow).SetWindowTitle(t string) (A *ApplicationWindow).GetWindowTitle() string(A *ApplicationWindow).SetOpenMethod(f func()) (A *ApplicationWindow).GetOpenMethod() func()(A *ApplicationWindow).SetCloseMethod(f func()) (A *ApplicationWindow).GetCloseMethod() func()(A *ApplicationWindow).SetWindowCanvas(c intf.Canvas_Interface) (A *ApplicationWindow).GetWindowCanvas() intf.Canvas_Interface(A *ApplicationWindow).SetMouseHandler(c intf.MouseHandler_Interface) (A *ApplicationWindow).GetWindowCanvas() intf.MouseHandler_Interface(A *ApplicationWindow).SetMouseHandler(c intf.MouseHandler_Interface) (A *ApplicationWindow).GetWindowCanvas() intf.MouseHandler_Interface
import gooi/base/components
components.NewCanvas(window intf.Window_Interface) *Canvas_Struct
Canvas Methods
(c *Canvas_Struct).AddDisplayable(a intf.Displayable) (c *Canvas_Struct).GetDisplayable(a intf.Displayable) (c *Canvas_Struct).SetDisplayable(a intf.Displayable)(c *Canvas_Struct).CountComponents() int(c *Canvas_Struct).RefreshCanvas() (c *Canvas_Struct).Redraw() (c *Canvas_Struct).Draw()
- Refresh: selects corrent openGL program, clears the openGL screen, calles Draw() and swaps buffers.
- Redraw: called Redraw() on all displayables.
- Draw: called Draw() on all displayables
(c *Canvas_Struct).CompileCanvasShader(source string, shaderType uint32) uint32(c *Canvas_Struct).SetBackgroundColour(colour [3]float32)(c *Canvas_Struct).GetPrograms() uint32(c *Canvas_Struct).GetEventHandler() intf.EventHandler_Interface (c *Canvas_Struct).SetEventHandler(intf.EventHandler_Interface)(c *Canvas_Struct).GetWindow() intf.Window_Interface (c *Canvas_Struct).SetWindow(intf.Window_Interface)(c *Canvas_Struct).GetWidth() float32 (c *Canvas_Struct).GetHeight() float32(c *Canvas_Struct).SetPos(x, y, z float32) (c *Canvas_Struct).GetPos() (float32, float32, float32)
- GetPos always returns 0, 0, 0 as the canvas is at the root of the ApplicationWindow.
(c *Canvas_Struct).GetMasterStruct() intf.Displayable (c *Canvas_Struct).SetMasterStruct(intf.Displayable)
import gooi/interfaces
All displayable structs implement the intf.Displayable
interface. This includes compositions
and components
. The interface methods are as follows:
(i intf.Displayable).SetPos(float32, float32, float32)
(i intf.Displayable).GetPos() (float32, float32, float32)
(i intf.Displayable).GetWidth() float32
(i intf.Displayable).GetHeight() float32
(i intf.Displayable).GetMasterStruct() intf.Displayable
(i intf.Displayable).SetMasterStruct() intf.Displayable
(i intf.Displayable).Draw()
(i intf.Displayable).Redraw()
Anything that is composed of the clickable struct in the foundation package implements the clickable interface.
(c intf.Clickable).GetClickableBounds() (x_min float32, x_max float32, y_min float32, y_max float32, z float32)
(c intf.Clickable).Click(click_alive *bool, press_action int, x float32, y float32, glfw.ModifierKey)
Anything that is composed of the drawable struct in the foundation package implements the drawable interface.
(d intf.Drawable).SetXYZ([]float32)
(d intf.Drawable).GetXYZ() []float32
(d intf.Drawable).SetRGB([]float32)
(d intf.Drawable).GetRGB() []float32
(d intf.Drawable).SetDIM([]float32)
(d intf.Drawable).GetDIM() []float32
(d intf.Drawable).SetVAO([]intf.Drawing)
(d intf.Drawable).GetVAO() []intf.Drawing
(d intf.Drawable).GetWidth() float32
(d intf.Drawable).GetHeight() float32
import "gooi/base/constants"
const (
// Mouse click pressed conditions
MOUSE_RELEASED = 0
MOUSE_PRESSED = 1
NO_CHANGE = 2
// Orientation of ratio button component
VERTICAL_ORIENT = 3
HORISONT_ORIENT = 4
// Box alignment constants
ALIGN_CENTRE = 5
ALIGN_TOP_CENTRE = 6
ALIGN_BOTTOM_CENTRE = 7
ALIGN_TOP_LEFT = 8
ALIGN_TOP_RIGHT = 9
ALIGN_BOTTOM_LEFT = 10
ALIGN_BOTTOM_RIGHT = 11
ALIGN_CENTRE_LEFT = 12
ALIGN_CENTRE_RIGHT = 13
// Column alignment constants
ALIGN_LEFT = 14
ALIGN_RIGHT = 15
ALIGN_CENTRE_COLUMN = 16
// Row alignment constants
ALIGN_TOP = 17
ALIGN_BOTTOM = 18
ALIGN_CENTRE_ROW = 19
// Rectangle constants
FILL_MASTER_DIMENSIONS = 20
NO_FILL = 21
MATCH_MASTER_POSITION = 22
NO_MATCH_POSITION = 23
)
import "gooi/base/colours"
var (
WHITE
BLACK
BLUE
DARK_BLUE
LIGHT_BLUE
GRAY
DARK_GRAY
LIGHT_GRAY
GREEN
RED
NONE
)
Gooi components are displayable structs that can be placed on the canvas to achieve some functionality or communicate some information.
These components are based upon the foundation structs (see foundation package in source). These foundations implement compositional structs for "Clickable", "Animation", "Drawable", "Input", and "Writing". These labels are largely self explanatory.
- "Clickable" handles the triggering and assigning of events to clickable areas.
- "Animation" handles the execution of animation-specific functions with time-delay.
- "Drawable" handles the generation of openGL graphics.
- "Input" handles the implementation of editable text input-fields.
- "Writing" handles the implementation of text (using the GLtext package).
The implementation of these compositional structs are listed for each of the displayable components in this section.
The Button composition is composed of the Animation, Clickable, Drawable, and Writing compositional structs.
Button struct
type Button struct {
canvas intf.Canvas_Interface
masterStruct intf.Displayable
componentName string
radius float32
posX, posY, posZ float32
masterWidth, masterHeight float32
slaveWidth, slaveHeight float32
openGLWindowWidth, openGLWindowHeight float32
animationFunctions []func()
clickable *foundation.Clickable
drawable *foundation.Drawable
writing *foundation.Writing
animation *foundation.Animation
buttonBodyColour [3]float32
}
components.NewButton(intf.Canvas_Interface, MasterStruct intf.Displayable, Name string, Width, Height, Radius, PosX, PosY, PosZ float32, FontName, FontPath string, FontSize int, ButtonEvent *event.Event_Struct, AniamtionTime time.Duration)
- "Radius" refers to the radius of the rounded corners of the button.
- PosX, PosY, and PosZ may be set to 0 if component is arranged inside a compositional structure.
The Label composition implements the Writing compositional struct.
Label struct
type Label struct {
canvas intf.Canvas_Interface
masterStruct intf.Displayable
name string
posX, posY, posZ float32
masterWidth, masterHeight float32
slaveWidth, slaveHeight float32
openGLWindowWidth float32
openGLWindowHeight float32
writing *foundations.Writing
}
components.NewLabel(intf.Canvas_Interface, MasterStruct intf.Displayable, Name string, PosX, PosY, PosZ float32, FontName, FontPath string, FontSize int)
The CheckBox composition is composed of the Drawable, Clickable, Writing, and Animation compositional structs.
CheckBox struct
type CheckBox struct {
canvas intf.Canvas_Interface
masterStruct intf.Displayable
name string
radius, posX, posY, posZ float32
openGLWindowWidth float32
openGLWindowHeight float32
filledColour [3]float32
filledState bool
masterWidth, masterHeight float32
slaveWidth, slaveHeight float32
clickable *foundations.Clickable
animation *foundations.Animation
drawable *foundations.Drawable
writing *foundations.Writing
animationFunctions []func()
}
components.NewCheckBox(intf.Canvas_Interface, MasterStruct intf.Displayable, Name string, Radius, PosX, PosY, PosZ float32, CheckEvent *event.Event_Struct, FontName, FontPath string, FontSize int)
- Here "Radius" refers to the literal radius of the circular checkbox.
- PosX, PosY, and PosZ may be set to 0 if component is arranged inside a compositional structure.
The Rectangle composition is composed of the Drawable compositional struct.
Rectangle struct
type Rectangle struct {
canvas intf.Canvas_Interface
masterStruct intf.Displayable
name string
colour [3]float32
posX, posY, posZ, Radius float32
openGLWindowWidth float32
openGLWindowHeight float32
masterWidth, masterHeight float32
slaveWidth, slaveHeight float32
drawable *foundations.Drawable
fillStyle, positionStyle int
}
components.NewRectangle(intf.Canvas_Interface, MasterStruct intf.Displayable, Name string, Width, Height, PosX, PosY, PosZ, Radius float32, Colour [3]float32, FillStyle, PositionStyle integer)
- FillStyle and PositionStyle are integer constants (see constant section of this readme / constants package in source).
- constants dictate whether the rectangle immitates the position and dimensions of the MasterStruct.
- PosX, PosY, and PosZ may be set to 0 if component is arranged inside a compositional structure.
The TextInput composition is composed of the Input struct. By extension, it is indirectly composed of the Drawable, Writing, and Clickable structs. Additionally, it explicitly implements the Writing struct via the input prompt (see TextInput struct).
TextInput struct
type TextInput struct {
canvas intf.Canvas_Interface
masterStruct intf.Displayable
name, placeholder string
inputbox *Rectangle
keylistener *listeners.KeyHandler_Struct
input *foundaitons.Input
prompt *foundaitons.Writing
posX, posY, posZ, Radius float32
masterWidth, masterHeight float32
slaveWidth, slaveHeight float32
}
components.NewTextInput(intf.Canvas_Interface, MasterStruct intf.Displayable, Name, Placeholder string, KeyListener *listeners.KeyHandler_Struct, Width, Height, PosX, PosY, PosZ, Radius float32, Colour [3]float32, FontName, FontPath string, FontSize int)
- Placeholder is the text present in the input field by default.
- Name is the text present in the text field prompt.
- Colour refers to the colour of the text field background rectangle.
The ToggleSwitch composition is composed of the Drawable, Animation, Writing, and Clickable compositional structs.
ToggleSwitch struct
type ToggleSwitch struct {
canvas intf.Canvas_Interface
masterStruct intf.Displayable
name, placeholder string
posX, posY, posZ float32
width, height float32
togglePos float32
openGLWindowWidth, openGLWindowHeight float32
masterWidth, masterHeight float32
slaveWidth, slaveHeight float32
fontName, fontPath string
fontSize int
toggleEvent *event.Event_Struct
toggleState bool
toggleColour [3]float32
writing *foundations.Writing
drawable *foundations.Drawable
clickable *foundations.Clickable
animation *foundations.Animation
}
components.NewToggle(intf.Canvas_Interface, MasterStruct intf.Displayable, Name string, Width, Height, PosX, PosY, PosZ, Radius float32, FontName, FontPath string, FontSize int, toggleEvent *event.Event_Struct)
- Simple composition that holds one
intf.Displayable
. - Alignment may be
constants.ALIGN_CENTRE
constants.ALIGN_TOP_CENTRE
/constants.ALIGN_BOTTOM_CENTRE
constants.ALIGN_TOP_LEFT
/constants.ALIGN_TOP_RIGHT
constants.ALIGN_BOTTOM_LEFT
/constants.ALIGN_BOTTOM_RIGHT
constants.ALIGN_CENTRE_LEFT
/constants.ALIGN_CENTRE_RIGHT
compositions.NewBoxComposition(name string, canvas intf.Canvas_Interface, masterStruct intf.Displayable, x, y, z, slaveWidthRatio, slaveHeightRatio float32, alignment int, colour [3]float32) *Box
slaveWidthRatio
andslaveHeightRatio
refers to a fractional proportion of the masterStruct dimensions.- ie:
(0.5, 0.5)
would indicate that the box composition takes up 1/4 of the masterStruct dimensisons.
- Stack composition is an extension of box that allows for multiple
intf.Displayable
structs to the displayed in the same composition, with unique alignments.
compositions.NewStackComposition(name string, canvas intf.Canvas_Interface, x, y, z slaveWidthRatio, slaveHeightRatio float32, alignment []int)
- alignments are constants defined in an array for each of the planned
intf.Displayables
to be added to the composition.
- The column composition organises
intf.Displayable
structs in a vertical stack. - the slaveWidth and slaveHeight of this composition are not defined explicity, but instead obtained via the addition of the slave dimensions of all composition displayables plus padding.
- Alignment can be stated as:
ALIGN_LEFT
ALIGN_RIGHT
ALIGN_CENTRE_COLUMN
compositions.NewColumnComposition(name string, canvas intf.Canvas_Interface, masterStruct intf.Displayable, x, y, z float32, alignment int)
- The row composition organises
intf.Displayable
structs in a horisontal line. - the slaveWidth and slaveHeight of this composition are not defined explicity, but instead obtained via the addition of the slave dimensions of all composition displayables plus padding.
- Alignment can be stated as:
ALIGN_TOP
ALIGN_BOTTOM
ALIGN_CENTRE_ROW
compositions.NewRowComposition(name string, canvas intf.Canvas_Interface, masterStruct intf.Displayable, x, y, z float32, alignment int)
- The tabbed composition allows for multiple box compositions to be switched between via the use of a row of selection buttons.
compositions.NewTabComposition(name string, canvas intf.Canvas_Interface, masterStruct intf.Displayable, eventHandler intf.EventHandler_Interface, mouseHandler intf.MouseHandler_Interface, labels []string, x, y, z, slaveWithRatio, slaveHeightRatio float32, font_name, font_path, font_size string)
import gooi/base/event
- in Gooi, events are handled by an event handler. Each program cycle, the event handler selects an event from the event queue, and executes the associated function.
- Selecting displayables that implement the clickable interface adds a given event to the event handler queue.
- Events are stored in a map which associates event names with function calls. The event queue stores event names only. For this reason all events must have unique names.
event.NewEventHandler() *EventHandler_Struct(c intf.Canvas_Interface).SetEventHandler(e *EventHandler_Struct)This is handled internally by displayables that implement the clickable interface.
(e *EventHandler_Struct).RegisterEventToHandler(ev intf.Event_Interface)This is handled internally by displayables that implement the clickable interface.
(e *EventHandler_Struct).AddEventToEventQueue(ev string)Handled internally by the window loop.
(e *EventHandler_Struct).ExecuteNextEvent()Pops event queue without executing
(e *EventHandler_Struct).SkipNextEvent()
event.NewEvent(name string, f func(intf.Paramaters_Interface), params intf.Paramaters_Interface) *event.Event_Struct(e *Event_Struct).SetName(s string) (e *Event_Struct).GetName() string(e *Event_Struct).SetMethod(f func(intf.Paramaters_Interface)) (e *Event_Struct).GetMethod() func(intf.Paramaters_Interface)(e *Event_Struct).SetParamaterStruct(p intf.Paramaters_Interface) (e *Event_Struct).GetParamaterStruct() intf.Paramaters_Interface
event.NewEventParamater(p any) intf.Paramaters_Interface(p *Event_Paramaters).SetParamaters(param any) (p *Event_Paramaters).GetParamaters() any
listeners.CreateMouseHandler(name string) *MouseHandler_Struct(c intf.Canvas_Interface).SetMouseHandler(ci intf.Clickable)
listeners.CreateKeyListener(name string, canvas intf.Canvas_Interface) *KeyHandler_Struct
- The key handler is not set to the canvas, but instead passed to editable components that implement the input compositional struct (layout package)