beGUI is a minimal customizable GUI system for Lua, and fully written in Lua.
Try it in browser.
Index
- Features
- Setup
- Reference
- License
"beGUI" implements:
- Placable, resizable, anchorable, and nestable
Widget
- Textual
Label
,MultilineLabel
,Url
,InputBox
Picture
- Clickable
Button
,PictureButton
CheckBox
,RadioBox
ComboBox
NumberBox
ProgressBar
,Slide
Group
- Scrollable
List
Draggable
andDroppable
Tab
Popup
,MessageBox
,QuestionBox
Custom
to make your own update function- And customizable by writing your own widget
- Navigation by key (or custom method)
Play live demo in browser.
beGUI is originally created to run within the Bitty Engine. The graphics primitives and input API is quite straightforward in Bitty Engine, it's possible to port it to other Lua-based environments with little twist, if that environment does rect(...)
, tex(...)
, text(...)
, mouse(...)
, etc.
- Clone this repository or download from releases
- Open "src" directly to run or copy everything under "src" to your own projects for Bitty Engine
beGUI implements a retained mode GUI system, it separates behaviour and appearance into widget classes and theme preference. Widgets are organized in tree hierarchies, each widget can have none or one parent, and none or multiple children. There are two phases of the lib, first to construct the hierarchy, second to update it. It enumerates from root widget to it's descendents during update, beGUI will handle internal states like visibility, click event, etc. then draw it properly with the theme preference during this procedure.
Most of the member functions return the widget object itself, it makes it easier to write internal DSL to construct full hierarchy in a tree style code.
require 'libs/beGUI/beGUI'
require 'libs/beGUI/beTheme'
local widgets = nil
local theme = nil
function setup()
local P = beGUI.percent -- Alias of percent.
widgets = beGUI.Widget.new()
:put(0, 0)
:resize(P(100), P(100))
:addChild(
beGUI.Label.new('beGUI demo')
:setId('label')
:anchor(0, 0)
:put(10, 10)
:resize(100, 23)
)
:addChild(
beGUI.Button.new('Button')
:setId('button')
:anchor(0, 0)
:put(10, 36)
:resize(100, 23)
:on('clicked', function (sender)
local lbl = widgets:find('label')
lbl:setValue('Clicked ' .. tostring(sender))
end)
)
theme = beTheme.default()
end
function update(delta)
cls(Color.new(255, 255, 255))
font(theme['font'].resource)
widgets:update(theme, delta)
font(nil)
end
Each widget has an anchor property which represents for the locating point in its local space, and a position property for either absolute or percentage position in its parent's space relatively. The final position is calculated according to these two properties. An anchor component is typically in range of values from 0.0 to 1.0, but it could be also less than 0.0 or greater than 1.0. A relative position component is typically in range of values from Percent(0)
to Percent(100)
, but it could be also less than Percent(0)
or greater than Percent(100)
.
Resources are splitted into nine grids evenly for flex scaled widgets.
Structures
These structures are used to help organizing widget layout.
beStructures.Percent
denotes relative value instead of absolute for positioning and sizing depending on its parent properties.
Model: require 'libs/beGUI/beGUI_Structures'
- beStructures.
Percent.new(amount)
: constructs aPercent
objectamount
: real number, no limit but often with range of values from 0 to 100
p.__mul(num)
: multiply thePercent
value with another numbernum
: the number to multiply- returns result number
Shortcut to create Percent
object.
Model: require 'libs/beGUI/beGUI'
- beGUI.
percent(amount)
: constructs aPercent
objectamount
: real number, no limit but often with range of values from 0 to 100- returns
Percent
Widget
Model: require 'libs/beGUI/beGUI'
-
beGUI.
Widget.new()
: constructs aWidget
object -
widget:setId(id)
: sets the ID of theWidget
; an ID is used to identify aWidget
from others for accessingid
: ID string- returns
self
-
widget:get(...)
: gets a childWidget
with the specific ID sequence...
: ID sequence of the full hierarchy path- returns the got
Widget
ornil
-
widget:find(id)
: finds the first matchedWidget
with the specific IDid
: ID string at any level of the hierarchy path- returns the found
Widget
ornil
-
widget:visible()
: gets the visibility of theWidget
- returns boolean for visibility
-
widget:setVisible(val)
: sets the visibility of theWidget
val
: whether it's visible- returns
self
-
widget:capturable()
: gets the capturability of theWidget
- returns boolean or string for capturability
-
widget:setCapturable(val)
: sets the capturability of theWidget
val
:true
,false
or'children'
- returns
self
-
widget:anchor(x, y)
: sets the anchor of theWidget
; anchor is used to calculate the offset when placingWidget
x
: x position of the anchor in local space as number, typically [0.0, 1.0] for [left, right], but it could be also less than 0.0 or greater than 1.0y
: y position of the anchor in local space as number, typically [0.0, 1.0] for [top, bottom], but it could be also less than 0.0 or greater than 1.0- returns
self
-
widget:offset()
: gets the offset of theWidget
- returns offset
x
,y
in world space
- returns offset
-
widget:put(x, y)
: sets the position of theWidget
x
: number for absolute position; orPercent
for relative position, typically with range of values fromPercent(0)
toPercent(100)
, but it could be also less thanPercent(0)
or greater thanPercent(100)
y
: number for absolute position; orPercent
for relative position, typically with range of values fromPercent(0)
toPercent(100)
, but it could be also less thanPercent(0)
or greater thanPercent(100)
- returns
self
-
widget:position()
: gets the position of theWidget
- returns position
x
,y
in local space
- returns position
-
widget:worldPosition()
: gets the position of theWidget
in world space- returns position
x
,y
in world space
- returns position
-
widget:resize(width, height)
: sets the size of theWidget
width
: number for absolute size; orPercent
for relative size, typically with range of values fromPercent(0.00...n)
toPercent(100)
, but it could be also greater thanPercent(100)
height
: number for absolute size; orPercent
for relative size, typically with range of values fromPercent(0.00...n)
toPercent(100)
, but it could be also greater thanPercent(100)
- returns
self
-
widget:size()
: gets the size of theWidget
- returns size
width
,height
- returns size
-
widget:alpha()
: gets the alpha value of theWidget
- returns transparency number, with range of values from 0 to 255
-
widget:setAlpha(val)
: sets the alpha value of theWidget
val
: number with range of value from 0 to 255, or nil for default (255)- returns
self
-
widget:getChild(idOrIndex)
: gets the child with the specific ID or indexidOrIndex
: ID string, or index number- returns the found child or nil
-
widget:insertChild(child, index)
: inserts a child before the specific indexchild
: the childWidget
to insert- returns
self
-
widget:addChild(child)
: adds a child to the end of the children listchild
: the childWidget
to add- returns
self
-
widget:removeChild(childOrIdOrIndex)
: removes a child with the specific child, or its ID or indexchild
: childWidget
, or its ID string, or index number- returns
self
-
widget:foreachChild(handler)
: iterates all children, and calls the specific handlerhandler
: the children handler in form offunction (child, index) end
- returns
self
-
widget:sortChildren(comp)
: sorts all children with the specific comparercomp
: the comparer in form offunction (left, right) end
- returns
self
-
widget:getChildrenCount()
: gets the count of all children- returns children count number
-
widget:clearChildren()
: clears all children- returns
self
- returns
-
widget:openPopup(content)
: opens a popupcontent
: the popup to open- returns
self
-
widget:closePopup()
: closes any popup- returns
self
- returns
-
widget:update(theme, delta, event = nil)
: updates theWidget
and its children recursivelytheme
: the theme to draw withdelta
: elapsed time since previous updateevent
: omit it for common usage, pass a prefilled event to prevent default event
-
widget:on(event, handler)
: registers the handler of the specific eventevent
: event name stringhandler
: callback function- returns
self
-
widget:off(event)
: unregisters the handlers of the specific eventevent
: event name string- returns
self
-
widget:navigatable()
: gets whether thisWidget
is navigatable- returns
'all'
for fully navigatable,nil
for non-navigatable,'children'
for children only,'content'
for content only
- returns
-
widget:navigate(dir)
: navigates through widgets, call this to perform key navigation, etc.dir
: can be one in'prev'
,'next'
,'press'
,'cancel'
-
widget:queriable()
: gets whether thisWidget
is queriable- returns
true
for queriable, otherwisefalse
- returns
-
widget:setQueriable(val)
: sets whether thisWidget
is queriableval
: whether thisWidget
is queriable- returns
self
-
widget:query(x, y)
: queries aWidget
at the specific positionx
: the x position to queryy
: the y position to query- returns the queried
Widget
ornil
-
widget:captured()
: gets whether thisWidget
has captured mouse event.- returns
true
for captured, otherwisefalse
- returns
-
widget:tween(t)
: schedules a tweening proceduret
: the tweening object- returns
self
-
widget:clearTweenings()
: clears all tweening procedures- returns
self
- returns
Basic Widgets
Model: require 'libs/beGUI/beGUI'
, implements beGUI.Widget
-
beGUI.
Label.new(content, alignment = 'left', clip_ = false, theme = nil, shadow = nil)
: constructs aLabel
with the specific contentcontent
: the content stringalignment
: one innil
,'left'
,'right'
,'center'
clip_
: whether to clip drawing outside thisWidget
's boundstheme
: custom themeshadow
: shadow theme for shadowed drawing
-
label:getValue()
: gets the content text- returns the content string
-
label:setValue(val)
: sets the content textval
: the specific content string- returns
self
-
label:alignment()
: gets the alignment- returns the alignment preference string
-
label:setAlignment(val)
: sets the alignment preferenceval
: the specific alignment preference string- returns
self
-
label:clipping()
: gets whether to clip drawing outside theWidget
's bounds- returns
true
for clipping, otherwisefalse
- returns
-
label:setClipping(val)
: sets whether to clip drawing outside theWidget
's boundsval
:true
to clip- returns
self
-
label:setTheme(theme, shadow = nil)
: sets the themetheme
: the custom themeshadow
: the custom shadow theme- returns
self
Model: require 'libs/beGUI/beGUI'
, implements beGUI.Widget
-
beGUI.
MultilineLabel.new(content, lineHeight = nil, alighment = 'left')
: constructs aMultilineLabel
with the specific contentcontent
: the content stringlineHeight
: the custom line heightalignment
: one innil
,'left'
,'right'
,'center'
-
multilinelabel:getValue()
: gets the content text- returns the content string
-
multilinelabel:setValue(val)
: sets the content textval
: the specific content string- returns
self
-
multilinelabel:lineHeight()
: gets the line height- returns the line height
-
multilinelabel:setLineHeight(val)
: sets the line heightval
: the specific line height- returns
self
-
multilinelabel:alignment()
: gets the alignment- returns the alignment preference string
-
multilinelabel:setAlignment(val)
: sets the alignment preference, the preference falls to'left'
if had set flex width totrue
val
: the specific alignment preference string- returns
self
-
multilinelabel:setTheme(theme, widgetTheme)
: sets the themetheme
: the custom font themewidgetTheme
: the custom widget theme- returns
self
-
multilinelabel:flexWidth()
: gets whether to calculateWidget
width automatically- returns
true
for calculating automatically, otherwisefalse
- returns
-
multilinelabel:setFlexWidth(val)
: sets whether to calculateWidget
width automaticallyval
:true
to calculate automatically- returns
self
-
multilinelabel:flexHeight()
: gets whether to calculateWidget
height automatically- returns
true
for calculating automatically, otherwisefalse
- returns
-
multilinelabel:setFlexHeight(val)
: sets whether to calculateWidget
height automaticallyval
:true
to calculate automatically- returns
self
-
multilinelabel:pattern()
: gets the word split pattern- returns the word split pattern string
-
multilinelabel:setPattern(val)
: sets the word split patternval
: the specific word split pattern- returns
self
-
multilinelabel:translator()
: gets the word translator- returns the word translator
-
multilinelabel:setTranslator(val)
: sets the word translatorval
: the specific word translator- returns
self
Model: require 'libs/beGUI/beGUI'
, implements beGUI.Widget
-
beGUI.
Url.new(content, alighment = 'left', clip_ = false, theme = nil)
: constructs aUrl
with the specific contentcontent
: the content stringalignment
: one innil
,'left'
,'right'
,'center'
clip_
: whether to clip drawing outside thisWidget
's boundstheme
: custom theme
-
url:getValue()
: gets the content text- returns the content string
-
url:setValue(val)
: sets the content textval
: the specific content string- returns
self
-
url:alignment()
: gets the alignment- returns the alignment preference string
-
url:setAlignment(val)
: sets the alignment preferenceval
: the specific alignment preference string- returns
self
-
url:clipping()
: gets whether to clip drawing outside theWidget
's bounds- returns
true
for clipping, otherwisefalse
- returns
-
url:setClipping(val)
: sets whether to clip drawing outside theWidget
's boundsval
:true
to clip- returns
self
-
url:setTheme(theme)
: sets the themetheme
: the custom theme- returns
self
-
url:on('clicked', function (sender) end)
: registers an event which will be triggered when theWidget
has been clicked- returns
self
- returns
Model: require 'libs/beGUI/beGUI'
, implements beGUI.Widget
-
beGUI.
InputBox.new(content placeholder)
: constructs an InputBox with the specific contentcontent
: the content stringplaceholder
: the placeholder string when there's no input yet
-
inputbox:getValue()
: gets the content text- returns the content string
-
inputbox:setValue(val)
: sets the content textval
: the specific content string
-
inputbox:setTheme(theme, placeholderTheme)
: sets the themetheme
: the custom font themeplaceholderTheme
: the custom placeholder theme- returns
self
-
inputbox:placeholder()
: gets the placeholder text- returns the placeholder string
-
inputbox:setPlaceholder(val)
: sets the placeholder textval
: the specific placeholder string- returns
self
-
inputbox:on('changed', function (sender, value) end)
: registers an event which will be triggered when theWidget
content text has been changed- returns
self
- returns
Model: require 'libs/beGUI/beGUI'
, implements beGUI.Widget
-
beGUI.
Picture.new(content, stretched = false, permeation = false)
: constructs a Picture with the specific contentcontent
: the contentTexture
stretched
: whether to use 9-grid-based splitting for stretchingpermeation
: whether to use permeation correction
-
picture:setValue(content, stretched = false, permeation = false)
: sets the contentTexture
content
: the contentTexture
- returns
self
-
picture:stretched()
: gets whether to use 9-grid-based splitting for stretching- returns
true
for 9-grid-based splitting, otherwisefalse
- returns
-
picture:setStretched(val)
: sets whether to use 9-grid-based splitting for stretchingval
:true
to use 9-grid-based splitting for stretching- returns
self
-
picture:permeation()
: gets whether to use permeation correction- returns
true
for permeation correction, otherwisefalse
- returns
-
picture:setPermeation(val)
: sets whether to use permeation correctionval
:true
to use permeation correction- returns
self
-
picture:color()
: gets the mask color of thePicture
- returns the mask color or
nil
- returns the mask color or
-
picture:setColor(val)
: sets the mask color of thePicture
val
: the specific mask color- returns
self
Model: require 'libs/beGUI/beGUI'
, implements beGUI.Widget
-
beGUI.
Button.new(content)
: constructs a Button with the specific contentcontent
: the content string
-
button:setValue(content)
: sets the content textval
: the specific content string
-
button:setTheme(theme, themeNormal, themeDown, themeDisabled)
: sets the themetheme
: the custom font themethemeNormal
: the custom theme for normal statethemeDown
: the custom theme for pressed statethemeDisabled
: the custom theme for disabled state- returns
self
-
button:enabled()
: gets whether thisWidget
is enabled- returns
true
for enabled, otherwisefalse
- returns
-
button:setEnabled(val)
: sets whether thisWidget
is enabledval
:true
for enabled, otherwisefalse
- returns
self
-
button:on('clicked', function (sender) end)
: registers an event which will be triggered when theWidget
has been clicked- returns
self
- returns
Model: require 'libs/beGUI/beGUI'
, implements beGUI.Widget
-
beGUI.
PictureButton.new(content, repeat_ = false, theme = nil, background = nil)
: constructs aPictureButton
with the specific contentcontent
: the contentTexture
repeat_
: whether to enable repeating eventtheme
: the custom themebackground
: optional, the custom backgroundTexture
-
picturebutton:setTheme(theme, widgetTheme)
: sets the themetheme
: the custom font themewidgetTheme
: the custom widget theme- returns
self
-
picturebutton:enabled()
: gets whether thisWidget
is enabled- returns
true
for enabled, otherwisefalse
- returns
-
picturebutton:setEnabled(val)
: sets whether thisWidget
is enabledval
:true
for enabled, otherwisefalse
- returns
self
-
picturebutton:on('clicked', function (sender) end)
: registers an event which will be triggered when theWidget
has been clicked- returns
self
- returns
Model: require 'libs/beGUI/beGUI'
, implements beGUI.Widget
-
beGUI.
CheckBox.new(content, value = false)
: constructs aCheckBox
with the specific contentcontent
: the content stringvalue
: the initial checked state
-
checkbox:getValue()
: gets whether thisWidget
is checked- returns
true
for checked, otherwisefalse
- returns
-
checkbox:setValue(val)
: sets whether thisWidget
is checkedval
:true
for checked, otherwisefalse
- returns
self
-
checkbox:setContent(val)
: sets the text content of thisWidget
val
: the content string- returns
self
-
checkbox:enabled()
: gets whether thisWidget
is enabled- returns
true
for enabled, otherwisefalse
- returns
-
checkbox:setEnabled(val)
: sets whether thisWidget
is enabledval
:true
for enabled, otherwisefalse
- returns
self
-
checkbox:on('changed', function (sender, value) end)
: registers an event which will be triggered when theWidget
checked state has been changed- returns
self
- returns
Model: require 'libs/beGUI/beGUI'
, implements beGUI.Widget
-
beGUI.
RadioBox.new(content, value = false)
: constructs aRadioBox
with the specific contentcontent
: the content stringvalue
: the initial checked state
-
radiobox:getValue()
: gets whether thisWidget
is checked- returns
true
for checked, otherwisefalse
- returns
-
radiobox:setValue(val)
: sets whether thisWidget
is checked; not recommended to call this manuallyval
:true
for checked, otherwisefalse
-
radiobox:setContent(val)
: sets the text content of thisWidget
val
: the content string- returns
self
-
radiobox:on('changed', function (sender, value) end)
: registers an event which will be triggered when theWidget
checked state has been changed- returns
self
- returns
Model: require 'libs/beGUI/beGUI'
, implements beGUI.Widget
-
beGUI.
ComboBox.new(content, value = nil)
: constructs aComboBox
with the specific contentcontent
: list of stringvalue
: the selected index number
-
combobox:getItemAt(index)
: gets the item text at the specific indexindex
: the specific index to get- returns got item string or
nil
-
combobox:addItem(item)
: adds an item string with the specific content textitem
the specific item text to add- returns
self
-
combobox:removeItemAt(index)
: removes the item at the specific indexindex
the specific index to remove- returns
true
for success, otherwisefalse
-
combobox:clearItems()
: clears all items- returns
self
- returns
-
combobox:getValue()
: gets the selected index- returns the selected index number
-
combobox:setValue(val)
: sets the selected indexval
: the specific selected index- returns
self
-
combobox:scrollable()
: gets whether can scroll the widget by mouse wheel- returns
true
for scrollable, otherwisefalse
- returns
-
combobox:setScrollable(val)
: sets whether can scroll the widget by mouse wheelval
:true
for allowing scrolling with a mouse wheel, otherwisefalse
- returns
self
-
combobox:on('changed', function (sender, value) end)
: registers an event which will be triggered when theWidget
selection state has been changed- returns
self
- returns
Model: require 'libs/beGUI/beGUI'
, implements beGUI.Widget
-
beGUI.
NumberBox.new(value, step, min = nil, max = nil, trim = nil, format = nil)
: constructs aNumberBox
with the specific valuevalue
: the initial value numberstep
: the changing stepmin
: the minumum limitmax
: the maximum limittrim
: optional, used to trim before value settingformat
: optional, used to format value for output
-
numberbox:getValue()
: gets the value number- returns the value number
-
numberbox:setValue(val)
: sets the value numberval
: the specific value number- returns
self
-
numberbox:getMinValue()
: gets the minimum limit number- returns the minimum limit number
-
numberbox:setMinValue(val)
: sets the minimum limit numberval
: the specific minimum limit number- returns
self
-
numberbox:getMaxValue()
: gets the maximum limit number- returns the maximum limit number
-
numberbox:setMaxValue(val)
: sets the maximum limit numberval
: the specific maximum limit number- returns
self
-
numberbox:step()
: gets the changing step- returns the changing step
-
numberbox:setStep(val)
: sets the changing stepval
: the specific changing step number- returns
self
-
numberbox:trim()
: gets the trim function- returns the trim function
-
numberbox:setTrim(val)
: sets the trim functionval
: the specific trim function- returns
self
-
numberbox:format()
: gets the format function- returns the format function
-
numberbox:setFormat(val)
: sets the format functionval
: the specific format function- returns
self
-
numberbox:setValueTheme(val)
: sets the value themeval
: the specific theme- returns
self
-
numberbox:scrollable()
: gets whether can scroll the widget by mouse wheel- returns
true
for scrollable, otherwisefalse
- returns
-
numberbox:setScrollable(val)
: sets whether can scroll the widget by mouse wheelval
:true
for allowing scrolling with a mouse wheel, otherwisefalse
- returns
self
-
numberbox:on('changed', function (sender, value) end)
: registers an event which will be triggered when theWidget
value has been changed- returns
self
- returns
Model: require 'libs/beGUI/beGUI'
, implements beGUI.Widget
-
beGUI.
ProgressBar.new(max, color, increasing = 'right')
: constructs aProgressBar
max
: the maximum valuecolor
: the color for the completed barincreasing
: indicates whether to increase from left to right, or reversed, one in'left'
,'right'
-
progressbar:getValue()
: gets the value number- returns the value number
-
progressbar:setValue(val)
: sets the value numberval
: the specific value number- returns
self
-
progressbar:getMaxValue()
: gets the maximum limit number- returns the maximum limit number
-
progressbar:setMaxValue(val)
: sets the maximum limit numberval
: the specific maximum limit number- returns
self
-
progressbar:getShadowValue()
: gets the shadow value number- returns the value number
-
progressbar:setShadowValue(val)
: sets the shadow value numberval
: the specific shadow value number- returns
self
-
progressbar:setTheme(theme)
: sets the themetheme
: the custom theme- returns
self
-
progressbar:on('changed', function (sender, value, maxValue, shadowValue) end)
: registers an event which will be triggered when theWidget
value has been changed- returns
self
- returns
Model: require 'libs/beGUI/beGUI'
, implements beGUI.Widget
-
beGUI.
Slide.new(value, min, max)
: constructs aSlide
with the specific valuevalue
: the initial value numbermin
: the minimum limit numbermax
: the maximum limit number
-
slide:getValue()
: gets the value number- returns the value number
-
slide:setValue(val)
: sets the value numberval
: the specific value number- returns
self
-
slide:getMinValue()
: gets the minimum limit number- returns the minimum limit number
-
slide:setMinValue(val)
: sets the minimum limit numberval
: the specific minimum limit number- returns
self
-
slide:getMaxValue()
: gets the maximum limit number- returns the maximum limit number
-
slide:setMaxValue(val)
: sets the maximum limit numberval
: the specific maximum limit number- returns
self
-
slide:scrollable()
: gets whether can scroll the widget by mouse wheel- returns
true
for scrollable, otherwisefalse
- returns
-
slide:setScrollable(val)
: sets whether can scroll the widget by mouse wheelval
:true
for allowing scrolling with a mouse wheel, otherwisefalse
- returns
self
-
slide:on('changed', function (sender, value) end)
: registers an event which will be triggered when theWidget
value has been changed- returns
self
- returns
Model: require 'libs/beGUI/beGUI'
, implements beGUI.Widget
-
beGUI.
Group.new(content)
: constructs aGroup
content
: the content string
-
group:getValue()
: gets the content text- returns the content string
-
group:setValue(val)
: sets the content textval
: the specific content string- returns
self
Container Widgets
Model: require 'libs/beGUI/beGUI'
, implements beGUI.Widget
-
beGUI.
List.new(withScrollBar = false)
: constructs aList
withScrollBar
: whether to draw scroll bar(s)
-
list:scrollableVertically()
: gets whether to allow scrolling vertically- returns
true
for allowing scrolling vertically, otherwisefalse
- returns
-
list:setScrollableVertically(val)
: sets whether to allow scrolling verticallyval
:true
for allowing scrolling vertically, otherwisefalse
- returns
self
-
list:scrollableHorizontally()
: gets whether to allow scrolling horizontally- returns
true
for allowing scrolling horizontally, otherwisefalse
- returns
-
list:setScrollableHorizontally(val)
: sets whether to allow scrolling horizontallyval
:true
for allowing scrolling horizontally, otherwisefalse
- returns
self
-
list:scrollSpeed()
: gets the scroll speed- returns the scroll speed
-
list:setScrollSpeed(val)
: sets the scroll speedval
: the specific scroll speed- returns
self
-
list:setTheme(theme)
: sets the themetheme
: the custom theme- returns
self
-
list:scrollable()
: gets whether can scroll the widget by mouse wheel- returns
true
for scrollable, otherwisefalse
- returns
-
list:setScrollable(val)
: sets whether can scroll the widget by mouse wheelval
:true
for allowing scrolling with a mouse wheel, otherwisefalse
- returns
self
Model: require 'libs/beGUI/beGUI'
, implements beGUI.Widget
- beGUI.
Draggable.new()
: constructs aDraggable
Model: require 'libs/beGUI/beGUI'
, implements beGUI.Widget
-
beGUI.
Droppable.new()
: constructs aDroppable
-
droppable:on('entered', function (sender, draggable) end)
: registers an event which will be triggered when theWidget
has been entered by aDraggable
- returns
self
- returns
-
droppable:on('left', function (sender, draggable) end)
: registers an event which will be triggered when theWidget
has been left by aDraggable
- returns
self
- returns
-
droppable:on('dropping', function (sender, draggable) return droppable end)
: registers an event which will be triggered when theWidget
has been hovering by aDraggable
- returns
self
- returns
-
droppable:on('dropped', function (sender, draggable) end)
: registers an event which will be triggered when theWidget
has been dropped by aDraggable
- returns
self
- returns
-
droppable:on('clicked', function (sender) end)
: registers an event which will be triggered when theWidget
has been clicked- returns
self
- returns
Model: require 'libs/beGUI/beGUI'
, implements beGUI.Widget
-
beGUI.
Tab.new()
: constructs aTab
-
tab:add(title)
: adds aTab
page with the specific titletitle
: theTab
page title to add- returns
self
-
tab:count()
: gets the page count of theTab
Widget
- returns the
Tab
page count
- returns the
-
tab:getValue()
: gets the active page index- returns the active page index number
-
tab:setValue(val)
: sets the active page indexval
: the specific page index- returns
self
-
tab:tabSize()
: gets the specifiedTab
size- returns the specified
Tab
size
- returns the specified
-
tab:setTabSize(val)
: sets the specifiedTab
sizeval
: the specifiedTab
size- returns
self
-
tab:scrollable()
: gets whether can scroll the widget by mouse wheel- returns
true
for scrollable, otherwisefalse
- returns
-
tab:setScrollable(val)
: sets whether can scroll the widget by mouse wheelval
:true
for allowing scrolling with a mouse wheel, otherwisefalse
- returns
self
-
tab:on('changed', function (sender, value) end)
: registers an event which will be triggered when theWidget
page has been switched- returns
self
- returns
Model: require 'libs/beGUI/beGUI'
, implements beGUI.Widget
- beGUI.
Popup.new()
: constructs aPopup
Model: require 'libs/beGUI/beGUI'
, implements beGUI.Popup
-
beGUI.
MessageBox.new(closable, title, message, confirm = 'OK')
: constructs aMessageBox
closable
:true
to enable the close button,false
to disabletitle
: the title textmessage
: the message textconfirm
: the text for the confirm button
-
messagebox:on('canceled', function (sender) end)
: registers an event which will be triggered when thePopup
has been canceled- returns
self
- returns
-
messagebox:on('confirmed', function (sender) end)
: registers an event which will be triggered when thePopup
has been confirmed- returns
self
- returns
Model: require 'libs/beGUI/beGUI'
, implements beGUI.Popup
-
beGUI.
QuestionBox.new(closable, title, messsage, confirm, deny)
: constructs aQuestionBox
closable
:true
to enable the close button,false
to disabletitle
: the title textmessage
: the message textconfirm
: the text for the confirm buttondeny
: the text for the deny button
-
questionbox:on('canceled', function (sender) end)
: registers an event which will be triggered when thePopup
has been canceled- returns
self
- returns
-
questionbox:on('confirmed', function (sender) end)
: registers an event which will be triggered when thePopup
has been confirmed- returns
self
- returns
-
questionbox:on('denied', function (sender) end)
: registers an event which will be triggered when thePopup
has been denied- returns
self
- returns
Custom Widget
There are two ways to customize your own Widget
, one is to use the beWidget.Custom
Widget
, the other is to write your own Widget
class.
The Custom
Widget
exposes a 'updated'
event to let you write short customized update routine in the callback.
Model: require 'libs/beGUI/beGUI'
, implements beGUI.Widget
-
beGUI.
Custom.new(name = 'Custom')
: constructs aCustom
Widget
name
: the customWidget
name used to perform__tostring
-
custom:name()
: gets the customWidget
name- returns the custom
Widget
name
- returns the custom
-
custom:setName(val)
: sets the customWidget
nameval
: the specific customWidget
name- returns
self
-
custom:on('updated', function (sender, x, y, w, h, delta, event) end)
: registers an event which will be triggered when theWidget
has been updated per frame- returns
self
- returns
You can also write your own Widget
inheriting from beWidget.Widget
.
local beClass = require 'libs/beGUI/beClass'
local beUtils = require 'libs/beGUI/beGUI_Utils'
local beWidget = require 'libs/beGUI/beGUI_Widget'
local MyWidget = beClass.class({
_value = nil, -- Define your fields.
_pressed = false,
ctor = function (self, ...)
beWidget.Widget.ctor(self)
-- Customize your constructor.
end,
__tostring = function (self)
return 'MyWidget'
end,
getValue = function (self) -- Define your properties.
return self._value
end,
setValue = function (self, val)
if self._value == val then
return self
end
self._value = val
self:_trigger('changed', self, self._value)
return self
end,
_update = function (self, theme, delta, dx, dy, event)
-- Ignore if invisible.
if not self.visibility then
return
end
-- Get the offset x, y, which is calculated by this widget's size and its anchor.
local ox, oy = self:offset()
-- Get the position x, y in local space.
local px, py = self:position()
-- Calculate the final position with the delta position, offset and local position,
-- where the delta position (`dx`, `dy`) is from this widget's parent, or 0, 0 for root widget.
local x, y = dx + px + ox, dy + py + oy
-- Get the size width, height of this widget.
local w, h = self:size()
-- The following code detects clicking.
local down = false
if event.context.active and event.context.active ~= self then
self._pressed = false
elseif event.canceled or event.context.dragging then
event.context.active = nil
self._pressed = false
elseif self._pressed then
down = event.mouseDown
else
-- Intersection detection.
down = event.mouseDown and Math.intersects(event.mousePosition, Rect.byXYWH(x, y, w, h))
end
if down and not self._pressed then
event.context.active = self
self._pressed = true
elseif not down and self._pressed then
event.context.active = nil
self._pressed = false
event.context.focus = self
self:_trigger('clicked', self) -- Trigger 'clicked' event by clicking.
elseif event.context.focus == self and event.context.navigated == 'press' then
self:_trigger('clicked', self) -- Trigger 'clicked' event by key navigation.
event.context.navigated = false
end
-- Draw the widget.
local elem = down and theme['button_down'] or theme['button'] -- Using the button theme.
beUtils.tex9Grid(elem, x, y, w, h, nil, self.transparency, nil) -- Draw texture.
beUtils.textCenter(self._value, theme['font'], x, y, w, h, elem.content_offset, self.transparency) -- Draw text.
-- Call base update to update its children.
beWidget.Widget._update(self, theme, delta, dx, dy, event)
end
}, beWidget.Widget)
Theme
Defined in "src/libs/beGUI/beTheme.lua". Widget classes will lookup for image resources, client area, content offset, fonts, colors and all other appearance preferences from it.
Tweening
beGUI is integrated with a tweening lib adapted from kikito/tween.lua, which allows to create tweening animations.
Model: require 'libs/beGUI/beGUI'
-
beGUI.
Tween.new(duration, subject, target, easing, loop)
: constructs aTween
objectduration
: the duration in secondssubject
: the tweening subjecttarget
: the tweening targeteasing
: the easing functionloop
: whether to loop the tweening
-
tween:reset()
: resets theTween
object- returns
self
- returns
-
tween:set(clock)
: sets theTween
object to a specific clock pointclock
: the click time point- returns
true
for success, otherwisefalse
-
tween:update(delta)
: updates theTween
object with a specific delta time in seconds- returns
true
for success, otherwisefalse
- returns
-
tween:on('changed', function (sender) end)
: registers an event which will be triggered when theTween
has been updated- returns
self
- returns
-
tween:on('completed', function (sender) end)
: registers an event which will be triggered when theTween
has completed or looped- returns
self
- returns
-
tween:off(event)
: unregisters the handlers of the specific eventevent
: event name string- returns
self
beGUI is distributed under the MIT license.