Skip to content

Commit f20931a

Browse files
committed
Updated all documentation
1 parent c5d682a commit f20931a

14 files changed

Lines changed: 262 additions & 95 deletions

config.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
file = "./"
1+
file = {"./", exclude = {"penguingui.lua"}}
22
project = "PenguinGUI"
33
title = "PenguinGUI Reference"
44
merge = true

penguingui.lua

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -354,19 +354,19 @@ Binding.valueTable.__index = Binding.valueTable
354354

355355

356356
function Binding.valueTable:addValueListener(listener)
357-
self:addListener("value", listener)
357+
return self:addListener("value", listener)
358358
end
359359

360360
function Binding.valueTable:removeValueListener(listener)
361-
self:removeListener("value", listener)
361+
return self:removeListener("value", listener)
362362
end
363363

364364
function Binding.valueTable:addValueBinding(binding)
365-
self:addBinding("value", binding)
365+
return self:addBinding("value", binding)
366366
end
367367

368368
function Binding.valueTable:removeValueBinding(binding)
369-
self:removeBinding("value", binding)
369+
return self:removeBinding("value", binding)
370370
end
371371

372372
function Binding.valueTable:unbind()
@@ -476,6 +476,7 @@ function Binding.proxyTable:addListener(key, listener)
476476
listeners[key] = keyListeners
477477
end
478478
table.insert(keyListeners, listener)
479+
return listener
479480
end
480481

481482
function Binding.proxyTable:removeListener(key, listener)
@@ -496,6 +497,7 @@ function Binding.proxyTable:addBinding(key, binding)
496497
end
497498
table.insert(keyBindings, binding)
498499
binding:valueChanged(self[key], self[key])
500+
return binding
499501
end
500502

501503
function Binding.proxyTable:removeBinding(key, binding)
@@ -831,6 +833,7 @@ Binding.THEN = Binding.valueTable.THEN
831833
-- GUI.lua
832834
--------------------------------------------------------------------------------
833835

836+
834837
GUI = {
835838
components = {},
836839
mouseState = {},
@@ -932,11 +935,13 @@ Component.y = 0
932935
Component.width = 0
933936
Component.height = 0
934937

938+
935939
function Component:_init()
936940
self.children = {}
937941
self.offset = Binding.proxy({0, 0})
938942
end
939943

944+
940945
function Component:add(child)
941946
local children = self.children
942947
children[#children + 1] = child
@@ -1041,12 +1046,14 @@ end
10411046

10421047
Panel = class(Component)
10431048

1049+
10441050
function Panel:_init(x, y)
10451051
Component._init(self)
10461052
self.x = x
10471053
self.y = y
10481054
end
10491055

1056+
10501057
function Panel:add(child)
10511058
Component.add(self, child)
10521059
self:pack()
@@ -1061,10 +1068,12 @@ Frame.borderColor = "black"
10611068
Frame.borderThickness = 1
10621069
Frame.backgroundColor = "#232323"
10631070

1071+
10641072
function Frame:_init(x, y)
10651073
Panel._init(self, x, y)
10661074
end
10671075

1076+
10681077
function Frame:update(dt)
10691078
if self.dragging then
10701079
if self.hasFocus then
@@ -1208,6 +1217,7 @@ Label.listeners = {
12081217
}
12091218
}
12101219

1220+
12111221
function Label:_init(x, y, text, fontSize, fontColor)
12121222
Component._init(self)
12131223
fontSize = fontSize or 10
@@ -1219,6 +1229,7 @@ function Label:_init(x, y, text, fontSize, fontColor)
12191229
self:recalculateBounds()
12201230
end
12211231

1232+
12221233
function Label:recalculateBounds()
12231234
self.width = PtUtil.getStringWidth(self.text, self.fontSize)
12241235
self.height = self.fontSize
@@ -1249,6 +1260,7 @@ TextButton.listeners = {
12491260
}
12501261
}
12511262

1263+
12521264
function TextButton:_init(x, y, width, height, text, fontColor)
12531265
Button._init(self, x, y, width, height)
12541266
local padding = 2
@@ -1262,11 +1274,13 @@ function TextButton:_init(x, y, width, height, text, fontColor)
12621274
self:repositionLabel()
12631275
end
12641276

1277+
12651278
function TextButton:repositionLabel()
12661279
local label = self.label
12671280
label.x = (self.width - label.width) / 2
12681281
end
12691282

