streamline button.lua
This commit is contained in:
parent
961f296131
commit
c29be0ffce
|
@ -9,9 +9,6 @@
|
||||||
|
|
||||||
-- draw button and queue up event handlers
|
-- draw button and queue up event handlers
|
||||||
function button(State, name, params)
|
function button(State, name, params)
|
||||||
if State.button_handlers == nil then
|
|
||||||
State.button_handlers = {}
|
|
||||||
end
|
|
||||||
love.graphics.setColor(params.bg.r, params.bg.g, params.bg.b, params.bg.a)
|
love.graphics.setColor(params.bg.r, params.bg.g, params.bg.b, params.bg.a)
|
||||||
love.graphics.rectangle('fill', params.x,params.y, params.w,params.h, 5,5)
|
love.graphics.rectangle('fill', params.x,params.y, params.w,params.h, 5,5)
|
||||||
if params.icon then params.icon(params) end
|
if params.icon then params.icon(params) end
|
||||||
|
@ -19,10 +16,7 @@ function button(State, name, params)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- process button event handlers
|
-- process button event handlers
|
||||||
function mouse_press_consumed_by_any_button_handler(State, x, y, mouse_button)
|
function mouse_press_consumed_by_any_button(State, x, y, mouse_button)
|
||||||
if State.button_handlers == nil then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local button_pressed = false
|
local button_pressed = false
|
||||||
local consume_press = true
|
local consume_press = true
|
||||||
for _,ev in ipairs(State.button_handlers) do
|
for _,ev in ipairs(State.button_handlers) do
|
||||||
|
|
2
edit.lua
2
edit.lua
|
@ -235,7 +235,7 @@ function edit.mouse_press(State, x,y, mouse_button)
|
||||||
if State.search_term then return end
|
if State.search_term then return end
|
||||||
State.mouse_down = mouse_button
|
State.mouse_down = mouse_button
|
||||||
--? print_and_log(('edit.mouse_press: cursor at %d,%d'):format(State.cursor1.line, State.cursor1.pos))
|
--? print_and_log(('edit.mouse_press: cursor at %d,%d'):format(State.cursor1.line, State.cursor1.pos))
|
||||||
if mouse_press_consumed_by_any_button_handler(State, x,y, mouse_button) then
|
if mouse_press_consumed_by_any_button(State, x,y, mouse_button) then
|
||||||
-- press on a button and it returned 'true' to short-circuit
|
-- press on a button and it returned 'true' to short-circuit
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
|
@ -294,7 +294,7 @@ The following facilities help set these things up:
|
||||||
everything about a button in one place. Create as many buttons as you like
|
everything about a button in one place. Create as many buttons as you like
|
||||||
within a single shared `state`.
|
within a single shared `state`.
|
||||||
|
|
||||||
* `mouse_press_consumed_by_any_button_handler(state, x,y, mouse_button)`
|
* `mouse_press_consumed_by_any_button(state, x,y, mouse_button)`
|
||||||
|
|
||||||
Call this either directly or indirectly from `App.mousepressed`. It will
|
Call this either directly or indirectly from `App.mousepressed`. It will
|
||||||
pass on a click to any button registered in `state`. It's also helpful to
|
pass on a click to any button registered in `state`. It's also helpful to
|
||||||
|
@ -302,7 +302,7 @@ The following facilities help set these things up:
|
||||||
following boilerplate early in `mousepressed`:
|
following boilerplate early in `mousepressed`:
|
||||||
|
|
||||||
```
|
```
|
||||||
if mouse_press_consumed_by_any_button_handler(state, x,y, mouse_button) then
|
if mouse_press_consumed_by_any_button(state, x,y, mouse_button) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
|
@ -239,7 +239,7 @@ function edit.mouse_press(State, x,y, mouse_button)
|
||||||
if State.search_term then return end
|
if State.search_term then return end
|
||||||
State.mouse_down = mouse_button
|
State.mouse_down = mouse_button
|
||||||
--? print_and_log(('edit.mouse_press: cursor at %d,%d'):format(State.cursor1.line, State.cursor1.pos))
|
--? print_and_log(('edit.mouse_press: cursor at %d,%d'):format(State.cursor1.line, State.cursor1.pos))
|
||||||
if mouse_press_consumed_by_any_button_handler(State, x,y, mouse_button) then
|
if mouse_press_consumed_by_any_button(State, x,y, mouse_button) then
|
||||||
-- press on a button and it returned 'true' to short-circuit
|
-- press on a button and it returned 'true' to short-circuit
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
|
@ -881,6 +881,7 @@ function test_select_text_using_mouse_starting_above_text_wrapping_line()
|
||||||
Editor_state.screen_top1 = {line=2, pos=3}
|
Editor_state.screen_top1 = {line=2, pos=3}
|
||||||
Editor_state.screen_bottom1 = {}
|
Editor_state.screen_bottom1 = {}
|
||||||
-- press mouse above first line of text
|
-- press mouse above first line of text
|
||||||
|
edit.draw(Editor_state)
|
||||||
edit.run_after_mouse_press(Editor_state, Editor_state.left+8,5, 1)
|
edit.run_after_mouse_press(Editor_state, Editor_state.left+8,5, 1)
|
||||||
-- selection is at screen top
|
-- selection is at screen top
|
||||||
check(Editor_state.selection1.line ~= nil, 'selection:line-not-nil')
|
check(Editor_state.selection1.line ~= nil, 'selection:line-not-nil')
|
||||||
|
|
|
@ -881,6 +881,7 @@ function test_select_text_using_mouse_starting_above_text_wrapping_line()
|
||||||
Editor_state.screen_top1 = {line=2, pos=3}
|
Editor_state.screen_top1 = {line=2, pos=3}
|
||||||
Editor_state.screen_bottom1 = {}
|
Editor_state.screen_bottom1 = {}
|
||||||
-- press mouse above first line of text
|
-- press mouse above first line of text
|
||||||
|
edit.draw(Editor_state)
|
||||||
edit.run_after_mouse_press(Editor_state, Editor_state.left+8,5, 1)
|
edit.run_after_mouse_press(Editor_state, Editor_state.left+8,5, 1)
|
||||||
-- selection is at screen top
|
-- selection is at screen top
|
||||||
check(Editor_state.selection1.line ~= nil, 'selection:line-not-nil')
|
check(Editor_state.selection1.line ~= nil, 'selection:line-not-nil')
|
||||||
|
|
Loading…
Reference in New Issue