Merge lines.love
This commit is contained in:
commit
d011c0ce32
50
app.lua
50
app.lua
|
@ -207,22 +207,22 @@ function App.modifier_down(key)
|
|||
end
|
||||
|
||||
App.fake_mouse_state = {x=-1, y=-1} -- x,y always set
|
||||
function App.fake_mouse_press(x,y, button)
|
||||
function App.fake_mouse_press(x,y, mouse_button)
|
||||
App.fake_mouse_state.x = x
|
||||
App.fake_mouse_state.y = y
|
||||
App.fake_mouse_state[button] = true
|
||||
App.fake_mouse_state[mouse_button] = true
|
||||
end
|
||||
function App.fake_mouse_release(x,y, button)
|
||||
function App.fake_mouse_release(x,y, mouse_button)
|
||||
App.fake_mouse_state.x = x
|
||||
App.fake_mouse_state.y = y
|
||||
App.fake_mouse_state[button] = nil
|
||||
App.fake_mouse_state[mouse_button] = nil
|
||||
end
|
||||
function App.mouse_move(x,y)
|
||||
App.fake_mouse_state.x = x
|
||||
App.fake_mouse_state.y = y
|
||||
end
|
||||
function App.mouse_down(button)
|
||||
return App.fake_mouse_state[button]
|
||||
function App.mouse_down(mouse_button)
|
||||
return App.fake_mouse_state[mouse_button]
|
||||
end
|
||||
function App.mouse_x()
|
||||
return App.fake_mouse_state.x
|
||||
|
@ -250,25 +250,25 @@ function App.run_after_keychord(chord)
|
|||
App.draw()
|
||||
end
|
||||
|
||||
function App.run_after_mouse_click(x,y, button)
|
||||
App.fake_mouse_press(x,y, button)
|
||||
App.mousepressed(x,y, button)
|
||||
App.fake_mouse_release(x,y, button)
|
||||
App.mousereleased(x,y, button)
|
||||
function App.run_after_mouse_click(x,y, mouse_button)
|
||||
App.fake_mouse_press(x,y, mouse_button)
|
||||
App.mousepressed(x,y, mouse_button)
|
||||
App.fake_mouse_release(x,y, mouse_button)
|
||||
App.mousereleased(x,y, mouse_button)
|
||||
App.screen.contents = {}
|
||||
App.draw()
|
||||
end
|
||||
|
||||
function App.run_after_mouse_press(x,y, button)
|
||||
App.fake_mouse_press(x,y, button)
|
||||
App.mousepressed(x,y, button)
|
||||
function App.run_after_mouse_press(x,y, mouse_button)
|
||||
App.fake_mouse_press(x,y, mouse_button)
|
||||
App.mousepressed(x,y, mouse_button)
|
||||
App.screen.contents = {}
|
||||
App.draw()
|
||||
end
|
||||
|
||||
function App.run_after_mouse_release(x,y, button)
|
||||
App.fake_mouse_release(x,y, button)
|
||||
App.mousereleased(x,y, button)
|
||||
function App.run_after_mouse_release(x,y, mouse_button)
|
||||
App.fake_mouse_release(x,y, mouse_button)
|
||||
App.mousereleased(x,y, mouse_button)
|
||||
App.screen.contents = {}
|
||||
App.draw()
|
||||
end
|
||||
|
@ -302,13 +302,15 @@ function App.open_for_writing(filename)
|
|||
end
|
||||
|
||||
function App.open_for_reading(filename)
|
||||
return {
|
||||
lines = function(self)
|
||||
return App.filesystem[filename]:gmatch('[^\n]+')
|
||||
end,
|
||||
close = function(self)
|
||||
end,
|
||||
}
|
||||
if App.filesystem[filename] then
|
||||
return {
|
||||
lines = function(self)
|
||||
return App.filesystem[filename]:gmatch('[^\n]+')
|
||||
end,
|
||||
close = function(self)
|
||||
end,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function App.run_tests()
|
||||
|
|
35
button.lua
35
button.lua
|
@ -1,20 +1,37 @@
|
|||
-- simple immediate-mode buttons
|
||||
|
||||
Button_handlers = {}
|
||||
-- Simple immediate-mode buttons with (currently) just an onpress1 handler for
|
||||
-- the left button.
|
||||
--
|
||||
-- Buttons can nest in principle, though I haven't actually used that yet.
|
||||
--
|
||||
-- Don't rely on the order in which handlers are run. Within any widget, all
|
||||
-- applicable button handlers will run. If _any_ of them returns true, the
|
||||
-- event will continue to propagate elsewhere in the widget.
|
||||
|
||||
-- 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)
|
||||
if params.icon then params.icon(params) end
|
||||
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 mouse_press_consumed_by_any_button_handler(State, x, y, mouse_button)
|
||||
if State.button_handlers == nil then
|
||||
return
|
||||
end
|
||||
local result = false
|
||||
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 ev.onpress1() end
|
||||
if ev.onpress1 and mouse_button == 1 then
|
||||
if not ev.onpress1() then
|
||||
result = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
|
28
edit.lua
28
edit.lua
|
@ -80,6 +80,7 @@ function edit.initialize_state(top, left, right, font_height, line_height) -- c
|
|||
end -- App.initialize_state
|
||||
|
||||
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
|
||||
|
@ -133,7 +134,10 @@ 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)
|
||||
propagate_to_button_handlers(x,y, mouse_button)
|
||||
if mouse_press_consumed_by_any_button_handler(State, x,y, mouse_button) then
|
||||
-- press on a button and it returned 'true' to short-circuit
|
||||
return
|
||||
end
|
||||
|
||||
for line_index,line in ipairs(State.lines) do
|
||||
if Text.in_line(State, line_index, x,y) then
|
||||
|
@ -355,25 +359,25 @@ function edit.run_after_keychord(State, chord)
|
|||
edit.draw(State)
|
||||
end
|
||||
|
||||
function edit.run_after_mouse_click(State, x,y, button)
|
||||
App.fake_mouse_press(x,y, button)
|
||||
edit.mouse_pressed(State, x,y, button)
|
||||
App.fake_mouse_release(x,y, button)
|
||||
edit.mouse_released(State, x,y, button)
|
||||
function edit.run_after_mouse_click(State, x,y, mouse_button)
|
||||
App.fake_mouse_press(x,y, mouse_button)
|
||||
edit.mouse_pressed(State, x,y, mouse_button)
|
||||
App.fake_mouse_release(x,y, mouse_button)
|
||||
edit.mouse_released(State, x,y, mouse_button)
|
||||
App.screen.contents = {}
|
||||
edit.draw(State)
|
||||
end
|
||||
|
||||
function edit.run_after_mouse_press(State, x,y, button)
|
||||
App.fake_mouse_press(x,y, button)
|
||||
edit.mouse_pressed(State, x,y, button)
|
||||
function edit.run_after_mouse_press(State, x,y, mouse_button)
|
||||
App.fake_mouse_press(x,y, mouse_button)
|
||||
edit.mouse_pressed(State, x,y, mouse_button)
|
||||
App.screen.contents = {}
|
||||
edit.draw(State)
|
||||
end
|
||||
|
||||
function edit.run_after_mouse_release(State, x,y, button)
|
||||
App.fake_mouse_release(x,y, button)
|
||||
edit.mouse_released(State, x,y, button)
|
||||
function edit.run_after_mouse_release(State, x,y, mouse_button)
|
||||
App.fake_mouse_release(x,y, mouse_button)
|
||||
edit.mouse_released(State, x,y, mouse_button)
|
||||
App.screen.contents = {}
|
||||
edit.draw(State)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue