Skip to content

Commit a2ee4f6

Browse files
committed
Feather 0 Errors 0 Warnings 0 Suggestions
1 parent c681562 commit a2ee4f6

File tree

9 files changed

+72
-30
lines changed

9 files changed

+72
-30
lines changed

SimpleUI.yyp

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fonts/fSimpleUITitle/fSimpleUITitle.yy

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

objects/oSimpleUIDemo/Alarm_0.gml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/// @desc set self.fps
22

3-
self.fps = fps_real
3+
_fps = fps_real
44
alarm[0] = 8

objects/oSimpleUIDemo/Create_0.gml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
/// @desc
22

33
global.some_text = "Some big text"
4-
self.fps = -1
4+
_fps = -1
55
alarm[0] = 8
66

77
canvas = new SUICanvas([
88
new SUIText(room_width/2, room_height/2, SUIBind("global.some_text"),
99
{font: fSimpleUITitle, halign: fa_center, valign: fa_middle})
1010
])
1111

12-
canvas.appendChild(new SUIText(50, 50, SUIBind(".fps")))
12+
canvas.appendChild(new SUIText(50, 50, SUIBind("._fps")))
1313
canvas.appendChild(new SUIButton(200, 100, "Click me", function() { show_message_async("Clicked!") }))
1414
canvas.appendChild(new SUISprite(700, 50, sSimpleUIDemo, 0, {w: 200, h: 50}))
1515
canvas.appendChild(new SUITextInput(100, 400,,,SUIBind("global.some_text", "global.some_text"),"Enter the title"))
1616