1283+
12701284
--------------------------------------------------------------------------------
12711285
-- TextField.lua
12721286
--------------------------------------------------------------------------------
@@ -1283,6 +1297,7 @@ TextField.defaultTextHoverColor = "#777777"
12831297
TextField.cursorColor = "white"
12841298
TextField.cursorRate = 1
12851299

1300+
12861301
function TextField:_init(x, y, width, height, defaultText)
12871302
Component._init(self)
12881303
self.x = x
@@ -1300,6 +1315,7 @@ function TextField:_init(x, y, width, height, defaultText)
13001315
self.mouseOver = false
13011316
end
13021317

1318+
13031319
function TextField:update(dt)
13041320
if self.hasFocus then
13051321
local timer = self.cursorTimer
@@ -1477,12 +1493,14 @@ function TextField:keyEvent(keyCode, pressed)
14771493
end
14781494
end
14791495

1496+
14801497
--------------------------------------------------------------------------------
14811498
-- Image.lua
14821499
--------------------------------------------------------------------------------
14831500

14841501
Image = class(Component)
14851502

1503+
14861504
function Image:_init(x, y, image, scale)
14871505
Component._init(self)
14881506
scale = scale or 1
@@ -1496,6 +1514,7 @@ function Image:_init(x, y, image, scale)
14961514
self.scale = scale
14971515
end
14981516

1517+
14991518
function Image:draw(dt)
15001519
local startX = self.x + self.offset[1]
15011520
local startY = self.y + self.offset[2]
@@ -1577,9 +1596,6 @@ end
15771596
function CheckBox:clickEvent(position, button, pressed)
15781597
if not pressed and self.pressed then
15791598
self.selected = not self.selected
1580-
if self.onSelect then
1581-
self:onSelect(self.selected)
1582-
end
15831599
end
15841600
self.pressed = pressed
15851601
return true
@@ -1591,6 +1607,9 @@ end
15911607

15921608
RadioButton = class(CheckBox)
15931609

1610+
1611+
1612+
15941613
function RadioButton:drawCheck(dt)
15951614
local startX = self.x + self.offset[1]
15961615
local startY = self.y + self.offset[2]
@@ -1619,19 +1638,9 @@ function RadioButton:select()
16191638
end
16201639
if selectedButton then
16211640
selectedButton.selected = false
1622-
if selectedButton.onSelect then
1623-
selectedButton:onSelect(false)
1624-
end
16251641
end
16261642

1627-
if not self.selected then
1628-
self.selected = true
1629-
if self.onSelect then
1630-
self:onSelect(self.selected)
1631-
end
1632-
else
1633-
self.selected = true
1634-
end
1643+
self.selected = not self.selected
16351644
end
16361645

16371646
function RadioButton:setParent(parent)

penguingui/Binding.lua

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
--- Add listeners or bindings to objects
1+
--- Adds listeners or bindings to objects.
22
-- @module Binding
33
-- @usage -- Add a listener to print whenever a value is changed.
44
-- local sometable = { a = "somevalue" }
@@ -23,7 +23,7 @@ Binding = setmetatable(
2323
}
2424
)
2525

