You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<TextforEach="element in collection">{{ element }}</Text>
10
10
</Layout>
11
11
<Style>
@@ -26,9 +26,12 @@ local render_gui = dofile_once("mods/your_mod_id/lib/EZGUI/EZGUI.lua").init("mod
26
26
localdata= {
27
27
collection= { "Bloo", "Blaa", "Blee" },
28
28
button_margin=5,
29
-
-- Methods defined here can be used in @click, arg1 is the data_context itself, arg2 the element that was clicked, arg3 the first custom arg
30
-
a_method=function(data, element, arg1)
31
-
print(arg1)
29
+
-- Methods defined here can be used in @click, two variables will be available within these functions:
30
+
-- 'self', refering to the data_context and
31
+
-- 'element', the element that was clicked on
32
+
add_button_margin=function(amount)
33
+
print(element.name.." was clicked!")
34
+
self.button_margin=self.button_margin+amount
32
35
end,
33
36
}
34
37
@@ -42,35 +45,35 @@ I've also managed to make it work in the `settings.lua` by bundling up all the n
42
45
43
46
# Currently existing Elements:
44
47
## Layout
45
-
**The** element to handle layouting, can either layout child elements horizontally or vertically.
46
-
Also responsible for rendering a border, if you like.
47
-
- CSS Properties: `direction`
48
+
**The** element to handle layouting, can either layout child elements horizontally or vertically, depending on its CSS property `direction`.
48
49
49
50
## Button
50
-
Draws a button with text (probably also Images in the future) that you can click.
51
+
A button with text that you can click and execute functions. The text is determined by it's contents, e.g: `<Button @click="do_something()">Click me!</Button>`
51
52
### Attributes:
52
53
-`@click`:function a function to call. It uses a primitive lua function parser and therefore only supports a syntax like this: `function_name('a string', 5)`
53
54
54
55
## Image
55
56
Render an image.
56
-
### Properties:
57
+
### Attributes:
57
58
-`src`:string - The path to the image file
58
-
59
+
-`scaleX`:number - Stretch the image on the x axis
60
+
-`scaleY`:number - Stretch the image on the y axis
59
61
## Slider
60
62
Render a slider.
61
-
### Properties:
63
+
### Attributes:
62
64
-`bind` - The data context variable to bind to
63
-
65
+
-`min`:number
66
+
-`max`:number
67
+
-`precision`:number - Number of digits to show after the decimal point
64
68
## Text
65
69
Render some text. Example `<Text>Hello</Text>`
66
70
67
71
## Input
68
72
For getting user input. Example `<Input bind="name"></Input>`
69
-
70
-
### Properties:
73
+
### Attributes:
71
74
-`bind` - The data context variable to bind to
72
-
73
-
All element support the `padding`, `margin` properties.
75
+
-`max_length`:number - Maximum number of allowed characters
The framework uses a custom implementation of CSS based solely on my own assumptions on how CSS works. It tries to mimic it without meeting any official specifications. Because it's custom made, it only implements a small subset of selectors and only a handful of properties. There are no IDs, only classes.
@@ -79,11 +82,14 @@ The framework uses a custom implementation of CSS based solely on my own assumpt
79
82
- Class selector: `.classname`
80
83
- Ancestor selector: `Layout Button`
81
84
- Child selector: `Layout > Button`
85
+
- Universal selector: `Layout > *`
82
86
83
87
And of course you can combine them like: `Layout.classname > Button Text.otherclass`
84
88
85
89
Margin and padding should work just like the CSS Box Model https://www.w3schools.com/css/css_boxmodel.asp
86
90
87
-
Except that there's no border except for the Layout element, which has an optional fixed border style and width of 3.
91
+
There are also the CSS properties `width` and `height`, which only take effect if they're bigger than the elements calculated size.
92
+
Can be used to set the size of an element to a specific size, if the size is bigger than it's content, you can use `align_self_horizontal`
93
+
and `align_self_vertical` to align its content, kind of like `text-align` in real CSS, but also vertical.
Copy file name to clipboardExpand all lines: package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
{
2
2
"name": "ezgui",
3
-
"version": "0.1.4",
3
+
"version": "0.2.0",
4
4
"description": "You make an XML file that contains your GUI definition, just like single file components in Vue.js.\r A root Layout element is mandatory.\r ```xml\r <Layout>\r <Button @click=\"a_method('with a string arg')\">Click me!</Button>\r <Text forEach=\"element in collection\">{{ element }}</Text>\r </Layout>\r <Style>\r Layout {\r direction: vertical;\r padding: 2;\r }\r Layout > Button {\r margin: [button_margin]; // Can also databind to CSS properties!\r }\r </Style>\r ```\r Then in your init.lua you can render this GUI:\r ```lua\r -- Dofiling EZGUI.lua returns a table with an init function that you need to call and pass in the path to the library, which in turn will return a render function you can call to render a GUI\r local render_gui = dofile_once(\"mods/your_mod_id/lib/EZGUI/EZGUI.lua\").init(\"mods/your_mod_id/lib/EZGUI\")\r -- This is the data context table, here lives your data that you can bind to\r local data = {\r collection = { \"Bloo\", \"Blaa\", \"Blee\" },\r button_margin = 5,\r -- Methods defined here can be used in @click, arg1 is the data_context itself, arg2 the element that was clicked, arg3 the first custom arg\r a_method = function(data, element, arg1)\r print(arg1)\r end,\r }",
0 commit comments