Bug fixes and improvements
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 7 Apr 2020 22:11:05 +0000 (17:11 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 7 Apr 2020 22:11:05 +0000 (17:11 -0500)
app.lua
conf.lua
src/ui.lua
src/wasm/text.lua

diff --git a/app.lua b/app.lua
index b45a755368a755aeb4381277e150115260db6611..47c722450cf01d89b5d930f537e622412972c80b 100644 (file)
--- 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;
 
index 752af6d28097aa6f3ef0da73c0856e55295982bf..8b1368951cab9b60092aba606ac43c48fcb27b25 100644 (file)
--- 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;
 }
index 88ad1c859e9b95e03819da5b7ddfbacb398c8abf..ddcfc04c33b492acde6e53f19bbb7bb007d5ed22 100644 (file)
@@ -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
index 3797827b4ba5e0fe4ce09a575edb935250ad041b..9abbbfb8d9c22639b8567424916d44f60bb545a8 100644 (file)
@@ -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 = {}