diff options
-rw-r--r-- | button.lua | 16 | ||||
-rw-r--r-- | edit.lua | 5 | ||||
-rw-r--r-- | main.lua | 1 |
3 files changed, 13 insertions, 9 deletions
diff --git a/button.lua b/button.lua index 4cafc86..4c7fe0b 100644 --- a/button.lua +++ b/button.lua @@ -3,19 +3,23 @@ -- If the handler returns true, it'll prevent any further processing of the -- event. -Button_handlers = {} - -- draw button and queue up event handlers -function button(name, params) +function button(State, name, params) + if State.button_handlers == nil then + State.button_handlers = {} + end love.graphics.setColor(params.color[1], params.color[2], params.color[3]) love.graphics.rectangle('fill', params.x,params.y, params.w,params.h, 5,5) if params.icon then params.icon(params.x, params.y) end - table.insert(Button_handlers, params) + table.insert(State.button_handlers, params) end -- process button event handlers -function propagate_to_button_handlers(x, y, mouse_button) - for _,ev in ipairs(Button_handlers) do +function propagate_to_button_handlers(State, x, y, mouse_button) + if State.button_handlers == nil then + return + end + for _,ev in ipairs(State.button_handlers) do if x>ev.x and x<ev.x+ev.w and y>ev.y and y<ev.y+ev.h then if ev.onpress1 and mouse_button == 1 then return ev.onpress1() diff --git a/edit.lua b/edit.lua index 5bc8bad..3c92d49 100644 --- a/edit.lua +++ b/edit.lua @@ -128,6 +128,7 @@ function edit.fixup_cursor(State) end function edit.draw(State) + State.button_handlers = {} App.color(Text_color) assert(#State.lines == #State.line_cache) if not Text.le1(State.screen_top1, State.cursor1) then @@ -151,7 +152,7 @@ function edit.draw(State) end if line.data == '' then -- button to insert new drawing - button('draw', {x=4,y=y+4, w=12,h=12, color={1,1,0}, + button(State, 'draw', {x=4,y=y+4, w=12,h=12, color={1,1,0}, icon = icon.insert_drawing, onpress1 = function() Drawing.before = snapshot(State, line_index-1, line_index) @@ -208,7 +209,7 @@ end function edit.mouse_pressed(State, x,y, mouse_button) if State.search_term then return end --? print('press', State.selection1.line, State.selection1.pos) - if propagate_to_button_handlers(x,y, mouse_button) then + if propagate_to_button_handlers(State, x,y, mouse_button) then -- press on a button and it returned 'true' to short-circuit return end diff --git a/main.lua b/main.lua index 74928c1..f328139 100644 --- a/main.lua +++ b/main.lua @@ -133,7 +133,6 @@ function App.filedropped(file) end function App.draw() - Button_handlers = {} edit.draw(Editor_state) end |