Skip to content

Commit e8b87e7

Browse files
committed
Update version and docs a bit
1 parent 5a4ea4e commit e8b87e7

File tree

5 files changed

+79
-26
lines changed

5 files changed

+79
-26
lines changed

README.md

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ You make an XML file that contains your GUI definition, just like single file co
55
A root Layout element is mandatory.
66
```xml
77
<Layout>
8-
<Button @click="a_method('with a string arg')">Click me!</Button>
8+
<Button @click="add_button_margin(5)">Click me!</Button>
99
<Text forEach="element in collection">{{ element }}</Text>
1010
</Layout>
1111
<Style>
@@ -26,9 +26,12 @@ local render_gui = dofile_once("mods/your_mod_id/lib/EZGUI/EZGUI.lua").init("mod
2626
local data = {
2727
collection = { "Bloo", "Blaa", "Blee" },
2828
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
3235
end,
3336
}
3437

@@ -42,35 +45,35 @@ I've also managed to make it work in the `settings.lua` by bundling up all the n
4245

4346
# Currently existing Elements:
4447
## 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`.
4849

4950
## 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>`
5152
### Attributes:
5253
- `@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)`
5354

5455
## Image
5556
Render an image.
56-
### Properties:
57+
### Attributes:
5758
- `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
5961
## Slider
6062
Render a slider.
61-
### Properties:
63+
### Attributes:
6264
- `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
6468
## Text
6569
Render some text. Example `<Text>Hello</Text>`
6670

6771
## Input
6872
For getting user input. Example `<Input bind="name"></Input>`
69-
70-
### Properties:
73+
### Attributes:
7174
- `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
76+
- `allowed_characters`:string - Example: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
7477

7578
# Styling / Pseudo-CSS
7679
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
7982
- Class selector: `.classname`
8083
- Ancestor selector: `Layout Button`
8184
- Child selector: `Layout > Button`
85+
- Universal selector: `Layout > *`
8286

8387
And of course you can combine them like: `Layout.classname > Button Text.otherclass`
8488

8589
Margin and padding should work just like the CSS Box Model https://www.w3schools.com/css/css_boxmodel.asp
8690

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.
8894

8995
![alt text](www/assets/box_model.png "Title")

TODO.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
[ ] Text input element
21
[ ] Binding to mod settings
32
[ ] Extend function bindings by writing their content to a virtual file and dofile that and execute it inside context...?
43
[ ] Parse bound data like color = "#FFFFFF" and do it again whenever it changes?...
54
[ ] Create github workflow script to zip files and create a release when pushing a new tag
65
[ ] Create local script to zip files and create a release when setting a new tag
7-
[ ] setfenv/metatable magic for @click functions so `self` and `element` is available in the function
86
[ ] Layout item wrapping when exceeeding max size
97
[ ] support style setting on the element: <Element style="border: false">
108
[ ] Caching of data_context access?

changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
v0.2.0:
12
- Images now support the @click attribute to basically create an ImageButton
3+
- Add Input element
4+
- (Button): Change default style to 'border: true'
25
- BREAKING: Methods now automatically have access to 'self' (which is the data_context) and 'element' which is the element it was triggered on
36
- FIX: Button padding was no longer included in the click area
47

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ezgui",
3-
"version": "0.1.4",
3+
"version": "0.2.0",
44
"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 }",
55
"main": "build.js",
66
"directories": {

www/elementData.js

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const bool = typeof true;
22
const string = typeof "";
33
const number = typeof 0;
4+
const func = "function";
45
const loop_expression = "loop expression";
56
const color = "RGB(A) Hex Color #FFFFFF(FF)";
67
const direction = "horizontal | vertical";
@@ -36,31 +37,76 @@ local data_context = {
3637
},
3738
{
3839
name: "Layout",
39-
description: "Responsible for positioning items, either horizontally or vertically (set by the CSS property ^direction)",
40+
description: "Responsible for positioning items, either horizontally or vertically (set by the CSS property ^direction).",
4041
attributes: [{
4142
name: "debug",
4243
values: [
4344
[bool]
4445
],
45-
description: "Renders a debug overlay for padding and content"
46+
description: "Renders a debug overlay for padding and content."
4647
}]
4748
},
4849
{
4950
name: "Button",
50-
description: "Despite it's name it only supports text right now.",
51+
attributes: [{
52+
name: "@click",
53+
values: [ [func] ],
54+
}],
55+
description: "A text button. Its padding will be included in the clickable area.",
5156
},
5257
{
5358
name: "Image",
54-
description: "Can you guess what this does?",
59+
attributes: [{
60+
name: "scaleX",
61+
values: [ [number] ],
62+
},{
63+
name: "scaleY",
64+
values: [ [number] ],
65+
},
66+
{
67+
name: "@click",
68+
values: [ [func] ],
69+
}],
70+
description: "Renders an image. You can scale it using scaleX and scaleY attributes and add an @click listener to use it as an ImageButton.",
5571
},
5672
{
5773
name: "Slider",
58-
description: "I think you know what a slider is.",
74+
attributes: [{
75+
name: "min",
76+
values: [ [number] ],
77+
},{
78+
name: "max",
79+
values: [ [number] ],
80+
},
81+
{
82+
name: "precision",
83+
values: [ [number] ],
84+
description: "Number of digits to show after the decimal point."
85+
}],
86+
description: "A slider :)",
5987
},
6088
{
6189
name: "Text",
6290
description: "Self explanatory, really.",
6391
},
92+
{
93+
name: "Input",
94+
description: "An input element for entering text, is kinda buggy but there's nothing I can do about that, it's part of the Noita GUI API.",
95+
attributes: [{
96+
name: "max_length",
97+
values: [
98+
[number]
99+
],
100+
description: "Maximum number of allowed characters"
101+
},
102+
{
103+
name: "allowed_characters",
104+
values: [
105+
[string]
106+
],
107+
description: "Example: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
108+
}]
109+
},
64110
],
65111
// CSS Properties
66112
cssProperties: [
@@ -97,7 +143,7 @@ local data_context = {
97143
values: [
98144
{ types: [bool] },
99145
],
100-
description: "Toggles border rendering for certain elements like ^Layout and ^Button.",
146+
description: "Renders a border around an element.",
101147
},
102148
{
103149
name: "color",

0 commit comments

Comments
 (0)