From e3de424f42e64e34a9a9ac3248f5c36fe96269cd Mon Sep 17 00:00:00 2001 From: Sabine Lim Date: Mon, 8 May 2023 01:57:14 +1000 Subject: [PATCH 1/6] Elaborate on onEvent documentation --- docs/objects/Object/onEvent.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/objects/Object/onEvent.md b/docs/objects/Object/onEvent.md index fd825af..f90d1a9 100644 --- a/docs/objects/Object/onEvent.md +++ b/docs/objects/Object/onEvent.md @@ -14,7 +14,7 @@ You can find a full list here: [CC:Tweaked](https://tweaked.cc/) (on the left si ### Usage -* Add an onEvent event to your frame: +Add an onEvent event to your frame: ```lua local basalt = require("basalt") @@ -26,3 +26,22 @@ main:onEvent(function(event, side, channel, replyChannel, message, distance) end end) ``` + +The parameters passed to this function are the same as those returned by `os.pullEvent()`. See [here](https://computercraft.info/wiki/Os.pullEvent) for more info. + +Alternatively, you can add an onEvent event to an XML layout: + +```xml + + local eventType = event[3] + local message = event[7] + if (eventType == "modem_message") then + basalt.debug("Message received: " .. tostring(message)) + end + +``` + +In this case, the event table indices correspond to: +* 1: The Object where this event is being handled +* 2: A string representing the Basalt event type. This will always just be the string `"other_event"` +* 3 onwards: the `os.pullEvent()` parameters From 2e65d14538902fdba217d5116fec40c6dafdaa93 Mon Sep 17 00:00:00 2001 From: Sabine Lim Date: Mon, 8 May 2023 02:04:16 +1000 Subject: [PATCH 2/6] Update onEvent.md --- docs/objects/Object/onEvent.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/objects/Object/onEvent.md b/docs/objects/Object/onEvent.md index f90d1a9..875472a 100644 --- a/docs/objects/Object/onEvent.md +++ b/docs/objects/Object/onEvent.md @@ -27,16 +27,17 @@ main:onEvent(function(event, side, channel, replyChannel, message, distance) end) ``` -The parameters passed to this function are the same as those returned by `os.pullEvent()`. See [here](https://computercraft.info/wiki/Os.pullEvent) for more info. +The parameters passed to this function are the same as those returned by `os.pullEvent()`. See [here](https://tweaked.cc/module/os.html#v:pullEvent) for more info. Alternatively, you can add an onEvent event to an XML layout: ```xml - local eventType = event[3] - local message = event[7] + local eventType = event[2] + if (eventType == "modem_message") then - basalt.debug("Message received: " .. tostring(message)) + local message = event[6] + basalt.debug("Message received: " .. message) end ``` From c084e9e5adc4576305f06261dce5c3745bd24e3e Mon Sep 17 00:00:00 2001 From: Robert Jelic <36573031+NoryiE@users.noreply.github.com> Date: Sun, 7 May 2023 18:11:53 +0200 Subject: [PATCH 3/6] Update onEvent.md --- docs/objects/Object/onEvent.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/objects/Object/onEvent.md b/docs/objects/Object/onEvent.md index 875472a..e4422be 100644 --- a/docs/objects/Object/onEvent.md +++ b/docs/objects/Object/onEvent.md @@ -44,5 +44,4 @@ Alternatively, you can add an onEvent event to an XML layout: In this case, the event table indices correspond to: * 1: The Object where this event is being handled -* 2: A string representing the Basalt event type. This will always just be the string `"other_event"` -* 3 onwards: the `os.pullEvent()` parameters +* 2, 3,...: the `os.pullEvent()` parameters From 2f09e12ec23f9155729da8061aff8668bef3a140 Mon Sep 17 00:00:00 2001 From: Sabine Lim Date: Mon, 8 May 2023 02:35:33 +1000 Subject: [PATCH 4/6] Add XML usage to schedule.md --- docs/objects/Basalt/schedule.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/objects/Basalt/schedule.md b/docs/objects/Basalt/schedule.md index 2ea0b7d..e946514 100644 --- a/docs/objects/Basalt/schedule.md +++ b/docs/objects/Basalt/schedule.md @@ -15,7 +15,7 @@ Schedules a function which gets called in a coroutine. After the coroutine is fi ### Usage -* Creates a schedule which switches the color between red and gray +Creates a schedule which switches the color between red and gray: ```lua local mainFrame = basalt.createFrame() @@ -34,3 +34,18 @@ aButton:onClick(basalt.schedule(function(self) self:setBackground(colors.gray) end)) ``` + +Usage in XML layout: + +```xml + +``` From 48ad4ad88e151dce12be3c5ecf4b8837e832cb52 Mon Sep 17 00:00:00 2001 From: Sabine Lim Date: Mon, 8 May 2023 02:45:53 +1000 Subject: [PATCH 5/6] Add foreground XML parameter for VisualObjects --- Basalt/plugins/xml.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Basalt/plugins/xml.lua b/Basalt/plugins/xml.lua index a214f33..072c64c 100644 --- a/Basalt/plugins/xml.lua +++ b/Basalt/plugins/xml.lua @@ -187,6 +187,7 @@ return { if(xmlValue("width", data)~=nil)then w = xmlValue("width", data) end if(xmlValue("height", data)~=nil)then h = xmlValue("height", data) end if(xmlValue("background", data)~=nil)then self:setBackground(colors[xmlValue("background", data)]) end + if(xmlValue("foreground", data)~=nil)then self:setForeground(colors[xmlValue("foreground", data)]) end if(xmlValue("script", data)~=nil)then @@ -762,4 +763,4 @@ return { return object end, -} \ No newline at end of file +} From 19d7fa9a61477d01b849ba0e4074c5c7f3519979 Mon Sep 17 00:00:00 2001 From: Sabine Lim Date: Mon, 8 May 2023 06:34:47 +1000 Subject: [PATCH 6/6] Add Flexbox-specific XML parameter support --- Basalt/plugins/xml.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Basalt/plugins/xml.lua b/Basalt/plugins/xml.lua index 072c64c..3fcb1dc 100644 --- a/Basalt/plugins/xml.lua +++ b/Basalt/plugins/xml.lua @@ -369,6 +369,19 @@ return { return object end, + Flexbox = function(base, basalt) + local object = { + setValuesByXMLData = function(self, data, scripts) + base.setValuesByXMLData(self, data, scripts) + if(xmlValue("flexDirection", data)~=nil)then self:setFlexDirection(xmlValue("flexDirection", data)) end + if(xmlValue("justifyContent", data)~=nil)then self:setJustifyContent(xmlValue("justifyContent", data)) end + if(xmlValue("spacing", data)~=nil)then self:setFlexDirection(xmlValue("spacing", data)) end + return self + end, + } + return object + end, + Button = function(base, basalt) local object = { setValuesByXMLData = function(self, data, scripts)