-- The c8ui gallery (toolkit/c8ui/examples/gallery.c) in Lua, looking and acting
-- the same: text views, a list of 5000 items in rows or a grid, a hub, a
-- pivot of small controls, a flyout, progress bars and rings, the app bar
-- (right click the list, or the Menu key anywhere), pickers (numbers,
-- stars, dates, times, a calendar), layout (grid, expander, split, flip
-- view, info bars) and a tree beside a details list with column headers,
-- and more: a search box with suggestions, a menu with ticks and
-- submenus, a strip that scrolls sideways and a semantic zoom (Ctrl+wheel,
-- Ctrl+minus, a pinch). Reader: rich text in columns and linked boxes, a
-- viewbox. Tiles & media: toggle and repeat buttons, item containers,
-- media controls, cells that span, the nav bar (F2, or its button) and
-- the settings flyout.
--
-- Run it with `c8-lua gallery.lua`.
local c8 = require "c8"
local ITEMS = 5000
local icons = { "folder", "text-x-generic", "image-x-generic",
"audio-x-generic", "video-x-generic", "application-pdf" }
local page_names = { "Text", "List", "Hub", "Pivot", "Progress", "Pickers",
"Layout", "Tree", "More", "Reader", "Tiles & media" }
local win, bar, navbar, nav, pages, status, status_box
local list, columns, stack, transport, step_label
-- Narrow: the page list or a page, with a back bar over the page
local side, right, back_bar, back_title, split
local page_list = {}
local narrow, in_page = false, false
local media_position, playing, step = 0, false, 0
-- A colour from cairo's 0 to 1
local function rgb(r, g, b)
local function byte(v) return math.floor(v * 255 + 0.5) end
return byte(r) << 16 | byte(g) << 8 | byte(b)
end
-- A page's margins and big title, smaller and gone when narrow (the back
-- bar names the page then)
local function page_pad(box)
box:padding(40, 30, 40, 20)
box:narrow_padding(16, 8, 16, 12)
end
local function page_title(box, text)
box:add(c8.label { text = text, style = "header", narrow_hidden = true })
end
local function say(s)
status:set(s)
end
local function column(what, n)
local box = c8.column { spacing = 8 }
for i = 1, n do
box:add(c8.label { text = what .. " " .. i, style = "item" })
end
return c8.scroll { box, fill = true, expand = true }
end
local function show_flyout(button)
win:flyout { at = button,
c8.column { spacing = 12, width = 320,
c8.label { text = "Rename", style = "title" },
c8.entry { text = "Holiday photos", fill = true },
c8.button { label = "Rename",
on_click = function() say("Renamed (not really)") end },
},
closed = function() say("The flyout closed") end,
}
end
local function controls_pivot()
local ring = c8.ring { size = 40 }
local forms = c8.column { spacing = 14,
c8.entry { search = true, placeholder = "Search",
on_enter = function(_, text)
say(string.format("Searched for \"%s\"", text))
end },
c8.checkbox { label = "Loading", checked = true,
on_change = function(_, on) ring:set(on) end },
ring,
c8.radio { header = "Mode",
items = { "Standard", "Scientific", "Converter" } },
c8.button { label = "Rename…", on_click = show_flyout },
}
-- A picture drawn here, as there are none to load
local pic = c8.draw_picture(480, 320, function(g)
g:paint(c8.gradient(0, 0, 0, 320, {
{ 0, rgb(0.1, 0.35, 0.75) }, { 1, rgb(0.95, 0.6, 0.3) } }))
g:circle(330, 200, 50, rgb(1, 0.9, 0.5))
g:shape({ 0, 320, 0, 230, 140, 160, 260, 250, 480, 210, 480, 320 },
rgb(0.1, 0.2, 0.15))
end)
local pictures = c8.row { spacing = 20, wrap = true,
c8.image { image = pic, width = 320, height = 0 },
c8.image { image = pic, width = 200, height = 200, fit = "cover" },
}
-- Windows Phone's way: the app's name over headers that go round
return c8.pivot { expand = true, title = "c8ui gallery", wrap = true,
tabs = {
{ title = "controls", c8.scroll { forms } },
{ title = "pictures", pictures },
{ title = "a long list", column("Row", 60) },
},
}
end
local function hub()
-- A wide picture behind it all, to show it panning slower than the
-- sections: dusk with a skyline along the bottom
local sky = c8.draw_picture(1800, 600, function(g)
g:paint(c8.gradient(0, 0, 1800, 600, {
{ 0, rgb(0.10, 0.05, 0.25) }, { 1, rgb(0.45, 0.12, 0.20) } }))
for x = 0, 1799, 70 do
local tall = 60 + (x * 37 % 170)
g:rect(x, 600 - tall, 56, tall, 0x000000, 0.45)
end
end)
return c8.hub { title = "Music", expand = true, background = sky,
scheme = "dark", -- white text on it
sections = {
{ header = "Now playing", width = 360, column("Song", 40) },
{ header = "Albums", width = 360, column("Album", 40) },
{ header = "Artists", width = 360, column("Artist", 40) },
{ header = "Radio", width = 360, column("Station", 6) },
},
}
end
-- Pickers
local function number_changed(what)
return function(_, value) say(string.format("%s: %g", what, value)) end
end
local function time_changed(_, h, m)
say(string.format("Time: %02d:%02d", h, m))
end
local function pickers_page()
return c8.row { spacing = 60, wrap = true,
c8.column { spacing = 20,
c8.number { header = "Copies", min = 1, max = 99, step = 1,
value = 2, digits = 0, on_change = number_changed("Copies") },
c8.number { header = "Margin (cm)", min = 0, max = 10, step = 0.25,
value = 2.5, digits = 2, on_change = number_changed("Margin") },
c8.label { text = "Your rating", style = "body" },
c8.rating { max = 5, value = 3, on_change = function(_, v)
say(string.format("Rated %g stars", v))
end },
c8.label { text = "Average (rest the pointer on it)", style = "body" },
c8.rating { max = 5, value = 3.6, readonly = true,
tooltip = "3.6 from 812 ratings" },
c8.date { header = "Date", year = 2026, month = 11, day = 2,
on_change = function(_, y, m, d)
say(string.format("Date: %04d-%02d-%02d", y, m, d))
end },
c8.time { header = "Alarm", hour = 7, minute = 30, minute_step = 5,
on_change = time_changed },
c8.time { header = "On a 12 hour clock", hour = 19, minute = 45,
clock24 = false, on_change = time_changed },
},
c8.calendar { year = 2026, month = 11, day = 2,
-- Something on every 3rd and 10th, and on Fridays the 13th
marks = function(_, _, day)
return day % 10 == 3 or day == 10 or day == 13
end,
on_change = function(_, y, m, d)
say(string.format("Picked %04d-%02d-%02d", y, m, d))
end },
}
end
-- Layout
local slide_colors = { 0x1ba1e2, 0x339933, 0xe51400, 0xf09609, 0x8cbf26 }
-- A picture to flip through: a colour and a number
local function slide(i)
local pic = c8.draw_picture(600, 300, function(g)
g:paint(slide_colors[(i - 1) % 5 + 1])
g:text(tostring(i), 260, 200, { size = 120, color = 0xffffff,
baseline = true })
end)
return c8.image { image = pic, width = 0, height = 0, fit = "cover",
fill = true }
end
local function layout_page()
local offline = c8.infobar { severity = "warning",
title = "You're offline",
message = "Changes are kept here and sent when you're back.",
closable = true }
offline:action("Try again", function() say("Trying again (not really)") end)
local flip = c8.flip { height = 260, dots = true,
on_change = function(_, n) say("Picture " .. n) end }
for i = 1, 5 do
flip:add(slide(i))
end
-- A wizard: a stack of steps, with a back button
stack = c8.stack { expand = true,
c8.label { text = "Step 1: pick a folder", style = "subheader" },
c8.label { text = "Step 2: choose what to copy", style = "subheader" },
c8.label { text = "Step 3: done", style = "subheader" },
}
local wizard = c8.row { spacing = 16,
c8.back_button { on_click = function()
local at = stack:get()
if at > 1 then
stack:set(at - 1, true)
else
say("Back (Alt+Left or the mouse's back button work too)")
end
end },
stack,
c8.icon_button { icon = "go-next", label = "Next", on_click = function()
stack:set(stack:get() % stack:count_children() + 1, true)
end },
c8.icon_button { icon = "media-playlist-shuffle", tooltip = "Shuffle",
toggle = true },
}
-- A form in a grid: labels in one column, fields in the other
local more = c8.grid { columns = 2, column_spacing = 20, row_spacing = 12,
column_widths = { 120, 0 }, expand_columns = { 2 },
c8.label { text = "Name", style = "body" },
c8.entry { text = "Ada", fill = true },
c8.label { text = "Server", style = "body" },
c8.entry { text = "mail.example.org", fill = true },
c8.label { text = "Port", style = "body" },
c8.number { min = 1, max = 65535, step = 1, value = 993, digits = 0 },
}
more:span(c8.checkbox { label = "Use TLS (spans both columns)",
checked = true }, 2)
return c8.column { spacing = 20,
offline,
c8.infobar { severity = "success", message = "Saved to Documents.",
closable = true },
c8.infobar { severity = "error", title = "Couldn't sync" },
flip,
wizard,
c8.separator {},
c8.expander { title = "Advanced settings", more },
}
end
-- Tree and details
local files = {
{ name = "Budget 2026.ods", kind = "Spreadsheet", size = "48 KB", kb = 48 },
{ name = "Holiday.jpg", kind = "Picture", size = "3.1 MB", kb = 3100 },
{ name = "Notes.md", kind = "Text", size = "2 KB", kb = 2 },
{ name = "Talk.odp", kind = "Presentation", size = "1.2 MB", kb = 1200 },
{ name = "Song.flac", kind = "Music", size = "28 MB", kb = 28000 },
{ name = "Invoice 112.pdf", kind = "PDF", size = "96 KB", kb = 96 },
}
local order = {}
local sort_column, sort_down = 1, false
local function sort_files()
local key = sort_column == 3 and "kb" or sort_column == 2 and "kind" or
"name"
table.sort(order, function(a, b)
local x, y = files[a][key], files[b][key]
if sort_down then
return x > y
end
return x < y
end)
end
local function tree_page()
-- Folders open to three more each, made up as they open
local filled = {}
local tree = c8.tree {
on_expand = function(tree, item)
if filled[item] then
return -- done before
end
filled[item] = true
for i = 0, 2 do
local child = tree:add(item, tree:label(item) .. " " ..
string.char(string.byte("a") + i), "folder")
tree:has_children(child, true)
end
end,
on_select = function(tree, item) say("Folder: " .. tree:label(item)) end,
}
for _, place in ipairs { "Documents", "Music", "Pictures", "Videos" } do
tree:has_children(tree:add(0, place, "folder"), true)
end
local details
columns = c8.columns {
columns = { { "Name", 220 }, { "Type", 140 }, { "Size", 100 } },
sort = 1,
on_change = function(_, column, down)
if column then
sort_column, sort_down = column, down
sort_files()
end
details:redraw()
end,
}
for i = 1, #files do
order[i] = i
end
sort_files()
details = c8.list { item_height = 40, count = #files, columns = columns,
click_opens = false,
item = function(i)
local f = files[order[i]]
return { cells = { f.name, { f.kind, secondary = true },
{ f.size, secondary = true } } }
end }
split = c8.split { position = 260, expand = true,
c8.scroll { tree },
c8.column { padding = { 12, 0, 0, 0 },
columns,
c8.scroll { details, expand = true, fill = true },
},
}
return split
end
-- More: suggestions, menus, sideways scrolling, semantic zoom
local fruit = { "Apple", "Apricot", "Avocado", "Banana", "Blackberry",
"Blueberry", "Cherry", "Clementine", "Coconut", "Cranberry", "Date",
"Dragon fruit", "Fig", "Grape", "Grapefruit", "Guava", "Kiwi", "Lemon",
"Lime", "Lychee", "Mango", "Melon", "Nectarine", "Orange", "Papaya",
"Peach", "Pear", "Pineapple", "Plum", "Pomegranate", "Raspberry",
"Strawberry", "Tangerine", "Watermelon" }
local wrap_on, sort_by = true, 1
local function show_menu(button)
win:menu { at = button,
items = {
{ "Cut", id = 1, shortcut = "Ctrl+X" },
{ "Copy", id = 2, shortcut = "Ctrl+C" },
{ "Paste", id = 3, shortcut = "Ctrl+V", disabled = true },
"-",
{ "Word wrap", id = 10, check = true, checked = wrap_on },
{ "Sort by", submenu = {
{ "Name", id = 20, radio = true, checked = sort_by == 0 },
{ "Date", id = 21, radio = true, checked = sort_by == 1 },
{ "Size", id = 22, radio = true, checked = sort_by == 2 },
"-",
{ "More", submenu = {
{ "Group by type", id = 30 },
{ "Group by date", id = 31 },
} },
} },
},
done = function(id)
if id == 10 then
wrap_on = not wrap_on
elseif id and id >= 20 and id < 23 then
sort_by = id - 20
end
say(id and ("Menu item " .. id) or "Menu dismissed")
end,
}
end
local function more_page()
local box = c8.column { spacing = 16, fill = true, expand = true }
page_pad(box)
page_title(box, "More")
box:add(c8.row { spacing = 20,
c8.entry { search = true, placeholder = "Search fruit (try \"p\")",
width = 320,
on_change = function(entry, typed)
local found = {}
local lower = typed:lower()
for _, f in ipairs(fruit) do
if #typed > 0 and f:sub(1, #typed):lower() == lower then
found[#found + 1] = f
end
end
entry:suggest(found)
end,
on_enter = function(_, text)
say(string.format("Looked for \"%s\"", text))
end },
c8.button { label = "Menu…", on_click = show_menu },
})
-- A strip of squares wider than the page
local strip = c8.row { spacing = 8 }
for i = 0, 23 do
local color = (0x1ba1e2 + i * 0x0b1d07) & 0xffffff
strip:add(c8.canvas { width = 110, height = 90,
draw = function(g, x, y, w, h) g:rect(x, y, w, h, color) end })
end
box:add(c8.scroll { strip, horizontal = true, height = 100, fill = true })
-- Semantic zoom: fruit by letter, and the letters
local zoom
local by_letter = c8.column { spacing = 4 }
local letters = c8.row { spacing = 8, wrap = true, padding = { 0, 8, 0, 0 } }
local last
for _, f in ipairs(fruit) do
local letter = f:sub(1, 1)
if letter ~= last then
last = letter
local header = c8.label { text = letter, style = "subheader",
color = "accent" }
by_letter:add(header)
letters:add(c8.button { label = letter, width = 64, height = 64,
on_click = function() zoom:show(header) end })
end
by_letter:add(c8.label { text = f, style = "item" })
end
zoom = c8.zoom { c8.scroll { by_letter }, letters,
on_change = function(_, out)
say(out and "Zoomed out: pick a letter" or "Zoomed in")
end }
box:add(zoom)
return box
end
-- From the Windows 8 samples: rich text in columns and linked boxes, a
-- viewbox, cells that span, item containers, toggle and repeat buttons,
-- media controls, the nav bar and the settings flyout
local article =
"<span size=\"xx-large\" weight=\"light\">The Metro style</span>\n" ..
"<i>Content before chrome.</i> Windows 8 made text the main thing on " ..
"the screen: large light headings, <b>generous margins</b> and body " ..
"copy that flows <span foreground=\"#1ba1e2\">from one column into the " ..
"next</span> instead of scrolling down a long page.\n\n" ..
"A reader app gives the text a height and lets the width follow. " ..
"Scroll sideways, with the wheel or a finger, and the columns come to " ..
"you. Resize the window and the text is laid out again without any " ..
"of it being lost between the columns.\n\n" ..
"The same text can be poured into boxes of your own: the first takes " ..
"as many lines as it has room for and hands the rest on. That is how " ..
"a magazine layout puts a picture or a pull quote in the middle of an " ..
"article. <b>Bold</b>, <i>italic</i>, <u>underline</u> and " ..
"<span size=\"large\">larger</span> text all work through Pango " ..
"markup.\n\n" ..
"Heading three\nMore words to make the third column worth having, and " ..
"a fourth: windows were once a thing you moved around; now they are " ..
"the thing you read through."
local function reader_page()
local box = c8.column { spacing = 16, fill = true, expand = true }
page_pad(box)
page_title(box, "Reader")
-- Columns across
box:add(c8.scroll { horizontal = true, height = 270, fill = true,
c8.rich_columns { markup = article, column_width = 280, gap = 40,
height = 260 } })
-- The same text through three boxes of our own
box:add(c8.label { text = "Linked boxes", style = "title" })
local first = c8.rich { markup = article, size = 13, justify = true,
width = 220, height = 130 }
local second = c8.rich_overflow { width = 220, height = 130 }
local third = c8.rich_overflow { width = 220, height = 130 }
first:overflow(second)
second:overflow(third)
box:add(c8.row { spacing = 20, wrap = true, -- fewer across when narrow
first, second, third })
-- A scaled picture of a widget
box:add(c8.label { text = "Viewbox", style = "title" })
box:add(c8.viewbox { width = 250, align = "start",
c8.column { spacing = 8, padding = 20, background = 0x1ba1e2,
width = 500,
c8.label { text = "800 px of heading", style = "header" },
c8.button { label = "Not clickable" },
} })
return box
end
local function transport_acted(t, action, value)
if action == "play" or action == "pause" then
playing = action == "play"
t:playing(playing)
say(playing and "Play" or "Pause")
elseif action == "seek" then
media_position = value
t:position(value)
say(string.format("Seek to %.0f s%s", value,
t:live() and " (dragging)" or ""))
elseif action == "volume" then
t:volume(value, false)
say(string.format("Volume %.0f%%", value * 100))
elseif action == "mute" then
t:volume(0.5, value > 0)
say(value > 0 and "Muted" or "Unmuted")
elseif action == "fullscreen" then
t:fullscreen(value > 0)
say(value > 0 and "Full screen" or "Left full screen")
elseif action == "previous" then
media_position = 0
t:position(0)
elseif action == "next" then
say("Next track")
end
end
local function stepped(by)
step = step + by
step_label:set("Held down: " .. step)
end
local function show_settings(wide)
local box = c8.column { spacing = 20,
c8.toggle { header = "Sync settings", on = true },
c8.slider { header = "Text size", min = 10, max = 30, step = 1,
value = 15 },
c8.checkbox { label = "Open links in a new window" },
}
for _ = 1, 12 do
box:add(c8.label { text = "More settings…", style = "body" })
end
win:settings { title = "Options", box, wide = wide,
closed = function() say("Settings flyout closed") end }
end
local function tiles_page()
local box = c8.column { spacing = 20, fill = true, expand = true }
page_pad(box)
page_title(box, "Tiles & media")
step_label = c8.label { text = "Hold + or −", style = "body" }
box:add(c8.row { spacing = 12, wrap = true,
c8.toggle_button { label = "Bold", on_change = function(_, on)
say(on and "Bold on" or "Bold off")
end },
c8.repeat_button { label = "−", on_click = function() stepped(-1) end },
c8.repeat_button { label = "+", on_click = function() stepped(1) end },
step_label,
c8.button { label = "Nav bar", on_click = function() navbar:show() end },
c8.button { label = "Settings",
on_click = function() show_settings(false) end },
c8.button { label = "Wide settings",
on_click = function() show_settings(true) end },
})
-- Item containers around anything
local items = c8.row { spacing = 12 }
for i = 1, 3 do
items:add(c8.item { width = 170, tap = i == 2 and "invoke" or "select",
c8.column { spacing = 4, padding = 12,
c8.label { text = "Item " .. i, style = "title" },
c8.label { text = i == 2 and "A tap only invokes" or
"A tap selects", style = "caption" },
},
on_invoke = function() say("Invoked") end,
on_select = function(_, selected)
say(selected and "Selected" or "Unselected")
end })
end
box:add(items)
-- Media transport
transport = c8.transport { duration = 215, buffered = 0.6, skip = true,
fullscreen = true, on_action = transport_acted }
c8.every(0.25, function()
if playing and not transport:live() then
media_position = media_position + 0.25
if media_position > 215 then
media_position = 0
end
transport:position(media_position)
end
end)
box:add(transport)
-- Cells that span
box:add(c8.scroll { fill = true, expand = true,
c8.list { item_width = 100, item_height = 100, count = 40,
multiple = true, click_opens = false,
-- Start's sizes: mostly small, some wide, a few big
spans = function(i)
if (i - 1) % 7 == 0 then
return 2, 2
elseif (i - 1) % 3 == 0 then
return 2, 1
end
return 1, 1
end,
draw = function(g, item)
local n = item.index - 1
g:rect(item.x, item.y, item.width, item.height,
(0x1ba1e2 + n * 0x0b1d07) & 0xffffff)
g:text(tostring(n), item.x + 8, item.y + item.height - 28,
{ style = "strong", color = 0xffffff, lines = 1 })
end },
})
return box
end
local function page(title, body)
local box = c8.column { spacing = 16, fill = true, expand = true }
page_pad(box)
page_title(box, title)
box:add(c8.scroll { body, fill = true, expand = true })
return box
end
-- Wide: the list beside the page. Narrow: one or the other filling the
-- window, like a phone app, the page under a back bar. Only which pane
-- shows and a few sizes are this one's: paddings are the boxes' own
-- (narrow_padding) and the split stacks itself. (An app would use
-- c8.pages, which does all of this; the gallery shows the parts.)
local function arrange()
local list_only = narrow and not in_page
side.width = narrow and 0 or 240
side.expand = narrow
nav:menu(narrow)
side.hidden = narrow and in_page
right.hidden = list_only
back_bar.hidden = not narrow
-- The folders over the files there (the split's own doing)
split:set(narrow and 220 or 260)
columns:width(1, narrow and 170 or 220)
columns:width(2, narrow and 120 or 140)
back_title:set(page_names[nav:get()])
if list_only then
nav:focus()
end
end
local function nav_changed(_, at)
for i, p in ipairs(page_list) do
p.hidden = i ~= at
end
in_page = true
arrange()
page_list[at]:enter()
end
local function go_back()
if not narrow or not in_page then
return
end
in_page = false
arrange()
side:enter()
end
local function add_page(p)
page_list[#page_list + 1] = p
pages:add(p)
end
local function build()
nav = c8.nav { items = page_names, on_change = nav_changed }
side = c8.column { width = 240, fill = true, background = 0xf0f0f0,
padding = { 0, 40, 0, 0 }, narrow_padding = { 0, 24, 0, 0 },
c8.column { padding = { 20, 0, 20, 16 },
c8.label { text = "Gallery", style = "header" } },
nav,
}
back_title = c8.label { text = "", style = "subheader", align = "center" }
back_bar = c8.row { spacing = 12, padding = { 16, 20, 16, 8 },
hidden = true,
c8.back_button { align = "center", on_click = go_back },
back_title,
}
pages = c8.column { expand = true, fill = true }
status = c8.label {
text = "Right click the list, or press the Menu key, for the app bar",
style = "caption", color = "secondary" }
status_box = c8.column { padding = { 40, 4, 40, 8 },
narrow_padding = { 16, 4, 16, 8 }, status }
right = c8.column { expand = true, fill = true, back_bar, pages, status_box }
-- Text
add_page(page("Text", c8.column { spacing = 16,
c8.text { framed = true, accepts_tab = false,
placeholder = "A framed one, for a form", height = 96 },
c8.text {
text = "Type here. Ctrl+Z undoes, Ctrl+Y or Ctrl+Shift+Z redoes.\n\n" ..
"Double click selects a word, three clicks a line, and dragging " ..
"after either goes on by words or lines. Up and Down keep to the " ..
"column they started in; Home goes to the indent, then the start.\n" ..
"\tTabs type a tab here; in the box above Tab moves on.",
on_change = function(view)
local line, col = view:position()
say(string.format("Line %d, column %d%s", line, col,
view:modified() and " (changed)" or ""))
end },
}))
-- List
list = c8.list { multiple = true, count = ITEMS, click_opens = false,
item = function(i)
local n = i - 1
return { title = "Item " .. i, subtitle = (n * 37) % 9000 .. " KB",
icon = icons[n % #icons + 1] }
end,
on_open = function(_, i) say("Opened item " .. i) end,
on_select = function(l) say(l:selected_count() .. " selected") end,
on_context = function() bar:show(true) end,
}
add_page(page("List", list))
-- Hub: edge to edge, its own title
add_page(hub())
-- Pivot
local pivot_page = c8.column { fill = true, expand = true }
page_pad(pivot_page)
pivot_page:add(controls_pivot())
add_page(pivot_page)
-- Progress
add_page(page("Progress", c8.column { spacing = 24,
c8.label { text = "Copying 3 items", style = "body" },
c8.progress { value = 0.35 },
c8.label { text = "Looking for updates", style = "body" },
c8.progress {},
}))
add_page(page("Pickers", pickers_page()))
add_page(page("Layout", layout_page()))
-- Tree: the split needs the page's height, so no scroll around it
local tree_box = c8.column { spacing = 16, fill = true, expand = true }
page_pad(tree_box)
page_title(tree_box, "Tree")
tree_box:add(tree_page())
add_page(tree_box)
add_page(more_page())
add_page(reader_page())
add_page(tiles_page())
for i = 2, #page_list do
page_list[i].hidden = true
end
return c8.row { fill = true, side, right }
end
c8.app {
id = "org.cont8nuum.LuaGallery",
open = function()
if win and win.open then
win:present()
return
end
win = c8.window { title = "Gallery", width = 1000, height = 700,
build(),
on_resize = function(_, _, _, now_narrow)
if now_narrow ~= narrow then
narrow = now_narrow
arrange()
end
end,
on_key = function(_, ev)
if ev.key == "F2" and navbar then
navbar:show()
return true
elseif ev.key == "Menu" then
bar:show()
return true
elseif ev.key == "Escape" and narrow and in_page then
go_back()
return true
end
return false
end,
}
bar = win:appbar()
bar:add { icon = "edit-select-all", label = "Select all",
on_click = function() list:select_all(true) end }
bar:add { icon = "edit-clear", label = "Clear selection",
on_click = function() list:select_all(false) end }
bar:add { icon = "view-grid", label = "Grid", right = true,
toggle = false,
on_click = function(cmd)
if cmd:get() then
list:mode("grid", 150, 130)
else
list:mode("rows", 0, 56)
end
end }
navbar = win:navbar()
for _, place in ipairs { "Home", "Photos", "Music", "Videos",
"Documents", "Downloads", "Settings", "Help", "Store", "People",
"Mail", "Maps" } do
navbar:place(place)
end
navbar:set(1)
navbar.on_choose = function(_, n) say("Nav bar: place " .. n) end
nav:focus() -- the arrows go through the pages
win:present()
end,
}