17+
18+
var mx = SUIBind("mouse.x")
19+
var my = SUIBind("mouse.y")
20+
var mtext = SUIBind(function() { return "pos: " + string({x: mouse_x, y: mouse_y}) })
1721
canvas.appendChild(
1822
new SUIText(
1923
// follow mouse
20-
SUIBind("mouse.x"),
21-
SUIBind("mouse.y"),
22-
SUIBind(
23-
function() { return "pos: " + string({x: mouse_x, y: mouse_y}) }
24-
),
24+
mx,
25+
my,
26+
mtext,
2527
{
2628
hoverable: false
2729
}

scripts/SUITextBox/SUITextBox.gml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,17 @@ function SUITextInput(x, y, w = 192, h = 48, text = "", placeholder = "", props
2323
self.placeholder_element = undefined
2424

2525
init = function() {
26-
self.box_element = appendChild(new SUIBox(0, 0, get("w"), get("h"), props))
27-
self.text_element = appendChild(new SUIText(10, get("h")/2, SUIBind("self.text", "self.text"), props))
28-
self.cursor_element = appendChild(new SUISprite(190, get("h")/2, sSimpleUITextCursor, 0))
29-
self.placeholder_element = appendChild(new SUIText(10, get("h")/2, SUIBind("self.placeholder_text", "self.placeholder_text")))
26+
var bx = 0, by = 0, bw = get("w"), bh = get("h")
27+
self.box_element = appendChild(new SUIBox(bx, by, bw, bh, props))
28+
29+
var tx = 10, ty = get("h")/2
30+
self.text_element = appendChild(new SUIText(tx, ty, SUIBind("self.text", "self.text"), props))
31+
32+
var cx = 190, cy = get("h")/2
33+
self.cursor_element = appendChild(new SUISprite(cx, cy, sSimpleUITextCursor, 0))
34+
35+
var px = 10, py = get("h")/2
36+
self.placeholder_element = appendChild(new SUIText(px, py, SUIBind("self.placeholder_text", "self.placeholder_text")))
3037

3138
box_element.hoverable = false
3239
text_element.hoverable = false

scripts/SimpleUI/SimpleUI.gml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ global.__SUIEmptyFunction = function() {}
1010
// if the mouse goes > this away from the border of a button, it will be "unclicked"
1111
#macro SUI_CLICK_OFFSET 96
1212

13+
1314
global.sui_canvases = []
1415

1516
function SUICanvas(children = []) constructor {
@@ -42,7 +43,13 @@ function SUICanvas(children = []) constructor {
4243
element.onSelect()
4344
}
4445

46+
///@param {String} name
47+
///@returns {Any} value
4548
get = function(name) { return variable_struct_get(self, name) }
49+
50+
///@param {String} name
51+
///@param {Any} value
52+
///@returns {Undefined}
4653
set = function(name, value) { variable_struct_set(self, name, value) }
4754

4855
forEach = function(func, arr = self.children, parent = self) {
@@ -271,8 +278,23 @@ function SUIElement(x, y, props = {}, children = []) constructor {
271278
getX = function() { return self.canvas.calculateX(self, self.parent) }
272279
getY = function() { return self.canvas.calculateY(self, self.parent) }
273280

281+
282+
///@function
283+
///@desc you should call this function at the end of your custom UI elements' constructor
284+
///@param {Struct} props
285+
///@self {SUIElement}
286+
function SUILoadProps(props) {
287+
SUIInherit(self, global.SUI_DEFAULT_PROPS)
288+
if (variable_struct_exists(global.SUI_DEFAULT_ELEMENT_PROPS, self.__element_type))
289+
SUIInherit(self, global.SUI_DEFAULT_ELEMENT_PROPS[$ self.__element_type])
290+
SUIInherit(self, props)
291+
}
292+
274293
#region get/set
275294

295+
///@param {String} prop_name
296+
///@param {Any} default_value
297+
///@returns {Any} value
276298
get = function(prop_name, default_value = undefined) {
277299
var value = variable_struct_get(self, prop_name)
278300
while (is_struct(value) and instanceof(value) == "SUIBinding") {
@@ -284,6 +306,8 @@ function SUIElement(x, y, props = {}, children = []) constructor {
284306
else return value
285307
}
286308

309+
///@param {String} prop_name
310+
///@param {Any} value
287311
set = function(prop_name, value) {
288312
var old_value = variable_struct_get(self, prop_name)
289313
if(is_struct(old_value) and instanceof(old_value) == "SUIBinding") {
@@ -345,7 +369,13 @@ function SUIElement(x, y, props = {}, children = []) constructor {
345369
distanceToMouse = function() {
346370
var mx = SUIMouseX
347371
var my = SUIMouseY
348-
return SUIDistanceToRectangle(mx, my, self.get("left"), self.get("top"), self.get("right"), self.get("bottom"))
372+
373+
var left = self.get("left")
374+
var top = self.get("top")
375+
var right = self.get("right")
376+
var bottom = self.get("bottom")
377+
378+
return SUIDistanceToRectangle(mx, my, left, top, right, bottom)
349379
}
350380

351381

scripts/SimpleUIBinding/SimpleUIBinding.gml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
///@function SUIBind(_get, _set)
2+
///@param {Function|String} _get
3+
///@param {Function|String} _set
14
function SUIBind(_get = SUIEmptyFunction, _set = SUIEmptyFunction) {
25
// get = "global.something" or get = "oPlayer.username"
36
if is_string(_get) {

scripts/SimpleUIDefaultProps/SimpleUIDefaultProps.gml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,3 @@ global.SUI_DEFAULT_ELEMENT_PROPS = {
1414
//}
1515
// ...
1616
}
17-
18-
// you should call this function at the end of your custom UI elements' constructor
19-
function SUILoadProps(props) {
20-
SUIInherit(self, global.SUI_DEFAULT_PROPS)
21-
if (variable_struct_exists(global.SUI_DEFAULT_ELEMENT_PROPS, self.__element_type))
22-
SUIInherit(self, global.SUI_DEFAULT_ELEMENT_PROPS[$ self.__element_type])
23-
SUIInherit(self, props)
24-
}

scripts/SimpleUIUtils/SimpleUIUtils.gml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ function SUIDistanceToRectangle(px, py, x1, y1, x2, y2) {
1919

2020
#region Variable stuff
2121

22+
///@param {Struct} dest
23+
///@param {Struct} src
2224
function SUIInherit(dest, src) {
2325
var var_names = variable_struct_get_names(src)
2426
var names_len = variable_struct_names_count(src)
@@ -56,25 +58,28 @@ function SUIVarGet(scope, varname) {
5658
}
5759
}
5860

61+
///@function SUIVarSet(scope, varname, value)
62+
///@param {Any} scope
63+
///@param {String} varname
64+
///@param {Any} value
5965
function SUIVarSet(scope, varname, value) {
6066
if (is_undefined(argument[1])) {
6167
varname = argument[0]
6268
value = argument[1]
6369
scope = other
6470
}
71+
else {
72+
value = argument[2]
73+
}
6574

6675
if (scope == global) {
6776
variable_global_set(varname, value)
6877
}
78+
else if (is_struct(scope)) {
79+
variable_struct_set(scope, varname, value)
80+
}
6981
else {
70-
with(scope) {
71-
if (is_struct(self)) {
72-
variable_struct_set(self, varname, value)
73-
}
74-
else {
75-
variable_instance_set(self, varname, value)
76-
}
77-
}
82+
variable_instance_set(scope, varname, value)
7883
}
7984
}
8085

0 commit comments

Comments
 (0)