ui_components = "src.ui.components"; -- Just imported to add the functionality
COLORS = "conf:COLOR_SCHEME";
-}
--- Responsible for containing and managing all
--- global-ish objects for the application
-class "Application" {
- init = function(self)
- ui_text.register_font("fonts/FiraCode-Regular", 16)
- ui_text.set_font("fonts/FiraCode-Regular", 16)
-
- self.ui = with(ui.make_element "root") {
- rect = Rectangle(0, 0, 0, 0);
- }
-
- self.scroller = with(ui.make_element "scrolling_area") {
- rect = Rectangle(0, 0, 1200, 900);
- background_color = COLORS.background;
- line_color = COLORS.dark_background;
- layer = 10;
- }
-
- ui.insert_child(self.ui, self.scroller)
-
- self.wasm = nil
- end;
-
- bootstrap = function(self)
- -- Sets all Love callbacks
- function love.filedropped(file) self:open_file(file:getFilename()) end
- function love.update(dt) self:update(dt) end
- function love.draw() self:draw() end
-
- function love.mousepressed(x, y, button) ui.mousepressed(self.ui, button, x, y) end
- function love.mousereleased(x, y, button) ui.mousereleased(self.ui, button, x, y) end
- function love.mousemoved(x, y, dx, dy) ui.mousemoved(self.ui, x, y, dx, dy) end
- function love.wheelmoved(dx, dy) ui.wheelmoved(self.ui, dx, dy) end
- function love.keypressed(key) ui.keypressed(self.ui, key) end
- function love.keyreleased(key) ui.keyreleased(self.ui, key) end
- function love.resize(w, h) ui.resize(self.ui, w, h) end
- end;
-
- open_file = function(self, path)
- local wasm_mod = wasm_decompile(path)
- wasm_mod = wasm_analyze(wasm_mod)
- self.wasm = wasm_mod
-
- -- Delete all old children
- for _, chld in ipairs(self.scroller.children) do
- chld.remove = true
- end
- ui.fire_propagating_event(self.scroller, "dummy")
+ globals = "src.globals";
+}
- local i = 0
- for _, func in ipairs(wasm_mod.funcs) do
- if not func.imported then
- ui.insert_child(self.scroller, with(ui.make_element("function_block", func, wasm_mod)) {
+function init()
+ ui_text.register_font("fonts/FiraCode-Regular", 16)
+ ui_text.set_font("fonts/FiraCode-Regular", 16)
+
+ globals.ui.root = with(ui.make_element "root") {
+ rect = Rectangle(0, 0, 0, 0);
+ }
+
+ globals.ui.scrolling_area = with(ui.make_element "scrolling_area") {
+ rect = Rectangle(0, 0, 1200, 900);
+ background_color = COLORS.background;
+ line_color = COLORS.dark_background;
+ layer = 10;
+ }
+
+ ui.insert_child(globals.ui.root, globals.ui.scrolling_area)
+end
+
+function bootstrap()
+ -- Sets all Love callbacks
+ function love.filedropped(file) open_file(file:getFilename()) end
+ love.update = update
+ love.draw = draw
+
+ function love.mousepressed(x, y, button) ui.mousepressed(globals.ui.root, button, x, y) end
+ function love.mousereleased(x, y, button) ui.mousereleased(globals.ui.root, button, x, y) end
+ function love.mousemoved(x, y, dx, dy) ui.mousemoved(globals.ui.root, x, y, dx, dy) end
+ function love.wheelmoved(dx, dy) ui.wheelmoved(globals.ui.root, dx, dy) end
+ function love.keypressed(key) ui.keypressed(globals.ui.root, key) end
+ function love.keyreleased(key) ui.keyreleased(globals.ui.root, key) end
+ function love.resize(w, h) ui.resize(globals.ui.root, w, h) end
+end
+
+function open_file(path)
+ globals.wasm_module = wasm_decompile(path)
+ globals.wasm_module = wasm_analyze(globals.wasm_module)
+
+ -- Delete all old children
+ for _, chld in ipairs(globals.ui.scrolling_area.children) do
+ chld.remove = true
+ end
+ ui.fire_propagating_event(globals.ui.scrolling_area, "dummy")
+
+ local i = 0
+ for _, func in ipairs(globals.wasm_module.funcs) do
+ if not func.imported then
+ ui.insert_child(
+ globals.ui.scrolling_area,
+ with(ui.make_element("function_block", func, globals.wasm_module)) {
rect = Rectangle(0, i * 22, 400, 400);
- layer = 30 - i
+ layer = #globals.wasm_module.funcs - i
})
- i = i + 1
- if i > 25 then break end
- end
+ i = i + 1
end
- end;
+ end
+end
- update = function(self, dt)
- if love.keyboard.isDown "escape" then
- love.event.quit()
- end
-
- ui.update(self.ui, dt)
- end;
+function update(dt)
+ if love.keyboard.isDown "escape" then
+ love.event.quit()
+ end
- draw = function(self)
- love.graphics.setBackgroundColor(0, 0, 0)
- love.graphics.clear()
+ ui.update(globals.ui.root, dt)
+end
- ui.draw(self.ui)
+function draw()
+ love.graphics.setBackgroundColor(0, 0, 0)
+ love.graphics.clear()
- love.graphics.setScissor()
- end;
-}
+ ui.draw(globals.ui.root)
--- Delay the execution of the init function
--- until everything has been imported and
--- resolved
-app = Application()
+ love.graphics.setScissor()
+end
return module {
- app
+ init = init;
+ bootstrap = bootstrap;
+ open_file = open_file;
}
return obj\r
end\r
\r
-function interface(fns)\r
- if type(fns) == "string" then\r
- local sub, super = fns:match "(%w+) +extends +(%w+)"\r
- if sub then fns = sub end\r
-\r
- if super then\r
- return helper(fns, super, interface)\r
- else\r
- local int = {}\r
- int = setmetatable(int, {\r
- __call = helper(fns, nil, interface);\r
-\r
- __index = function(_, super)\r
- return helper(fns, super, interface)\r
- end;\r
- })\r
- return int\r
- end\r
- end\r
-\r
- local int = {}\r
- for k, v in pairs(fns) do\r
- if type(v) == "string" then\r
- int[v] = function(self) end\r
- end\r
- end\r
-\r
- if fns.extends then\r
- for k, v in pairs(fns.extends) do\r
- if type(v) == "function" then\r
- int[k] = function(self) end\r
- end\r
- end\r
- end\r
-\r
- local mt = {\r
- __call = function(_, ...)\r
- error "Interfaces cannot be instatiated with a constructor"\r
- end;\r
- }\r
- int = setmetatable(int, mt)\r
-\r
- return int\r
-end\r
-\r
function match(var)\r
return function(tab)\r
local ran = false\r
Rectangle = "src.utils:Rectangle";
wasm_text = "src.wasm.text";
+ globals = "src.globals";
COLORS = "conf:COLOR_SCHEME";
}
end
local function_block = { extends = "drag_rect" }
-function function_block:init(wasm_function, wasm_mod)
+function function_block:init(wasm_function)
self.func = wasm_function
- self.mod = wasm_mod
- local header_text, body_text = wasm_text.generate_text_format(self.func, self.mod, COLORS)
+ local header_text, body_text = wasm_text.generate_text_format(self.func, globals.wasm_module, COLORS)
self.header_text = header_text
self.body_text = body_text
self.old_height = 400
self.resize_down = false
- self.canvas = love.graphics.newCanvas(800, 800)
+ self.canvas = love.graphics.newCanvas(1200, 1200)
self.redraw = true
end
if ui.focused == self and button == 2 then self.resize_down = false end
if ui.focused == self and button == 3 then
- ui.insert_child(self, with(ui.make_element "rect") {
- rect = Rectangle(50, 40, 80, 60);
+ ui.insert_child(self, with(ui.make_element "deletable_rect") {
+ rect = Rectangle(x, y, 80, 60);
color = { 1, 0, 0 };
})
end
drag_rect.mousemoved(self, x, y, dx, dy)
if self.resize_down then
- self.rect.w = math.min(800, math.max(100, x))
+ self.rect.w = math.min(1200, math.max(100, x))
if self.body_visible then
- self.rect.h = math.min(800, math.max(22, y))
+ self.rect.h = math.min(1200, math.max(22, y))
self.old_height = self.rect.h
end
self.redraw = true