lay out buttons based on device dimensions
This commit is contained in:
parent
0d4500e41d
commit
d98bc8cc7d
|
@ -1,5 +1,6 @@
|
||||||
on.draw = function()
|
on.draw = function()
|
||||||
Global_state.button_handlers = {}
|
Global_state.button_handlers = {}
|
||||||
|
Overflow_button = nil
|
||||||
love.graphics.setBackgroundColor(Background_color.r, Background_color.g, Background_color.b)
|
love.graphics.setBackgroundColor(Background_color.r, Background_color.g, Background_color.b)
|
||||||
draw_canvas()
|
draw_canvas()
|
||||||
App.color(Foreground_color)
|
App.color(Foreground_color)
|
||||||
|
|
|
@ -2,6 +2,7 @@ on.mouse_press = function(x,y, mouse_button)
|
||||||
if mouse_press_consumed_by_any_button_handler(Global_state, x,y, mouse_button) then
|
if mouse_press_consumed_by_any_button_handler(Global_state, x,y, mouse_button) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
Show_overflow = false
|
||||||
if mouse_on_any_slider(x,y, mouse_button) then
|
if mouse_on_any_slider(x,y, mouse_button) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,33 +1,41 @@
|
||||||
draw_menu = function()
|
draw_menu = function()
|
||||||
App.color(Menu_background)
|
App.color(Menu_background)
|
||||||
love.graphics.rectangle('fill', 0,0, App.screen.width, Menu_bottom)
|
love.graphics.rectangle('fill', 0,0, App.screen.width, Menu_bottom)
|
||||||
local x = Menu_left+5
|
-- settings button on right
|
||||||
|
local w = App.width('settings')
|
||||||
|
local r = Safe_width-w-10-5
|
||||||
|
settings_button(r, w)
|
||||||
|
local x, y = Menu_left+5, Menu_top+5
|
||||||
|
-- main menu on left
|
||||||
App.color(White)
|
App.color(White)
|
||||||
love.graphics.print(Current_pane_index, x+5, Menu_top+5+2)
|
love.graphics.print(Current_pane_index, x+5, Menu_top+5+2)
|
||||||
App.color(Normal_color)
|
App.color(Normal_color)
|
||||||
x = x+5 + App.width(tostring(Current_pane_index)) + 10
|
x = x+5 + App.width(tostring(Current_pane_index)) + 10
|
||||||
-- main buttons
|
x = run_button(x, y, r)
|
||||||
x = run_button(x)
|
x = stop_button(x, y, r)
|
||||||
x = stop_button(x)
|
|
||||||
App.color{r=0.5, g=0.5, b=0.5}
|
App.color{r=0.5, g=0.5, b=0.5}
|
||||||
love.graphics.print('code', x, Menu_top+5)
|
love.graphics.print('code', x, y)
|
||||||
x = x+App.width('code')+10
|
x = x+App.width('code')+10
|
||||||
|
-- assume screen will always be wide enough to print this far without overflow
|
||||||
if Show_code then
|
if Show_code then
|
||||||
x = hide_code_button(x)
|
x, y = hide_code_button(x, y, r)
|
||||||
else
|
else
|
||||||
x = show_code_button(x)
|
x, y = show_code_button(x, y, r)
|
||||||
end
|
end
|
||||||
x = copy_button(x)
|
x, y = copy_button(x, y, r)
|
||||||
x = paste_button(x)
|
x, y = paste_button(x, y, r)
|
||||||
x = clear_pane_button(x)
|
x, y = clear_pane_button(x, y, r)
|
||||||
|
if not Overflow_button then
|
||||||
|
local w = App.width('screen')+10
|
||||||
|
local w2 = App.width('>>')+10
|
||||||
|
if x+w+10+w2+10 < r then
|
||||||
App.color{r=0.5, g=0.5, b=0.5}
|
App.color{r=0.5, g=0.5, b=0.5}
|
||||||
love.graphics.print('screen', x, Menu_top+5)
|
love.graphics.print('screen', x, y)
|
||||||
x = x+App.width('screen')+10
|
x = x+App.width('screen')+10
|
||||||
x = new_pane_button(x)
|
end
|
||||||
x = delete_pane_button(x)
|
end
|
||||||
-- settings button on right
|
x, y = new_pane_button(x, y, r)
|
||||||
local w = App.width('settings')
|
x, y = delete_pane_button(x, y, r)
|
||||||
settings_button(Safe_width-w-10-5, w)
|
|
||||||
-- nav buttons along sides
|
-- nav buttons along sides
|
||||||
if Current_pane_index > 1 then
|
if Current_pane_index > 1 then
|
||||||
previous_pane_button()
|
previous_pane_button()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
run_button = function(x)
|
run_button = function(x, y)
|
||||||
local w = App.width('run')+10
|
local w = App.width('run')+10
|
||||||
button(Global_state, 'run', {x=x, y=Menu_top+5, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
button(Global_state, 'run', {x=x, y=y, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
||||||
icon = function(p)
|
icon = function(p)
|
||||||
App.color(Normal_color)
|
App.color(Normal_color)
|
||||||
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
|
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
|
||||||
|
@ -33,5 +33,5 @@ run_button = function(x)
|
||||||
love.graphics.setCanvas()
|
love.graphics.setCanvas()
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
return x+w+10
|
return x+w+10, y
|
||||||
end
|
end
|
|
@ -1,6 +1,15 @@
|
||||||
new_pane_button = function(x)
|
new_pane_button = function(x, y, r)
|
||||||
local w = App.width('new')+10
|
local w = App.width('new')+10
|
||||||
button(Global_state, 'new', {x=x, y=Menu_top+5, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
local x2, y2 = maybe_draw_overflow_button(x, y, w, r)
|
||||||
|
if Overflow_button then
|
||||||
|
-- overflow
|
||||||
|
if not Show_overflow then
|
||||||
|
return x, y
|
||||||
|
else
|
||||||
|
y = y2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
button(Global_state, 'new', {x=x, y=y, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
||||||
icon = function(p)
|
icon = function(p)
|
||||||
App.color(Normal_color)
|
App.color(Normal_color)
|
||||||
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
|
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
|
||||||
|
@ -12,5 +21,9 @@ new_pane_button = function(x)
|
||||||
Current_pane = Panes[Current_pane_index]
|
Current_pane = Panes[Current_pane_index]
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
return x+w+10
|
if Overflow_button then
|
||||||
|
return x, y+Line_height
|
||||||
|
else
|
||||||
|
return x+w+10, y
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -1,6 +1,6 @@
|
||||||
show_code_button = function(x)
|
show_code_button = function(x, y)
|
||||||
local w = App.width('show')+10
|
local w = App.width('show')+10
|
||||||
button(Global_state, 'show', {x=x, y=Menu_top+5, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
button(Global_state, 'show', {x=x, y=y, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
||||||
icon = function(p)
|
icon = function(p)
|
||||||
App.color(Normal_color)
|
App.color(Normal_color)
|
||||||
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
|
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
|
||||||
|
@ -10,5 +10,5 @@ show_code_button = function(x)
|
||||||
Show_code = true
|
Show_code = true
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
return x+w+10
|
return x+w+10, y+Line_height
|
||||||
end
|
end
|
|
@ -1,6 +1,13 @@
|
||||||
hide_code_button = function(x)
|
hide_code_button = function(x, y, r)
|
||||||
local w = App.width('hide')+10
|
local w = App.width('hide')+10
|
||||||
button(Global_state, 'hide', {x=x, y=Menu_top+5, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
local x2, y2 = maybe_draw_overflow_button(x, y, w, r)
|
||||||
|
if Overflow_button then
|
||||||
|
-- overflow
|
||||||
|
if not Show_overflow then
|
||||||
|
return x, y
|
||||||
|
end
|
||||||
|
end
|
||||||
|
button(Global_state, 'hide', {x=x, y=y, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
||||||
icon = function(p)
|
icon = function(p)
|
||||||
App.color(Normal_color)
|
App.color(Normal_color)
|
||||||
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
|
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
|
||||||
|
@ -10,5 +17,9 @@ hide_code_button = function(x)
|
||||||
Show_code = false
|
Show_code = false
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
return x+w+10
|
if Overflow_button then
|
||||||
|
return x, y+Line_height
|
||||||
|
else
|
||||||
|
return x+w+10, y
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -1,6 +1,13 @@
|
||||||
copy_button = function(x)
|
copy_button = function(x, y, r)
|
||||||
local w = App.width('copy')+10
|
local w = App.width('copy')+10
|
||||||
button(Global_state, 'copy', {x=x, y=Menu_top+5, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
local x2, y2 = maybe_draw_overflow_button(x, y, w, r)
|
||||||
|
if Overflow_button then
|
||||||
|
-- overflow
|
||||||
|
if not Show_overflow then
|
||||||
|
return x, y
|
||||||
|
end
|
||||||
|
end
|
||||||
|
button(Global_state, 'copy', {x=x, y=y, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
||||||
icon = function(p)
|
icon = function(p)
|
||||||
App.color(Normal_color)
|
App.color(Normal_color)
|
||||||
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
|
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
|
||||||
|
@ -11,5 +18,9 @@ copy_button = function(x)
|
||||||
if s then App.set_clipboard(s) end
|
if s then App.set_clipboard(s) end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
return x+w+10
|
if Overflow_button then
|
||||||
|
return x, y+Line_height
|
||||||
|
else
|
||||||
|
return x+w+10, y
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -1,6 +1,15 @@
|
||||||
paste_button = function(x)
|
paste_button = function(x, y, r)
|
||||||
local w = App.width('paste')+10
|
local w = App.width('paste')+10
|
||||||
button(Global_state, 'paste', {x=x, y=Menu_top+5, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
local x2, y2 = maybe_draw_overflow_button(x, y, w, r)
|
||||||
|
if Overflow_button then
|
||||||
|
-- overflow
|
||||||
|
if not Show_overflow then
|
||||||
|
return x, y
|
||||||
|
else
|
||||||
|
y = y2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
button(Global_state, 'paste', {x=x, y=y, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
||||||
icon = function(p)
|
icon = function(p)
|
||||||
App.color(Normal_color)
|
App.color(Normal_color)
|
||||||
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
|
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
|
||||||
|
@ -11,5 +20,10 @@ paste_button = function(x)
|
||||||
Text.insert_text(Current_pane.editor_state, s)
|
Text.insert_text(Current_pane.editor_state, s)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
return x+w+10
|
if Overflow_button then
|
||||||
|
-- we're past the overflow button; start drawing downward
|
||||||
|
return x, y+Line_height
|
||||||
|
else
|
||||||
|
return x+w+10, y
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -1,6 +1,15 @@
|
||||||
clear_pane_button = function(x)
|
clear_pane_button = function(x, y, r)
|
||||||
local w = App.width('clear')+10
|
local w = App.width('clear')+10
|
||||||
button(Global_state, 'clear', {x=x, y=Menu_top+5, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
local x2, y2 = maybe_draw_overflow_button(x, y, w, r)
|
||||||
|
if Overflow_button then
|
||||||
|
-- overflow
|
||||||
|
if not Show_overflow then
|
||||||
|
return x, y
|
||||||
|
else
|
||||||
|
y = y2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
button(Global_state, 'clear', {x=x, y=y, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
||||||
icon = function(p)
|
icon = function(p)
|
||||||
App.color(Normal_color)
|
App.color(Normal_color)
|
||||||
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
|
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
|
||||||
|
@ -8,5 +17,9 @@ clear_pane_button = function(x)
|
||||||
end,
|
end,
|
||||||
onpress1 = clear_pane,
|
onpress1 = clear_pane,
|
||||||
})
|
})
|
||||||
return x+w+10
|
if Overflow_button then
|
||||||
|
return x, y+Line_height
|
||||||
|
else
|
||||||
|
return x+w+10, y
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -1,6 +1,15 @@
|
||||||
delete_pane_button = function(x)
|
delete_pane_button = function(x, y, r)
|
||||||
local w = App.width('delete')+10
|
local w = App.width('delete')+10
|
||||||
button(Global_state, 'delete', {x=x, y=Menu_top+5, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
local x2, y2 = maybe_draw_overflow_button(x, y, w, r, --[[final button]] true)
|
||||||
|
if Overflow_button then
|
||||||
|
-- overflow
|
||||||
|
if Show_overflow then
|
||||||
|
y = y2
|
||||||
|
else
|
||||||
|
return x, y
|
||||||
|
end
|
||||||
|
end
|
||||||
|
button(Global_state, 'delete', {x=x, y=y, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
||||||
icon = function(p)
|
icon = function(p)
|
||||||
App.color(Normal_color)
|
App.color(Normal_color)
|
||||||
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
|
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
|
||||||
|
@ -17,5 +26,9 @@ delete_pane_button = function(x)
|
||||||
Current_pane = Panes[Current_pane_index]
|
Current_pane = Panes[Current_pane_index]
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
return x+w+10
|
if Overflow_button then
|
||||||
|
return x, y+Line_height
|
||||||
|
else
|
||||||
|
return x+w+10, y
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -1,6 +1,6 @@
|
||||||
stop_button = function(x)
|
stop_button = function(x, y)
|
||||||
local w = App.width('stop')+10
|
local w = App.width('stop')+10
|
||||||
button(Global_state, 'stop', {x=x, y=Menu_top+5, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
button(Global_state, 'stop', {x=x, y=y, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
||||||
icon = function(p)
|
icon = function(p)
|
||||||
App.color(Normal_color)
|
App.color(Normal_color)
|
||||||
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
|
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
|
||||||
|
@ -8,5 +8,5 @@ stop_button = function(x)
|
||||||
end,
|
end,
|
||||||
onpress1 = clear_handlers,
|
onpress1 = clear_handlers,
|
||||||
})
|
})
|
||||||
return x+w+10
|
return x+w+10, y
|
||||||
end
|
end
|
|
@ -0,0 +1,2 @@
|
||||||
|
-- True if the overflow menu has been opened and we want to render buttons within it.
|
||||||
|
Show_overflow = false
|
|
@ -0,0 +1 @@
|
||||||
|
Overflow_button = nil -- location and dimensions of the overflow button if it's been drawn this frame
|
|
@ -0,0 +1,14 @@
|
||||||
|
overflow_button = function(x, y)
|
||||||
|
local w = App.width('>>')+10
|
||||||
|
button(Global_state, 'overflow', {x=x, y=y, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
|
||||||
|
icon = function(p)
|
||||||
|
App.color(Normal_color)
|
||||||
|
love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 2,2)
|
||||||
|
love.graphics.print('>>', p.x+5,p.y+2)
|
||||||
|
end,
|
||||||
|
onpress1 = function()
|
||||||
|
Show_overflow = not Show_overflow
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
return x+w+10, y+Line_height
|
||||||
|
end
|
|
@ -0,0 +1,16 @@
|
||||||
|
maybe_draw_overflow_button = function(x, y, w, r, final_button)
|
||||||
|
if Overflow_button then return x, y end
|
||||||
|
local after = x+w+10
|
||||||
|
if not final_button then
|
||||||
|
local w2 = App.width('>>')+10
|
||||||
|
-- only draw a button if there's going to be at least space for the overflow button afterwards
|
||||||
|
after = after+w2+10
|
||||||
|
end
|
||||||
|
if after > r then
|
||||||
|
x, y = overflow_button(x, y)
|
||||||
|
Overflow_button = Global_state.button_handlers[#Global_state.button_handlers]
|
||||||
|
return x, y
|
||||||
|
else
|
||||||
|
return x, y
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue