new fork: a template for carousel-based apps

This commit is contained in:
Kartik K. Agaram 2024-03-15 22:52:27 -07:00
parent fe06035b9d
commit cd278f9a85
6 changed files with 54 additions and 68 deletions

View File

@ -1,12 +1,19 @@
# Lua Carousel
# A template repo for developing cross-platform apps on mobile devices
![screenshot](assets/1.png)
A lightweight environment for writing small, throwaway
[Lua](https://www.lua.org) and [LÖVE](https://love2d.org) programs. Tested on
Windows, Mac, Linux, iOS and Android. The environment itself can be modified
as it runs. In early release; please report issues, particularly with
usability or accessibility.
Copy this repo to get a leg up creating tiny, low-maintenance, cross-platform
apps that you can make changes to right on a phone or tablet.
It comes bundled with a few optional goodies:
* Support for tap-to-pan and pinch-to-zoom gestures over an infinite 2D
surface for arbitrary graphics and UI.
* A tiny widget library for quickly creating arbitrary UI elements.
[Here's an example of the kinds of things you can add to the global variable `widgets`.](https://akkartik.itch.io/carousel/devlog/665231/a-sprite-editor-in-100-lines-of-code)
* A typographic scale for scaling the font size of text in visually pleasing
increments.
Tap the 'edit' button and then poke around the 'load' menu to learn more.
This repo is an example of a [Freewheeling App](http://akkartik.name/freewheeling),
designed above all to be easy to run, easy to modify and easy to share.
@ -20,14 +27,16 @@ extremely well-behaved.
## Hacking
To modify it live without restarting the app each time, download [the driver
app](https://git.sr.ht/~akkartik/driver.love). Here's an example session
using a fork of this repo:
You can edit the app and UI right on your device.
You can also modify the editing environment itself, or repurpose it for a
different app entirely, live as it runs. This requires running it on a
computer. Download [the driver app](https://git.sr.ht/~akkartik/driver.love).
Here's an example session showing the driver (left window) editing a different
app (right window containing yellow text):
![making changes without restarting the app](assets/2.gif)
(Only on non-mobile platforms for now.)
[Some reference documentation on how to create your own apps.](reference.md)
If the app being modified by the driver lives in a .love file, your changes
@ -66,21 +75,19 @@ found anything amiss: http://akkartik.name/contact
* Some colors can't be customized yet.
## Contributors
Many thanks to Mike Stein for code, feedback and suggestions.
## Mirrors and Forks
This repo is a fork of [lines.love](http://akkartik.name/lines.html), an
editor for plain text where you can also seamlessly insert line drawings.
Its immediate upstream is [the template repo for freewheeling apps](https://git.sr.ht/~akkartik/template-live-editor).
Updates to it can be downloaded from the following mirrors:
Its immediate upstream is [Lua Carousel, a lightweight cross-platform
environment for creating little throwaway scripts on a computer or
phone](https://git.sr.ht/~akkartik/carousel.love). Updates to it can be
downloaded from the following mirrors:
* https://git.sr.ht/~akkartik/carousel.love
* https://tildegit.org/akkartik/carousel.love
* https://git.merveilles.town/akkartik/carousel.love
* https://nest.pijul.com/akkartik/carousel.love (using the Pijul version control system)
* https://git.sr.ht/~akkartik/template-carousel-mobile
* https://tildegit.org/akkartik/template-carousel-mobile
* https://git.merveilles.town/akkartik/template-carousel-mobile
* https://nest.pijul.com/akkartik/template-carousel-mobile (using the Pijul version control system)
Further forks are encouraged. If you show me your fork, I'll link to it here.

View File

@ -1,3 +1,4 @@
function love.conf(t)
t.identity = 'dash2'
t.identity = 'TODO'
t.window.title = 'TODO'
end

View File

@ -55,7 +55,7 @@ function App.initialize(arg)
-- keep a few blank lines around: https://merveilles.town/@akkartik/110084833821965708
love.window.setTitle('Dash')
-- setTitle moved to conf.lua

View File

@ -1,8 +1,18 @@
function draw_hud()
local stop_app_label = 'edit'
button(ui_state, stop_app_label, {x=5, y=Safe_height-10-Line_height-10,
w=5+App.width(stop_app_label)+5, h=5+Line_height+5,
bg=Menu_background,
icon = function(p)
App.color(Normal_color)
rect('line', p.x,p.y, p.w,p.h)
g.print(stop_app_label, p.x+5, p.y+5)
end,
onpress1 = stop_app,
})
color(0.5, 0.5, 0.5)
for _,touch in ipairs(touches()) do
if curr[touch] then
circle('fill', curr[touch].x, curr[touch].y, 10)
end
for _,touch_id in ipairs(touches()) do
local x,y = touch(touch_id)
circle('fill', x,y, 10)
end
end

View File

@ -1,18 +1,14 @@
-- top-level handlers for dash's event loop
-- main responsibilities:
-- render widgets based on current viewport settings
-- dispatch keyboard and touch events to appropriate widget
-- pan viewport based on one-finger touch (from either mouse or touchscreen)
-- adjust zoom based on two-finger touch (touchscreen only)
ui_state = {} -- for buttons; recreated each frame
widgets = {} -- more versatile UI elements
function car.draw()
color(0, 0.6,0.6)
line(Safe_width-120, 0, Safe_width-120, 40)
g.setFont(Font)
local s = App.width('exit')
line(Safe_width-120, 40, Safe_width-s-20, 40)
line(Safe_width-s-20, 40, Safe_width-s-20, 110)
line(Safe_width-s-20, 110, Safe_width+100, 110)
ui_state.button_handlers = {}
for _,w in ipairs(widgets) do w.draw() end
draw_hud()
end
@ -27,6 +23,10 @@ end
function car.mouse_press(x,y, b)
skip_touch = nil
if mouse_press_consumed_by_any_button(ui_state, x,y, b) then
skip_touch = true
return
end
cursor = nil
for _,w in ipairs(widgets) do
if w.ispress(x,y) then
@ -77,7 +77,7 @@ function car.touch_move(id, x,y, ...)
end
end end end
function car.mouse_release(x,y, b)
function car.mouse_release(x,y, b)
for _,w in ipairs(widgets) do
if w.release then w.release(x,y, b) end
end

View File

@ -1,32 +0,0 @@
widgets = {}
-- button to add a text box
table.insert(widgets, {
draw = function()
color(0, 0.6,0.6)
rect('line', Safe_width-115, 5, 30,30, 5)
line(Safe_width-110, 20, Safe_width-90, 20)
line(Safe_width-100, 10, Safe_width-100, 30)
end,
ispress = function(x2,y2)
return x2 >= Safe_width-120 and x2 <= Safe_width-85 and y2 <= 40
end,
press = add_editor,
})
-- button to stop the app and return to the source editor
table.insert(widgets, {
draw = function()
color(0, 0.6,0.6)
g.setFont(Font)
local s = App.width('exit')
rect('line', Safe_width-s-15, 75, s+10,30, 5)
g.print('exit', Safe_width-s-10, 80)
end,
ispress = function(x2,y2)
g.setFont(Font)
local s = App.width('exit')
return x2 >= Safe_width-s-15 and y2 >= 75 and y2 <= 105
end,
press = stop_app,
})