Skip to content
Gary McPherson edited this page Apr 8, 2017 · 7 revisions

AbsTK UI data is stored, sorted and returned as a table, by the run() function, for both Screens and Wizards. Data tables store widget data as key/value pairs, where key is the widget id and value varies depending on the widget type. For instance, the value of a text input is the string inside the field.

Screen

In this example:

local abstk = require 'abstk'
abstk.set_mode(...)

local scr = abstk.new_screen("Register Form")

scr:add_label('label', "Fill the fields to register")
scr:add_text_input('email', "E-mail")
scr:add_text_input('user', "Username")
scr:add_password('pswrd', "Password")
scr:add_checkbox('news', "Send me newsletter")

local data = scr:run()

Considering user input being:

E-mail: [email protected]
Username: admin
Password: admin123
Send me newsletter: *checked box*

data is like:

{
	label = "Fill the fields to register",
	email = "[email protected]",
	user = "admin",
	pswrd = "admin123",
	news = true,
}

Wizard

In this example:

local abstk = require 'abstk'
abstk.set_mode(...)

local wizard = abstk.new_wizard("Registration Wizard", 800, 600)

local scr1 = abstk.new_screen("Register")
local scr2 = abstk.new_screen("Thanks")

scr1:add_label('label', "Fill the fields to register")
scr1:add_text_input('email', "E-mail")
scr1:add_text_input('user', "Username")
scr1:add_password('pswrd', "Password")

scr2:add_label('thanks', "Thank you for your registration.")
scr2:add_checkbox('news', "Send me newsletter")

wizard:add_page('register_page', scr1)
wizard:add_page('thanks_page', scr2)

local data = wizard:run()

Considering user input being:

(On the first page)
E-mail: [email protected]
Username: admin
Password: admin123

(On the second page)
Send me newsletter: *checked box*

data is like:

{
	register_page = {
		label = "Fill the fields to register",
		email = "[email protected]",
		user = "admin",
		pswrd = "admin123",
	},
	thanks_page = {
		thanks = "Thank you for your registration.",
		news = true,
	}
}

IMPORTANT: As you can see, a Wizard doesn't only return the widgets' data, but also arranges them according to their page's data sub-table. This is not just a matter of organization, but also because of the fact that widgets, on Wizards, can be homonymous. Since widgets are added directly to Screens, and manipulated inside them (as in scr:set_value(...)), there's no conflict.

Clone this wiki locally