aboutsummaryrefslogtreecommitdiff
path: root/src/sysapp/login
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2017-05-09 20:43:00 +0200
committerAlex Auvolat <alex@adnab.me>2017-05-09 20:43:00 +0200
commitb74a9f0c4b73bc3b98ec6c4345d9aaf4b6279f7a (patch)
treeedda3126acf99a0c9131c6ef293e8c69259a48b2 /src/sysapp/login
parent83cc53def0abb6f44ebd95a7175e717e3c66cd48 (diff)
downloadkogata-b74a9f0c4b73bc3b98ec6c4345d9aaf4b6279f7a.tar.gz
kogata-b74a9f0c4b73bc3b98ec6c4345d9aaf4b6279f7a.zip
Simili file manager
Diffstat (limited to 'src/sysapp/login')
-rw-r--r--src/sysapp/login/main.lua113
1 files changed, 102 insertions, 11 deletions
diff --git a/src/sysapp/login/main.lua b/src/sysapp/login/main.lua
index 0303c4f..a246c87 100644
--- a/src/sysapp/login/main.lua
+++ b/src/sysapp/login/main.lua
@@ -25,7 +25,7 @@ local wm = tk.window_manager()
tk.init(gui, wm)
local img = tk.image(f)
-wm:add(img, "Window 1", 100, 16)
+wm:add({title = "Window 1", x = 100, y = 16}, img)
local img2 = tk.box({
center_content = true,
vscroll = true,
@@ -33,27 +33,118 @@ local img2 = tk.box({
vresize = true,
hresize = true,
}, tk.image(f))
-wm:add(img2, "Window 2", 16, 100)
+wm:add({title = "Window 2", x = 16, y = 100}, img2)
local img3 = tk.box({
constrain_size = true,
vresize = true,
hresize = true,
}, tk.image(f))
-wm:add(img3, "Window 3", 300, 150)
+wm:add({title = "Window 3", x = 300, y = 150}, img3)
local txt = tk.text({color = tk.rgb(0, 255, 0), width=200}, "Hello, world!\nThis is a long text")
-wm:add(txt, "Text example", 32, 32)
+wm:add({title = "Text example", x = 32, y = 32}, txt)
+
+
+function alert(text, on_dismiss)
+ local win = {}
+ win.widget =
+ tk.grid({},
+ { { tk.text({padding = 16}, text) },
+ { tk.box({center_content = true, height = 40},
+ tk.text({background = tk.rgb(0, 255, 0),
+ padding = 4,
+ on_click = function() win.close() end},
+ "Ok"))
+ } })
+ win.close = function()
+ sys.dbg_print("Hello!")
+ wm:remove(win.win)
+ if on_dismiss then on_dismiss() end
+ end
+ win.win = wm:add({title = "Alert",
+ x = math.random(0, gui.surface:width() - 100),
+ y = math.random(0, gui.surface:height() - 100),
+ }, win.widget)
+end
+
+function loopy()
+ alert("Hello, world !!", loopy)
+ gui.hide_cursor()
+ gui.surface:fillrect(0, 0, gui.surface:width(), gui.surface:height(), gui.surface:rgb(0, 0, 0))
+ gui.show_cursor()
+ wm:redraw(0, 0, gui.surface:width(), gui.surface:height())
+end
+loopy()
+
+-- A small file manager test :)
+
+local function open_listing(path)
+ local function fileline(name, path, size)
+ return {
+ tk.text(name),
+ tk.text(tostring(size)),
+ tk.box({center_content = true, width = 32},
+ tk.text({background = tk.rgb(128, 128, 255),
+ padding =2,
+ text_size = 12,
+ on_click = function() open_listing(path) end},
+ "open"))
+ }
+ end
+ local griditems = {
+ { tk.box({hresize = true, width = 200, constrain_size = true, min_width = 16, control_size = 8}, tk.text("Name")),
+ tk.box({hresize = true, width = 75, constrain_size = true, min_width = 16, control_size = 8}, tk.text("Size")),
+ tk.box({constrain_size = true}, tk.text("Actions"))
+ }
+ }
+ local fd = sys.open(path, sysdef.FM_READDIR)
+ if not fd then
+ alert("Could not FM_READDIR " .. path)
+ return
+ end
+
+ local i = 0
+ while true do
+ x = sys.readdir(fd, i)
+ if not x then break end
+ table.insert(griditems, fileline(x.name .. (x.type & sysdef.FT_DIR ~= 0 and "/" or ""),
+ path .. x.name .. "/",
+ x.size))
+ i = i + 1
+ end
+ sys.close(fd)
+
+ local grid = tk.grid({border_size = 1}, griditems)
+ wm:add({title = path,
+ x = math.random(0, gui.surface:width() - 100),
+ y = math.random(0, gui.surface:height() - 100)},
+ tk.box({vresize = true, hresize = true, vscroll = true, hscroll = true}, grid))
+end
+
+local function fsline(fs)
+ return {
+ tk.text(fs .. ":/"),
+ tk.box({center_content = true, width = 32},
+ tk.text({background = tk.rgb(128, 128, 255),
+ padding =2,
+ text_size = 12,
+ on_click = function() open_listing(fs .. ":/") end},
+ "open"))
+ }
+end
local grid = tk.grid({border_size = 1}, {
{ tk.box({hresize = true, width = 200, constrain_size = true, min_width = 16, control_size = 8}, tk.text("Name")),
- tk.box({hresize = true, width = 100, constrain_size = true, min_width = 16, control_size = 8}, tk.text("Size")) },
- { tk.text("File A"), tk.text("10k") },
- { tk.text("File B"), tk.text("20k") },
- { tk.text("File C"), tk.text("15k") },
+ tk.box({constrain_size = true}, tk.text("Actions"))
+ },
+ fsline("io"),
+ fsline("root"),
+ fsline("config"),
+ fsline("app"),
+ fsline("sys"),
})
-wm:add(tk.box({vresize = true, hresize = true, vscroll = true, hscroll = true}, grid),
- "Grid example", 300, 20)
-
+wm:add({title = "Filesystems", x = 300, y = 20},
+ tk.box({vresize = true, hresize = true, vscroll = true, hscroll = true}, grid))
mainloop.run()