Hmm... this isn't a bad idea
Actually I just created the functions
win:show() and
win:hide() instead of
scr:add(win) and
scr:remove(win) .
In my point of view, only windows should be addable to the "screen", but you may add anything to a window.
There is less flexibility indeed, but you still may do everything you want
About the designer: again this is a good idea, but it will require a lot of work. I really don't have time for that... maybe someone else will make it later
Here is a list of the functions so far (There isn't many explanations, but I will explain it in details later
)
W - an UI widget
C - an UI component
P - a picture
T - a string
I - an index
N - a number
X,Y,W,H - x, y, width, heigth
-------------------------------------------------------------
-- GENERAL
-------------------------------------------------------------
-- loads the UI package
require("ui")
-- start the UI mode (main loop waiting for events)
ui.start()
-- stop it (may be restarted later)
ui.stop()
-------------------------------------------------------------
-- WINDOWS
--
-- General interface to hold and display the UI components.
-- You may create new UI windows with 'ui.window()'
-- Components (like widgets, buttons, ...) may be added to
-- this kind of windows, and events may be defined.
-- You may also access the other windows from CPLua (like the
-- console window), but you cannot add components or define
-- events for it. You may hide/show/resize it however.
-------------------------------------------------------------
-- create a new (hidden) UI window
-- NAME (string) = name of the window (should be unique for each win)
-- FRAME = "none", "thin" or "thick" (optional, default: thin)
win = ui.window({name=NAME, x=..., y=..., width=..., heigth=..., frame=FRAME})
-- set the scroll mode
-- MODE = "auto_v", "v", "auto_h", "h", "auto" or "none"
win:setscroll(MODE)
T = win:getscroll()
-- return the background picture of the window
-- use the DRAW package to draw on it
P = win:getpict()
-- refresh the window (call it after drawing operations on its picture)
win:update()
-- add or remove some components
win:add(C)
win:remove(C)
win:removeall()
-- return a window by its name
-- use "Console" as name for the console window
-- and "Graph" for the graph window
win = ui.getwin(NAME)
-- the following functions work for all type of windows (not only UI)
win:setsize(X,Y,W,H)
X,Y,W,H = win:getsize()
T = win:getframe()
win:show(HIDE_OTHERS) -- HIDE_OTHERS (bool) is optional (default: false)
win:hide()
T = win:getname()
T = win:gettype()
-- UI Window events
-- define these functions to catch the events
function win:_pendown(x,y) ... end
function win:_penmove(x,y) ... end
function win:_penup(x,y) ... end
function win:_keydown(key) ... end
function win:_keyup(key) ... end
function win:_sized(x,y,w,h) ... end
function win:_parentsized(x,y,w,h) ... end
-------------------------------------------------------------
-- WIDGETS
--
-- A basic component that can act as a container for other
-- components. You may also define events for it.
-- Use it to define some scrollable area inside windows
-- or to create some new kind of custom component.
-------------------------------------------------------------
-- create a new widget
-- FRAME = "none", "thin" or "thick" (optional, default: none)
wid = ui.widget({x=..., y=..., width=..., height=..., frame=FRAME})
-- set the scroll mode
-- MODE = "auto_v", "v", "auto_h", "h", "auto" or "none"
wid:setscroll(MODE)
T = wid:getscroll()
-- return the background picture of the widget
-- use the DRAW package to draw on it
P = wid:getpict()
-- refresh the widget (call it after drawing operations on its picture)
wid:update()
-- add or remove some components
wid:add(C)
wid:remove(C)
wid:removeall()
wid:setsize(X,Y,W,H)
X,Y,W,H = wid:getsize()
T = wid:getframe()
-- Widget events
-- define these functions to catch the events
function wid:_pendown(x,y) ... end
function wid:_penmove(x,y) ... end
function wid:_penup(x,y) ... end
function wid:_keydown(key) ... end
function wid:_keyup(key) ... end
function wid:_sized(x,y,w,h) ... end
function wid:_parentsized(x,y,w,h) ... end
-------------------------------------------------------------
-- NOTEBOOKS
--
-- A container that can manage several widgets and organize
-- it with text-decorated tabs.
-- Each "page" consists of a widget (which holds the content of
-- the page) and its title (which is written on the tab).
-- Each of those widgets may contain several components.
-- You may replace all widgets by some other ones.
-------------------------------------------------------------
nb = ui.notebook({x=..., y=..., width=..., height=..., frame=FRAME})
X,Y,W,H = nb:getsize()
nb:setsize(X,Y,W,H)
T = nb:getframe()
-- get properties of the page with number "I"
T = nb:gettitle(I)
W = nb:getwidget(I)
T,W = nb:getpage(I)
-- or replace it
nb:settitle(I,T)
nb:setwidget(I,W)
nb:setpage(I,T,W)
-- change pages number
nb:setnbrpages(N)
N = nb:getnbrpages()
nb:insertpage(I,T,W) -- T and W are optional
T,W = nb:removepage(I)
nb:addpage(T,W) -- T and W are optional
-- get or set the current page
nb:setcurrent(I)
I = nb:getcurrent()
-- event: if defined, this function will be called
-- each time the current page change.
function nb:_currentchanged(I) ... end
-------------------------------------------------------------
-- BUTTON
--
-- A simple, text-decorated button.
-------------------------------------------------------------
b = ui.button({text=TEXT, x=..., y=..., width=...}) -- width is optional
X,Y,W,H = b:getsize()
b:setsize(X,Y,W,H)
T = b:gettext()
b:settext(T)
-- event: if defined, this function will be called
-- each time the button is clicked.
function b:_clicked() ... end
-------------------------------------------------------------
-- TEXTEDIT
--
-- An editable text area.
-------------------------------------------------------------
t = ui.textedit({x=..., y=..., width=..., height=..., frame=FRAME})
X,Y,W,H = t:getsize()
t:setsize(X,Y,W,H)
T = t:getframe()
T = t:gettext()
N = t:getlength()
t:settext(T)
t:append(T)
t:clear()
t:cut()
t:copy()
t:paste()
t:undo()
Other planned components : lineedit, spinbox, combobox, menus, toolbars, ... + additional features
I tried to make it as simple and intuitive as possible, but if you already have some suggestions, just let me know.
For example, I'm thinking of adding an optional field "_clicked" in
ui.button(), then you could write
win:add( ui.button{text="btn", x=5, y=5,
_clicked = function(self)
...
end
})
as well as
b = ui.button{text="btn", x=5, y=5}
function b:_clicked()
...
end
win:add(b)