aboutsummaryrefslogblamecommitdiff
path: root/src/sysapp/login/main.lua
blob: 67ce3feb7ed7d25f450d52d274628bc2f3fd05ea (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                            

                                 
                              
 

                                      
 

                          
                      
 

                                            
                 
 


                                                                            


           
                                           
                              

                
                       
                                                  






                                              
                                                   




                                              
                                                    
 
                                                                                                 








                                                                

                                                                                                     































                                                                                                       

                                                                                                





































                                                                                                                                    

                                                                                        



                                                                                             
 

                                                                                                                            






                                                                   
          

                                                                                          
 

              
         
local sys = require 'lx.sys'
local sysdef= require 'lx.sysdef'
local ioctl = require 'lx.ioctl'
local draw = require 'lx.draw'

local gui = require 'lx.gui'
local mainloop = require 'lx.mainloop'

local tk = require 'lx.tk'

print("Hello, world!")

gui.open()
gui.load_cursor('sys:/cursors/left_ptr.png')
gui.show_cursor()

for x = 0, 255, 16 do
	for y = 0, 255, 16 do
		gui.surface:fillrect(x, y, 16, 16, gui.surface:rgb(x, y, 0))
	end
end

local f = draw.load_image('root:/logo.png')
local wm = tk.window_manager()
tk.init(gui, wm)

local img = tk.image(f)
wm:add({title = "Window 1", x = 100, y = 16}, img)
local img2 = tk.box({
			center_content = true,
			vscroll = true,
			hscroll = true,
			vresize = true,
			hresize = true,
		}, tk.image(f))
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({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({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.theme.colors.button.good.bg(tk),
				   			color = tk.theme.colors.button.good.text(tk),
				   			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.theme.colors.button.action.bg(tk),
						 color = tk.theme.colors.button.action.text(tk),
						 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.theme.colors.button.action.bg(tk),
					 color = tk.theme.colors.button.action.text(tk),
					 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({constrain_size = true}, tk.text("Actions"))
	  },
	  fsline("io"),
	  fsline("root"),
	  fsline("config"),
	  fsline("app"),
	  fsline("sys"),
	})
wm:add({title = "Filesystems", x = 300, y = 20},	
	   tk.box({vresize = true, hresize = true, vscroll = true, hscroll = true}, grid))

mainloop.run()

os.exit()