Skip to content

Commit 1094a24

Browse files
committed
+Added a Group Widget.
*Updated the doc.
1 parent 3685db8 commit 1094a24

File tree

10 files changed

+212
-90
lines changed

10 files changed

+212
-90
lines changed

README.md

Lines changed: 84 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ Try it [in browser](https://paladin-t.github.io/begui/).
1313
* [2. Structures](#2-structures)
1414
* [beStructures.Percent](#bestructurespercent)
1515
* [beGUI.percent](#beguipercent)
16-
* [3. Widgets](#3-widgets)
16+
* [3. Widget](#3-widget)
1717
* [beGUI.Widget](#beguiwidget)
18+
* [4. Basic Widgets](#4-basic-widgets)
1819
* [beGUI.Label](#beguilabel)
1920
* [beGUI.MultilineLabel](#beguimultilinelabel)
2021
* [beGUI.Url](#beguiurl)
@@ -28,19 +29,21 @@ Try it [in browser](https://paladin-t.github.io/begui/).
2829
* [beGUI.NumberBox](#beguinumberbox)
2930
* [beGUI.ProgressBar](#beguiprogressbar)
3031
* [beGUI.Slide](#beguislide)
32+
* [beGUI.Group](#beguigroup)
33+
* [5. Container Widgets](#5-container-widgets)
3134
* [beGUI.List](#beguilist)
3235
* [beGUI.Draggable](#beguidraggable)
3336
* [beGUI.Droppable](#beguidroppable)
3437
* [beGUI.Tab](#beguitab)
3538
* [beGUI.Popup](#beguipopup)
3639
* [beGUI.MessageBox](#beguimessagebox)
3740
* [beGUI.QuestionBox](#beguiquestionbox)
38-
* [4. Theme](#4-theme)
39-
* [5. Tweening](#5-tweening)
40-
* [beGUI.Tween](#beguitween)
41-
* [6. Custom Widgets](#6-custom-widgets)
41+
* [6. Custom Widget](#6-custom-widget)
4242
* [beGUI.Custom](#beguicustom)
4343
* [Writing Your Own Widget](#writing-your-own-widget)
44+
* [7. Theme](#7-theme)
45+
* [8. Tweening](#8-tweening)
46+
* [beGUI.Tween](#beguitween)
4447
* [License](#license)
4548

4649
# Features
@@ -59,6 +62,7 @@ Try it [in browser](https://paladin-t.github.io/begui/).
5962
* `ComboBox`
6063
* `NumberBox`
6164
* `ProgressBar`, `Slide`
65+
* `Group`
6266
* Scrollable `List`
6367
* `Draggable` and `Droppable`
6468
* `Tab`
@@ -164,10 +168,10 @@ Shortcut to create `Percent` object.
164168

165169
</details>
166170

167-
## 3. Widgets
171+
## 3. Widget
168172

169173
<details open>
170-
<summary>Widgets</summary>
174+
<summary>Widget</summary>
171175

172176
### beGUI.Widget
173177

@@ -278,6 +282,13 @@ Shortcut to create `Percent` object.
278282
* `widget:clearTweenings()`: clears all tweening procedures
279283
* returns `self`
280284

285+
</details>
286+
287+
## 4. Basic Widgets
288+
289+
<details open>
290+
<summary>Basic Widgets</summary>
291+
281292
### beGUI.Label
282293

283294
**Model: `require 'libs/beGUI/beGUI'`, implements beGUI.`Widget`**
@@ -625,6 +636,26 @@ Shortcut to create `Percent` object.
625636
* `slide:on('changed', function (sender, value) end)`: registers an event which will be triggered when the `Widget` value has been changed
626637
* returns `self`
627638

639+
### beGUI.Group
640+
641+
**Model: `require 'libs/beGUI/beGUI'`, implements beGUI.`Widget`**
642+
643+
* beGUI.`Group.new(content)`: constructs a `Group`
644+
* `content`: the content string
645+
646+
* `group:getValue()`: gets the content text
647+
* returns the content string
648+
* `group:setValue(val)`: sets the content text
649+
* `val`: the specific content string
650+
* returns `self`
651+
652+
</details>
653+
654+
## 5. Container Widgets
655+
656+
<details open>
657+
<summary>Container Widgets</summary>
658+
628659
### beGUI.List
629660

630661
**Model: `require 'libs/beGUI/beGUI'`, implements beGUI.`Widget`**
@@ -730,51 +761,10 @@ Shortcut to create `Percent` object.
730761

731762
</details>
732763

733-
## 4. Theme
764+
## 6. Custom Widget
734765

735766
<details open>
736-
<summary>Theme</summary>
737-
738-
Defined in "src/libs/beGUI/beTheme.lua". Widget classes will lookup for image resources, client area, content offset, fonts, colors and all other appearance config from it.
739-
740-
</details>
741-
742-
## 5. Tweening
743-
744-
<details open>
745-
<summary>Tweening</summary>
746-
747-
beGUI is integrated with a tweening lib adapted from [kikito/tween.lua](https://github.com/kikito/tween.lua), which allows to create tweening animations.
748-
749-
### beGUI.Tween
750-
751-
**Model: `require 'libs/beGUI/beGUI'`**
752-
753-
* beGUI.`Tween.new(duration, subject, target, easing)`: constructs a `Tween` object
754-
* `duration`: the duration in seconds
755-
* `subject`: the tweening subject
756-
* `target`: the tweening target
757-
* `easing`: the easing function
758-
759-
* `tween:set(clock)`: sets the `Tween` object to a specific clock point
760-
* `clock`: the click time point
761-
* returns `true` for success, otherwise `false`
762-
* `tween:reset()`: resets the `Tween` object
763-
* returns `true` for success, otherwise `false`
764-
* `tween:update(delta)`: updates the `Tween` object with a specific delta time in seconds
765-
* returns `true` for success, otherwise `false`
766-
767-
* `tween:on('changed', function (sender) end)`: registers an event which will be triggered when the `Tween` has been updated
768-
* returns `self`
769-
* `tween:on('completed', function (sender) end)`: registers an event which will be triggered when the `Tween` has completed
770-
* returns `self`
771-
772-
</details>
773-
774-
## 6. Custom Widgets
775-
776-
<details open>
777-
<summary>Custom Widgets</summary>
767+
<summary>Custom Widget</summary>
778768

779769
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.
780770

@@ -849,6 +839,50 @@ local MyWidget = beClass.class({
849839

850840
</details>
851841

842+
## 7. Theme
843+
844+
<details open>
845+
<summary>Theme</summary>
846+
847+
Defined in "src/libs/beGUI/beTheme.lua". Widget classes will lookup for image resources, client area, content offset, fonts, colors and all other appearance config from it.
848+
849+
</details>
850+
851+
## 8. Tweening
852+
853+
<details open>
854+
<summary>Tweening</summary>
855+
856+
beGUI is integrated with a tweening lib adapted from [kikito/tween.lua](https://github.com/kikito/tween.lua), which allows to create tweening animations.
857+
858+
### beGUI.Tween
859+
860+
**Model: `require 'libs/beGUI/beGUI'`**
861+
862+
* beGUI.`Tween.new(duration, subject, target, easing)`: constructs a `Tween` object
863+
* `duration`: the duration in seconds
864+
* `subject`: the tweening subject
865+
* `target`: the tweening target
866+
* `easing`: the easing function
867+
868+
* `tween:reset()`: resets the `Tween` object
869+
* returns `self`
870+
* `tween:set(clock)`: sets the `Tween` object to a specific clock point
871+
* `clock`: the click time point
872+
* returns `true` for success, otherwise `false`
873+
* `tween:update(delta)`: updates the `Tween` object with a specific delta time in seconds
874+
* returns `true` for success, otherwise `false`
875+
876+
* `tween:on('changed', function (sender) end)`: registers an event which will be triggered when the `Tween` has been updated
877+
* returns `self`
878+
* `tween:on('completed', function (sender) end)`: registers an event which will be triggered when the `Tween` has completed
879+
* returns `self`
880+
* `tween:off(event)`: unregisters the handlers of the specific event
881+
* `event`: event name string
882+
* returns `self`
883+
884+
</details>
885+
852886
# License
853887

854888
beGUI is distributed under the MIT license.

docs/bitty.data

9.01 KB
Binary file not shown.

imgs/beGUI1.png

12 Bytes
Loading

imgs/beGUI2.png

17 Bytes
Loading

src/info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"title": "beGUI | Bitty Engine",
44
"description": "Tiny customizable GUI system for Bitty Engine",
55
"author": "Tony",
6-
"version": "1.3.1",
6+
"version": "1.4.0",
77
"genre": "LIB",
88
"url": "https://github.com/paladin-t/begui"
99
}

src/libs/beGUI/beGUI.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ end
4141
beGUI = beUtils.merge(
4242
beGUI,
4343
{
44-
version = '1.3.1',
44+
version = '1.4.0',
4545

4646
-- Data structure to represent relative number.
4747
percent = beStructures.percent,
@@ -94,6 +94,8 @@ beGUI = beUtils.merge(
9494
-- Events:
9595
-- 'changed': function (sender, value) end
9696
Slide = beBasics.Slide,
97+
-- Group widget.
98+
Group = beContainers.Group,
9799
-- List widget.
98100
List = beContainers.List,
99101
-- Draggable widget.

src/libs/beGUI/beGUI_Containers.lua

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,58 @@ local beWidget = require 'libs/beGUI/beGUI_Widget'
2929
Widgets.
3030
]]
3131

32+
local Group = beClass.class({
33+
ctor = function (self, content)
34+
beWidget.Widget.ctor(self)
35+
36+
self.content = content
37+
end,
38+
39+
__tostring = function (self)
40+
return 'Group'
41+
end,
42+
43+
-- Gets the group name.
44+
getValue = function (self)
45+
return self.content
46+
end,
47+
-- Sets the group name.
48+
setValue = function (self, val)
49+
self.content = val
50+
51+
return self
52+
end,
53+
54+
navigatable = function (self)
55+
return 'children'
56+
end,
57+
58+
_update = function (self, theme, delta, dx, dy, event)
59+
if not self.visibility then
60+
return
61+
end
62+
63+
local ox, oy = self:offset()
64+
local px, py = self:position()
65+
local x, y = dx + px + ox, dy + py + oy
66+
local w, h = self:size()
67+
68+
local elem = theme['group']
69+
local x_ = x + elem.content_offset[1]
70+
local w_, h_ = measure(self.content, theme['font'].resource)
71+
local black = Color.new(elem.color.r, elem.color.g, elem.color.b, self.transparency or 255)
72+
line(x, y + h_ * 0.5, x, y + h - 1, black)
73+
line(x, y + h - 1, x + w - 1, y + h - 1, black)
74+
line(x + w - 1, y + h_ * 0.5, x + w - 1, y + h - 1, black)
75+
line(x, y + h_ * 0.5, x_ - 2, y + h_ * 0.5, black)
76+
line(x_ + w_ + 2, y + h_ * 0.5, x + w - 1, y + h_ * 0.5, black)
77+
local elem_ = theme['group_title']
78+
beUtils.textCenter(self.content, theme['font'], x_, y, w_, h_, elem_.content_offset, self.transparency)
79+
80+
beWidget.Widget._update(self, theme, delta, dx, dy, event)
81+
end
82+
}, beWidget.Widget)
83+
3284
local List = beClass.class({
3385
_withScrollBar = false,
3486
_scrolledTimestamp = nil,
@@ -757,6 +809,7 @@ Exporting.
757809
]]
758810

759811
return {
812+
Group = Group,
760813
List = List,
761814
Draggable = Draggable,
762815
Droppable = Droppable,

src/libs/beGUI/beTheme.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ local function default()
186186
content_offset = nil
187187
},
188188

189+
['group'] = {
190+
resource = nil,
191+
color = Color.new(0, 0, 0),
192+
area = nil,
193+
content_offset = { 8, 0 }
194+
},
195+
['group_title'] = {
196+
content_offset = nil
197+
},
198+
189199
['list'] = {
190200
resource = Resources.load('imgs/panel_white.png'),
191201
color = Color.new(127, 127, 127, 128),

src/libs/beGUI/beTween.lua

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
MIT LICENSE
33
44
Copyright (c) 2014 Enrique García Cota, Yuichi Tateno, Emmanuel Oga
5+
Adapted by Tony for Bitty Engine
56
67
Permission is hereby granted, free of charge, to any person obtaining a
78
copy of this software and associated documentation files (the
@@ -436,6 +437,15 @@ end
436437
local Tween_idx = { }
437438
local Tween_mt = { __index = Tween_idx }
438439

440+
function Tween_idx:reset()
441+
self.initial = self.initial or copyTables({ }, self.target, self.subject)
442+
self.clock = 0
443+
copyTables(self.subject, self.initial)
444+
self.finished = false
445+
446+
return self
447+
end
448+
439449
function Tween_idx:set(clock)
440450
assert(type(clock) == 'number', "clock must be a positive number or 0")
441451

@@ -469,15 +479,6 @@ function Tween_idx:set(clock)
469479
return true
470480
end
471481

472-
function Tween_idx:reset()
473-
self.initial = self.initial or copyTables({ }, self.target, self.subject)
474-
self.clock = 0
475-
copyTables(self.subject, self.initial)
476-
self.finished = false
477-
478-
return self
479-
end
480-
481482
function Tween_idx:update(delta)
482483
assert(type(delta) == 'number', "delta must be a number")
483484

@@ -496,6 +497,21 @@ function Tween_idx:on(event, handler)
496497
return self
497498
end
498499

500+
function Tween_idx:off(event)
501+
if not event then
502+
return self
503+
end
504+
if self.events == nil then
505+
return self
506+
end
507+
if self.events[event] == nil then
508+
return self
509+
end
510+
self.events[event] = nil
511+
512+
return self
513+
end
514+
499515
function Tween_idx:trigger(event, ...)
500516
if not event then
501517
return nil

0 commit comments

Comments
 (0)