small frames-docs update

updated frames example
fixed bug in process for programs
This commit is contained in:
Robert Jelic
2023-07-05 15:49:52 +02:00
parent b794612017
commit 31cda3d672
2 changed files with 14 additions and 15 deletions

View File

@@ -6,6 +6,7 @@ local newPackage = dofile("rom/modules/main/cc/require.lua").make
function process:new(path, window, newEnv, ...) function process:new(path, window, newEnv, ...)
local args = {...} local args = {...}
newEnv = newEnv or {}
local newP = setmetatable({ path = path }, { __index = self }) local newP = setmetatable({ path = path }, { __index = self })
newP.window = window newP.window = window
window.current = term.current window.current = term.current

View File

@@ -83,19 +83,19 @@ when the focus gets lost we simply change the position to "parent.w"
As you can see we add :setZIndex(25) - this makes sure the sidebar frame is always more important than our normal sub frames. As you can see we add :setZIndex(25) - this makes sure the sidebar frame is always more important than our normal sub frames.
:setScrollable just makes the sidebar frame scrollable (in case you're adding more frames) :setScrollable just makes the sidebar frame scrollable (in case you're adding more frames)
]] ]]
local sidebar = main:addFrame():setBackground(colors.gray):setPosition("parent.w", 1):setSize(15, "parent.h"):setZIndex(25):setScrollable() local sidebar = main:addFrame():setBackground(colors.gray):setPosition("{parent.w}", 1):setSize(15, "{parent.h}"):setZIndex(25):setScrollable()
:onGetFocus(function(self) :onGetFocus(function(self)
self:setPosition("parent.w - (self.w-1)") self:setPosition("{parent.w - (self.w-1)}")
end) end)
:onLoseFocus(function(self) :onLoseFocus(function(self)
self:setPosition("parent.w") self:setPosition("{parent.w}")
end) end)
-- Once again we add 3 frames, the first one should be immediatly visible -- Once again we add 3 frames, the first one should be immediatly visible
local sub = { local sub = {
main:addFrame():setPosition(1, 1):setSize("parent.w", "parent.h"), main:addFrame():setPosition(1, 1):setSize("{parent.w}", "{parent.h}"),
main:addFrame():setPosition(1, 1):setSize("parent.w", "parent.h"):hide(), main:addFrame():setPosition(1, 1):setSize("{parent.w}", "{parent.h}"):hide(),
main:addFrame():setPosition(1, 1):setSize("parent.w", "parent.h"):hide(), main:addFrame():setPosition(1, 1):setSize("{parent.w}", "{parent.h}"):hide(),
} }
--This part of the code adds buttons based on the sub table. --This part of the code adds buttons based on the sub table.
@@ -104,7 +104,7 @@ for k,v in pairs(sub)do
sidebar:addButton():setText("Example "..k) -- creating the button and adding a name k is just the index sidebar:addButton():setText("Example "..k) -- creating the button and adding a name k is just the index
:setBackground(colors.black) :setBackground(colors.black)
:setForeground(colors.lightGray) :setForeground(colors.lightGray)
:setSize("parent.w - 2", 3) :setSize("{parent.w - 2}", 3)
:setPosition(2, y) :setPosition(2, y)
:onClick(function() -- here we create a on click event which hides ALL sub frames and then shows the one which is linked to the button :onClick(function() -- here we create a on click event which hides ALL sub frames and then shows the one which is linked to the button
for a, b in pairs(sub)do for a, b in pairs(sub)do
@@ -138,7 +138,6 @@ In this example, we will demonstrate how to create movable frames with a program
<details> <details>
<summary>Click here to show code</summary> <summary>Click here to show code</summary>
```lua ```lua
local basalt = require("basalt") local basalt = require("basalt")
@@ -150,19 +149,18 @@ local processes = {}
local function openProgram(path, title, x, y, w, h) local function openProgram(path, title, x, y, w, h)
local pId = id local pId = id
id = id + 1 id = id + 1
local f = main:addFrame() local f = main:addMovableFrame()
:setMovable()
:setSize(w or 30, h or 12) :setSize(w or 30, h or 12)
:setPosition(x or math.random(2, 12), y or math.random(2, 8)) :setPosition(x or math.random(2, 12), y or math.random(2, 8))
f:addLabel() f:addLabel()
:setSize("parent.w", 1) :setSize("{parent.w}", 1)
:setBackground(colors.black) :setBackground(colors.black)
:setForeground(colors.lightGray) :setForeground(colors.lightGray)
:setText(title or "New Program") :setText(title or "New Program")
f:addProgram() f:addProgram()
:setSize("parent.w", "parent.h - 1") :setSize("{parent.w-1}", "{parent.h - 2}")
:setPosition(1, 2) :setPosition(1, 2)
:execute(path or "rom/programs/shell.lua") :execute(path or "rom/programs/shell.lua")
@@ -171,7 +169,7 @@ local function openProgram(path, title, x, y, w, h)
:setText("X") :setText("X")
:setBackground(colors.black) :setBackground(colors.black)
:setForeground(colors.red) :setForeground(colors.red)
:setPosition("parent.w", 1) :setPosition("{parent.w-1}", 1)
:onClick(function() :onClick(function()
f:remove() f:remove()
processes[pId] = nil processes[pId] = nil
@@ -182,7 +180,7 @@ end
openProgram("rom/programs/fun/worm.lua") openProgram("rom/programs/fun/worm.lua")
main:addButton():setPosition("parent.w - 16", 2):setText("Open"):onClick(function() main:addButton():setPosition("{parent.w - 16}", 2):setText("Open"):onClick(function()
openProgram() openProgram()
end) end)
@@ -218,7 +216,7 @@ local function makeResizeable(frame, minW, minH, maxW, maxH)
maxW = maxW or 99 maxW = maxW or 99
maxH = maxH or 99 maxH = maxH or 99
local btn = frame:addButton() local btn = frame:addButton()
:setPosition("parent.w", "parent.h") :setPosition("{parent.w-1}", "{parent.h-1}")
:setSize(1, 1) :setSize(1, 1)
:setText("/") :setText("/")
:setForeground(colors.blue) :setForeground(colors.blue)