From 6b7de243bfb177ad37f6191f0602bd05f1f3d950 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Tue, 7 Apr 2020 17:11:05 -0500 Subject: [PATCH] Bug fixes and improvements --- app.lua | 48 +++++++++++++++++++++++++++++------------------ conf.lua | 2 +- src/ui.lua | 2 ++ src/wasm/text.lua | 2 +- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/app.lua b/app.lua index b45a755..47c7224 100644 --- a/app.lua +++ b/app.lua @@ -63,7 +63,7 @@ function drag_rect.mousepressed(self, button, x, y) ui.focus(self) if button == 1 then self.mouse_down = true end return true -end; +end function drag_rect.mousereleased(self, button, x, y) if button == 1 then self.mouse_down = false end @@ -80,7 +80,6 @@ function drag_rect.mousemoved(self, x, y, dx, dy) end end - local function_block = { extends = "drag_rect" } function function_block.init(self, wasm_function, wasm_mod) self.func = wasm_function @@ -121,7 +120,14 @@ end function function_block.mousereleased(self, button, x, y) drag_rect.mousereleased(self, button, x, y) - if button == 2 then self.resize_down = false 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); + color = { 1, 0, 0 }; + }) + end end function function_block.focus(self) @@ -166,6 +172,7 @@ function function_block.update(self, dt) end if love.keyboard.isDown "up" then self.scroll = self.scroll - 300 * dt + if self.scroll < 0 then self.scroll = 0 end self.redraw = true end end @@ -202,10 +209,14 @@ function function_block.predraw(self) end love.graphics.setColor(1, 1, 1) - love.graphics.draw(self.canvas, self.rect.x, self.rect.y) + love.graphics.push() + love.graphics.translate(self.rect.x, self.rect.y) + love.graphics.draw(self.canvas, 0, 0) end -function function_block.postdraw(self) end +function function_block.postdraw(self) + love.graphics.pop() +end local scrolling = {} function scrolling.init(self) @@ -254,9 +265,11 @@ function scrolling.mousemoved(self, x, y, dx, dy) if self.mouse_down then self.offset.x = self.offset.x + dx self.offset.y = self.offset.y + dy + + return true end - return true + return false end function scrolling.change_zoom(self, multiplier) @@ -267,6 +280,7 @@ end function scrolling.wheelmoved(self, dx, dy) if ui.focused == self then scrolling.change_zoom(self, dy > 0 and 1.05 or (1 / 1.05)) + return true end end @@ -353,15 +367,10 @@ class "Application" { rect = Rectangle(0, 0, 0, 0); } - -- ui.insert_child(self.ui, with(ui.make_element "rect") { - -- rect = Rectangle(0, 0, 1200, 50); - -- color = COLORS.dark_background; - -- }) - self.scroller = with(ui.make_element "scrolling") { rect = Rectangle(0, 0, 1200, 900); background_color = COLORS.background; - line_color = COLORS.primary_dark; + line_color = COLORS.dark_background; layer = 10; } @@ -398,12 +407,15 @@ class "Application" { local i = 0 for _, func in ipairs(wasm_mod.funcs) do - ui.insert_child(self.scroller, with(ui.make_element("function_block", func, wasm_mod)) { - rect = Rectangle(i * 400, 0, 400, 400); - layer = i + 1 - }) - - i = i + 1 + if not func.imported then + ui.insert_child(self.scroller, with(ui.make_element("function_block", func, wasm_mod)) { + rect = Rectangle(0, i * 22, 400, 400); + layer = 30 - i + }) + + i = i + 1 + if i > 20 then break end + end end end; diff --git a/conf.lua b/conf.lua index 752af6d..8b13689 100644 --- a/conf.lua +++ b/conf.lua @@ -50,5 +50,5 @@ end return { COLOR_SCHEMES = COLOR_SCHEMES; - COLOR_SCHEME = COLOR_SCHEMES.LIGHT; + COLOR_SCHEME = COLOR_SCHEMES.DARK; } diff --git a/src/ui.lua b/src/ui.lua index 88ad1c8..ddcfc04 100644 --- a/src/ui.lua +++ b/src/ui.lua @@ -36,6 +36,7 @@ function ui.make_element(type_, ...) remove = false; -- Whether to remove this element rect = Rectangle(0, 0, 0, 0); -- Rectangle bounds of the object children = {}; -- List of children, sorted by layer + parent = nil; -- The parent node of this child -- Any other data can be appended to this object } @@ -64,6 +65,7 @@ function ui.focus(elem) end function ui.insert_child(parent, child) + child.parent = parent table.insert(parent.children, child) ui.sort_children(parent) end diff --git a/src/wasm/text.lua b/src/wasm/text.lua index 3797827..9abbbfb 100644 --- a/src/wasm/text.lua +++ b/src/wasm/text.lua @@ -141,7 +141,7 @@ end function build_body(func, mod, colors) if func.imported then - return { text = "Imported function", colors = colors.code, newline = true } + return { { text = "Imported function", colors = colors.code } } end local text = {} -- 2.25.1