implement second, 'output' editor

Also its scrollbar.
This commit is contained in:
Kartik K. Agaram 2023-11-18 20:34:51 -08:00
parent e53245e62d
commit 809a980213
13 changed files with 67 additions and 41 deletions

View File

@ -1,6 +1,8 @@
on.update = function()
refresh_debug_animations()
if Editor_scrollbar_drag then
adjust_scrollbar(App.mouse_y())
if Editor_state.scrollbar_drag then
adjust_scrollbar(Editor_state, App.mouse_y())
elseif Output_editor_state.scrollbar_drag then
adjust_scrollbar(Output_editor_state, App.mouse_y())
end
end

View File

@ -12,4 +12,10 @@ on.initialize = function()
math.min(100+30*App.width('m'), Safe_width*2/3), -- right
love.graphics.getFont():getHeight(), Line_height)
Text.redraw_all(Editor_state)
Output_editor_state = edit.initialize_state(
Editor_state.bottom+5+10+5, -- top
nil, -- buttom
Editor_state.left, Editor_state.right,
love.graphics.getFont():getHeight(), Line_height)
Text.redraw_all(Output_editor_state)
end

View File

@ -7,5 +7,7 @@ on.draw = function()
edit.draw(Editor_state)
draw_scrollbar(Editor_state)
draw_output_border()
edit.draw(Output_editor_state, Normal_color, --[[hide cursor]] true)
draw_scrollbar(Output_editor_state)
draw_menu()
end

View File

@ -2,11 +2,15 @@ on.mouse_press = function(x,y, mouse_button)
if mouse_press_consumed_by_any_button_handler(Editor_state, x,y, mouse_button) then
return
end
if on_editor_scrollbar(x,y) then
Editor_scrollbar_drag = true
elseif on_editor_scrollbar_area(x,y) then
if on_editor_scrollbar(Editor_state, x,y) then
Editor_state.scrollbar_drag = true
elseif on_editor_scrollbar_area(Editor_state, x,y) then
-- nothing
elseif x < Editor_state.right + 15 - 5 and y < Editor_state.bottom + 5 + 10 - 5 then
edit.mouse_press(Editor_state, x,y, mouse_button)
elseif on_editor_scrollbar(Output_editor_state, x,y) then
Output_editor_state.scrollbar_drag = true
elseif on_editor_scrollbar_area(Output_editor_state, x,y) then
-- nothing
end
end

View File

@ -1,10 +1,14 @@
on.mouse_release = function(x,y, mouse_button)
if Editor_scrollbar_drag then
adjust_scrollbar(y)
Editor_scrollbar_drag = nil
elseif on_editor_scrollbar_area(x,y) then
adjust_scrollbar(y)
if Editor_state.scrollbar_drag then
adjust_scrollbar(Editor_state, y)
Editor_state.scrollbar_drag = nil
elseif on_editor_scrollbar_area(Editor_state, x,y) then
adjust_scrollbar(Editor_state, y)
elseif x < Editor_state.right + 15 - 5 and y < Editor_state.bottom + 5 + 10 - 5 then
edit.mouse_release(Editor_state, x,y, mouse_button)
elseif Output_editor_state.scrollbar_drag then
adjust_scrollbar(Output_editor_state, y)
elseif on_editor_scrollbar_area(Output_editor_state, x,y) then
adjust_scrollbar(Output_editor_state, y)
end
end

View File

@ -17,8 +17,13 @@ draw_menu = function()
love.graphics.setBackgroundColor(1,1,1)
love.graphics.setColor(0,0,0)
local status, result = live.eval(buf)
if not status then
print(result)
print(status, result)
if result then
-- could be either output or error
Output_editor_state.lines = {
{data=tostring(result)},
}
Text.redraw_all(Output_editor_state)
end
love.graphics.pop()
love.graphics.setCanvas()

View File

