Skip to content

Commit

Permalink
copy/paste and access elements in App
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcoder04 committed Nov 29, 2022
1 parent 7852364 commit 59a29af
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,33 @@ App = {
LightColorscheme = {},
DarkColorscheme = {}
},
Interactions = {},
Data = {
Const = {},
Var = {}
}
}

-- register element and return its id
function App:AddElement(element)
table.insert(self._elements, element)
return #(self._elements)
end

-- execute a function as if it is running on an element
function App:ElementExec(id, callback)
if id > #(self._elements) or id < 1 or (not Lib.Internal.IsRunnable(callback)) then return end
return callback(self._elements[id])
end

function App:ElValGet(id, key)
if id > #(self._elements) or id < 1 then return end
return App._elements[id][key]
end

function App:ElValSet(id, key, val)
if id > #(self._elements) or id < 1 then return end
App._elements[id][key] = val
end

-- initialize colorscheme, is called after Lib.Colors.* is initialized
Expand Down
4 changes: 4 additions & 0 deletions events-system.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ function on.construction()
math.randomseed(timer:getMilliSecCounter())
timer.start(App.RefreshRate)

if Lib.Internal.IsRunnable(App.Interactions.Copy) then toolpalette.enableCopy(true) end
if Lib.Internal.IsRunnable(App.Interactions.Cut) then toolpalette.enableCut(true) end
if Lib.Internal.IsRunnable(App.Interactions.Paste) then toolpalette.enablePaste(true) end

if Lib.Internal.IsRunnable(init) then
init()
end
Expand Down
18 changes: 18 additions & 0 deletions events-user.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,21 @@ end
function on.help()
Lib.Internal.ShowAboutDialog()
end

function on.copy()
if Lib.Internal.IsRunnable(App.Interactions.Copy) then
clipboard.addText(App.Interactions.Copy())
end
end

function on.cut()
if Lib.Internal.IsRunnable(App.Interactions.Cut) then
clipboard.addText(App.Interactions.Cut())
end
end

function on.paste()
if Lib.Internal.IsRunnable(App.Interactions.Paste) then
App.Interactions.Paste(clipboard.getText())
end
end
8 changes: 8 additions & 0 deletions library/gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ function Lib.Gui.DrawFocusBox(x, y, w, h, gc)
gc:setColorRGB(0, 0, 0)
end

function Lib.Gui.GenTextField(label, x, y)
local tf = Components.Base.TextField:new()
tf.Label = label
tf.PosX = x
tf.PosY = y
return tf
end



-- mutiline string draw based on nSpaint GUI engine
Expand Down

0 comments on commit 59a29af

Please sign in to comment.