26-
-- Proxy metatable to add listeners to a table.
26+
-- Proxy metatable to add listeners to a table
2727
Binding.proxyTable = {
2828
__index = function(t, k)
2929
local out = t._instance[k]
@@ -115,7 +115,6 @@ Binding.weakMetaTable = {
115115
__mode = "v"
116116
}
117117

118-
-- Functions available to a binding.
119118
Binding.valueTable = {}
120119

121120
Binding.valueTable.__index = Binding.valueTable
@@ -125,34 +124,34 @@ Binding.valueTable.__index = Binding.valueTable
125124

126125
--- Adds a listener to the value of this binding.
127126
-- @function addValueListener
128-
--
129127
-- @param listener The listener to add.
128+
-- @return The added listener.
130129
function Binding.valueTable:addValueListener(listener)
131-
self:addListener("value", listener)
130+
return self:addListener("value", listener)
132131
end
133132

134133
--- Removes a listener to the value of this binding.
135134
-- @function removeValueListener
136-
--
137135
-- @param listener The listener to remove.
136+
-- @return Whether a listener was removed.
138137
function Binding.valueTable:removeValueListener(listener)
139-
self:removeListener("value", listener)
138+
return self:removeListener("value", listener)
140139
end
141140

142141
--- Convenience method for adding a binding to "value"
143142
-- @function addValueBinding
144-
--
145143
-- @param binding The binding to add.
144+
-- @return The added binding.
146145
function Binding.valueTable:addValueBinding(binding)
147-
self:addBinding("value", binding)
146+
return self:addBinding("value", binding)
148147
end
149148

150149
--- Convenience method for removing a binding from "value"
151150
-- @function removeValueBinding
152-
--
153151
-- @param binding The binding to remove.
152+
-- @return Whether a binding was removed.
154153
function Binding.valueTable:removeValueBinding(binding)
155-
self:removeBinding("value", binding)
154+
return self:removeBinding("value", binding)
156155
end
157156

158157
--- Unbinds this binding, as well as anything bound to it.
@@ -258,7 +257,7 @@ function Binding.value(t, k)
258257
end
259258
end
260259

261-
--- A proxy to allow listeners & bindings to be attached
260+
--- A proxy to allow listeners & bindings to be attached.
262261
-- @type Proxy
263262

264263
--- Adds a listener to the specified key that is called when the key's value
@@ -273,6 +272,7 @@ end
273272
-- old is the old value of the key.
274273
-- new is the new value of the key.
275274
-- If the function changes the key's value, it should return the new value.
275+
-- @return The added listener.
276276
function Binding.proxyTable:addListener(key, listener)
277277
local listeners = self.listeners
278278
if not listeners then
@@ -285,6 +285,7 @@ function Binding.proxyTable:addListener(key, listener)
285285
listeners[key] = keyListeners
286286
end
287287
table.insert(keyListeners, listener)
288+
return listener
288289
end
289290

290291
--- Removes the first instance of the given listener from the given key.
@@ -293,17 +294,18 @@ end
293294
-- @param key The key the listener is attached to.
294295
-- @param listener The listener to remove.
295296
--
296-
-- @return A boolean for whether a listener was removed.
297+
-- @return Whether a listener was removed.
297298
function Binding.proxyTable:removeListener(key, listener)
298299
local keyListeners = self.listeners[key]
299300
return PtUtil.removeObject(keyListeners, listener) ~= -1
300301
end
301302

302303
--- Adds a binding to the specified key in this table.
303304
-- @function addBinding
304-
--
305+
--
305306
-- @param key The key to bind to.
306307
-- @param binding The binding to attach.
308+
-- @return The added binding.
307309
function Binding.proxyTable:addBinding(key, binding)
308310
local bindings = self.bindings
309311
if not bindings then
@@ -317,13 +319,15 @@ function Binding.proxyTable:addBinding(key, binding)
317319
end
318320
table.insert(keyBindings, binding)
319321
binding:valueChanged(self[key], self[key])
322+
return binding
320323
end
321324

322325
--- Removes a binding from a key in this table.
323326
-- @function removeBinding
324-
--
327+
--
325328
-- @param key The key to remove a binding from.
326329
-- @param binding The binding to remove.
330+
-- @return Whether a binding was removed.
327331
function Binding.proxyTable:removeBinding(key, binding)
328332
local keyBindings = self.bindings[key]
329333
return PtUtil.removeObject(keyBindings, binding) ~= -1

penguingui/CheckBox.lua

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22
-- @classmod CheckBox
33
-- @usage -- Create a checkbox that prints when it is checked
44
-- local checkbox = CheckBox(0, 0, 16)
5-
--
5+
-- checkbox:addListener("selected", function(t, k, old, new)
6+
-- print("The checkbox was " .. (new and "checked" or "unchecked"))
7+
-- end
68
CheckBox = class(Component)
9+
--- The color of the border of this checkbox.
710
CheckBox.borderColor = "#545454"
11+
--- The color of the checkbox.
812
CheckBox.backgroundColor = "black"
13+
--- The color of this checkbox when the mouse is over it.
914
CheckBox.hoverColor = "#1C1C1C"
15+
--- The color of the check.
1016
CheckBox.checkColor = "#C51A0B"
17+
--- The color of this checkbox when it is pressed.
1118
CheckBox.pressedColor = "#343434"
1219

1320
--- Constructor
@@ -63,6 +70,7 @@ function CheckBox:draw(dt)
6370
end
6471

6572
--- Draw the checkbox
73+
-- @param dt The time elapsed since the last draw.
6674
function CheckBox:drawCheck(dt)
6775
local startX = self.x + self.offset[1]
6876
local startY = self.y + self.offset[2]
@@ -81,9 +89,6 @@ end
8189
function CheckBox:clickEvent(position, button, pressed)
8290
if not pressed and self.pressed then
8391
self.selected = not self.selected
84-
if self.onSelect then
85-
self:onSelect(self.selected)
86-
end
8792
end
8893
self.pressed = pressed
8994
return true

0 commit comments

Comments
 (0)