@ -4,4 +4,8 @@ on.resize = function()
Editor_state.width = Editor_state.right - Editor_state.left
Editor_state.bottom = Safe_height/2-5
Text.redraw_all(Editor_state)
Output_editor_state.top = Editor_state.bottom+5+10+5
Output_editor_state.right = Editor_state.right
Output_editor_state.width = Editor_state.width
Output_editor_state.bottom = Safe_height - 5
end

View File

@ -1,13 +1,13 @@
draw_scrollbar = function(Editor_state)
draw_scrollbar = function(state)
App.color(Normal_color)
love.graphics.line(Editor_state.right+30, Editor_state.top, Editor_state.right+30, Editor_state.bottom)
love.graphics.line(Editor_state.right+25, Editor_state.top, Editor_state.right+35, Editor_state.top)
love.graphics.line(Editor_state.right+25, Editor_state.bottom, Editor_state.right+35, Editor_state.bottom)
local sbtop, sbbot = compute_scrollbar(Editor_state)
local topy = Editor_state.top + sbtop*(Editor_state.bottom - Editor_state.top)
local boty = Editor_state.top +sbbot*(Editor_state.bottom - Editor_state.top)
love.graphics.line(state.right+30, state.top, state.right+30, state.bottom)
love.graphics.line(state.right+25, state.top, state.right+35, state.top)
love.graphics.line(state.right+25, state.bottom, state.right+35, state.bottom)
local sbtop, sbbot = compute_scrollbar(state)
local topy = state.top + sbtop*(state.bottom - state.top)
local boty = state.top +sbbot*(state.bottom - state.top)
App.color{r=0.8, g=0.8, b=0.9}
love.graphics.rectangle('fill', Editor_state.right+15, topy+5, 30, math.max(boty-topy-10, 5), 5,5)
Editor_scrollbar_top = topy
Editor_scrollbar_bottom = boty
love.graphics.rectangle('fill', state.right+15, topy+5, 30, math.max(boty-topy-10, 5), 5,5)
state.scrollbar_top = topy
state.scrollbar_bottom = boty
end

View File

@ -1,13 +1,13 @@
adjust_scrollbar = function(y)
local s = (y-Editor_state.top) / (Editor_state.bottom-Editor_state.top)
local screen_line = s*Editor_state.screen_line_count
adjust_scrollbar = function(state, y)
local s = (y-state.top) / (state.bottom-state.top)
local screen_line = s*state.screen_line_count
local line = 1
for i=1,#Editor_state.lines do
if Editor_state.line_cache[i].start_screen_line_index > screen_line then
for i=1,#state.lines do
if state.line_cache[i].start_screen_line_index > screen_line then
break
end
line = i
end
Editor_state.screen_top1 = {line=line, pos=1}
Editor_state.cursor1 = {line=line, pos=1}
state.screen_top1 = {line=line, pos=1}
state.cursor1 = {line=line, pos=1}
end

View File

@ -1,2 +0,0 @@
Editor_scrollbar_top = 0 -- in px
Editor_scrollbar_bottom = 0

View File

@ -1,7 +1,7 @@
on_editor_scrollbar = function(x,y)
if x < Editor_state.right+15 then return end
if x > Editor_state.right+45 then return end
if y < Editor_scrollbar_top then return end
if y > Editor_scrollbar_bottom then return end
on_editor_scrollbar = function(state, x,y)
if x < state.right+15 then return end
if x > state.right+45 then return end
if y < state.scrollbar_top then return end
if y > state.scrollbar_bottom then return end
return true
end

View File

@ -1,7 +1,7 @@
on_editor_scrollbar_area = function(x,y)
if x < Editor_state.right+15 then return end
if x > Editor_state.right+45 then return end
if y < Editor_state.top then return end
if y > Editor_state.bottom then return end
on_editor_scrollbar_area = function(state, x,y)
if x < state.right+15 then return end
if x > state.right+45 then return end
if y < state.top then return end
if y > state.bottom then return end
return true
end

1
0044-Output_editor_state Normal file
View File

@ -0,0 +1 @@
Output_editor_state = nil