give example panes a name

This commit is contained in:
Kartik K. Agaram 2023-11-22 21:11:31 -08:00
parent c0253d6182
commit 90319082f5
4 changed files with 122 additions and 89 deletions

View File

@ -6,7 +6,7 @@ on.initialize = function()
Menu_left, Menu_top, Safe_width, Safe_height = love.window.getSafeArea()
Menu_height = 5 + Line_height + 5
Menu_bottom = Menu_top + Menu_height
Panes = map(Example_panes, example_pane)
load_example_panes()
table.insert(Panes, new_pane())
Current_pane_index = 1
Current_pane = Panes[Current_pane_index]

View File

@ -1,5 +1,6 @@
example_pane = function(lines)
example_pane = function(name, lines)
local result = new_pane()
result.name = name
result.editor_state.lines = load_array(lines)
Text.redraw_all(result.editor_state)
return result

View File

@ -1,106 +1,133 @@
-- some examples
-- each element of this array is itself an array of lines that will get loaded into a pane
-- some examples that each get loaded into a pane
-- each example has a name, so we can avoid bringing back up an example someone deleted.
Example_panes = {
{
"-- Some examples; feel free to delete them and they'll never return.",
'-- First example: you can perform simple calculations.',
'-- (scroll down..)',
"-- Try hitting the 'run' button above.",
"-- When you're done, tap on the right margin to go to the next example.",
'2+3'
name='expr',
lines={
"-- Some examples; feel free to delete them and they'll never return.",
'-- First example: you can perform simple calculations.',
"-- (scroll down if you're on a small screen..)",
"-- Try hitting the 'run' button above.",
"-- When you're done, tap on the right margin to go to the next example.",
'2+3',
}
},
{
'-- print() calls show up in the area below.',
"-- Hit 'run' and then scroll through the results.",
'for i=1,20 do print(i) end',
name='print',
lines={
'-- print() calls show up in the area below.',
"-- Hit 'run' and then scroll through the results.",
'for i=1,20 do print(i) end',
},
},
{
'-- You can draw on the screen.',
"-- After you hit 'run', try hitting 'hide'.",
'love.graphics.line(100,100, 200,300)'
name='draw',
lines={
'-- You can draw on the screen.',
"-- After you hit 'run', try hitting 'hide'.",
'love.graphics.line(100,100, 200,300)',
},
},
{
'-- some color',
'love.graphics.setColor(1,0,0)',
"love.graphics.rectangle('fill', 100,100, 200,300)",
name='color',
lines={
'-- some color',
'love.graphics.setColor(1,0,0)',
"love.graphics.rectangle('fill', 100,100, 200,300)",
},
},
{
'-- A checkerboard',
'-- Notice Safe_width and Safe_height for the bounds of the screen.',
'n = 100',
'for x=0,Safe_width,n do',
' for y=0,Safe_height,n do',
' if (x+y)/n%2 == 0 then',
' love.graphics.setColor(0.9, 0.7, 0.7)',
' else',
' love.graphics.setColor(0.7, 0.7, 0.9)',
' end',
" love.graphics.rectangle('fill', x,y, n,n)",
' end',
'end',
name='pattern',
lines={
'-- A checkerboard',
'-- Notice Safe_width and Safe_height for the bounds of the screen.',
'n = 100',
'for x=0,Safe_width,n do',
' for y=0,Safe_height,n do',
' if (x+y)/n%2 == 0 then',
' love.graphics.setColor(0.9, 0.7, 0.7)',
' else',
' love.graphics.setColor(0.7, 0.7, 0.9)',
' end',
" love.graphics.rectangle('fill', x,y, n,n)",
' end',
'end',
},
},
{
'-- For animations, you can define various functions that will get called for you.',
'-- LÖVE supports functions of the form love.*,',
'-- for example, love.draw, love.update, etc.',
"-- You can't define those directly because Carousel Shell needs to define them for its UI, but you can define your own under car.*,",
'-- for example, car.draw, car.update, etc.',
'Radius, dRadius = 100, 10',
'function car.draw()',
" love.graphics.circle('fill', 100,100, Radius)",
'end',
'',
'function car.update(dt)',
' Radius = Radius+dRadius',
' if Radius > 500 then dRadius = -dRadius end',
' if Radius < 30 then dRadius = -dRadius end',
'end',
name='animation',
lines={
'-- For animations, you can define various functions that will get called for you.',
'-- LÖVE supports functions of the form love.*,',
'-- for example, love.draw, love.update, etc.',
"-- You can't define those directly because Carousel Shell needs to define them for its UI, but you can define your own under car.*,",
'-- for example, car.draw, car.update, etc.',
'Radius, dRadius = 100, 10',
'function car.draw()',
" love.graphics.circle('fill', 100,100, Radius)",
'end',
'',
'function car.update(dt)',
' Radius = Radius+dRadius',
' if Radius > 500 then dRadius = -dRadius end',
' if Radius < 30 then dRadius = -dRadius end',
'end',
},
},
{
'-- For interactivity, LÖVE provides functions like love.keypressed, love.mousepressed, etc.',
'-- As before, define the corresponding car.keypressed, car.mousepressed, etc.',
"-- A pane's interactive events only activate when the editor is hidden using the 'hide' button above.",
"-- Try running this example and then pressing and holding the mouse and pressing and releasing keys.",
'-- Then try hiding the editor and again pressing and holding the mouse and pressing and releasing keys',
'X, Y, dX = 100, 0, 10',
"Log = ''",
'',
'function car.draw()',
' love.graphics.line(X,Y, X,Y+300)',
' love.graphics.print(Log, 50,50)',
'end',
'',
'function car.update(dt)',
' if X > 500 then dX = -dX end',
' if X < 100 then dX = -dX end',
' X = X+dX',
'end',
'',
'function car.mousepressed(x,y, button)',
' Y = y',
'end',
'',
'function car.mousereleased(x,y, button)',
' Y = 0',
'end',
'',
'function car.keypressed(key)',
' Log = Log..key',
'end',
name='interactive',
lines={
'-- For interactivity, LÖVE provides functions like love.keypressed, love.mousepressed, etc.',
'-- As before, define the corresponding car.keypressed, car.mousepressed, etc.',
"-- A pane's interactive events only activate when the editor is hidden using the 'hide' button above.",
"-- Try running this example and then pressing and holding the mouse and pressing and releasing keys.",
'-- Then try hiding the editor and again pressing and holding the mouse and pressing and releasing keys',
'X, Y, dX = 100, 0, 10',
"Log = ''",
'',
'function car.draw()',
' love.graphics.line(X,Y, X,Y+300)',
' love.graphics.print(Log, 50,50)',
'end',
'',
'function car.update(dt)',
' if X > 500 then dX = -dX end',
' if X < 100 then dX = -dX end',
' X = X+dX',
'end',
'',
'function car.mousepressed(x,y, button)',
' Y = y',
'end',
'',
'function car.mousereleased(x,y, button)',
' Y = 0',
'end',
'',
'function car.keypressed(key)',
' Log = Log..key',
'end',
},
},
{
'-- Some abbreviations to reduce typing.',
'g = love.graphics',
'points, line, rectangle, polygon, circle, arc, ellipse = g.points, g.line, g.rectangle, g.polygon, g.circle, g.arc, g.ellipse',
'color, bgColor = g.setColor, g.setBackgroundColor',
"-- Enough abbreviations, let's draw.",
'color(1,0,0) bgColor(0,1,0)',
'line(100,100, 200,300)',
"circle('fill', 200,100, 30)",
'-- once you load this pane, the abbreviations here will be available in any other pane',
name='abbreviations',
lines={
'-- Some abbreviations to reduce typing.',
'g = love.graphics',
'points, line, rectangle, polygon, circle, arc, ellipse = g.points, g.line, g.rectangle, g.polygon, g.circle, g.arc, g.ellipse',
'color, bgColor = g.setColor, g.setBackgroundColor',
"-- Enough abbreviations, let's draw.",
'color(1,0,0) bgColor(0,1,0)',
'line(100,100, 200,300)',
"circle('fill', 200,100, 30)",
'-- once you load this pane, the abbreviations here will be available in any other pane',
},
},
{
"-- Over to you. We hope you enjoy Carousel Shell!",
'',
}
name='beginning',
lines={
"-- Over to you. We hope you enjoy Carousel Shell!",
'',
},
},
}

5
0112-load_example_panes Normal file
View File

@ -0,0 +1,5 @@
load_example_panes = function()
for _,ex in ipairs(Example_panes) do
table.insert(Panes, example_pane(ex.name, ex.lines))
end
end