[tekui-devel] tekui: List:addLine() function added; Object: improved cyclic no...

Timm S. Mueller tmueller at neoscientists.org
Fri Apr 25 00:10:43 CEST 2008


details:   http://hg.teklib.org/tekui/rev/75399584084f
changeset: 443:75399584084f
user:      Timm S. Mueller <tmueller at neoscientists.org>
date:      Wed Apr 23 15:20:43 2008 +0200
description:
List:addLine() function added; Object: improved cyclic notification warning
message; TextInput: Focus change is now properly submitted to Window

diffs (truncated from 170 to 100 lines):

diff -r 8d23a4c37592 -r 75399584084f tek/app/ui/list.lua
--- a/tek/app/ui/list.lua	Tue Apr 22 23:13:35 2008 +0200
+++ b/tek/app/ui/list.lua	Wed Apr 23 15:20:43 2008 +0200
@@ -4,9 +4,9 @@ local ui = require "tek.lib.ui"
 local ui = require "tek.lib.ui"
 
 local list = { }
--- for i = 1, 111 do
--- 	list[i] = { "Line " .. i .. ": The quick brown fox jumps over the lazy dog" }
--- end
+for i = 1, 12 do
+	list[i] = { "Line " .. i .. ": The quick brown fox jumps over the lazy dog" }
+end
 
 ui.Application:new
 {
@@ -17,7 +17,7 @@ ui.Application:new
 			Direction = "vertical",
 			Children =
 			{
-				ui.List:new { List = list },
+				ui.List:new { Id = "the-list", List = list },
 				ui.TextInput:new
 				{
 					Notifications =
@@ -28,7 +28,9 @@ ui.Application:new
 							{
 								{
 									ui.NOTIFY_SELF, function(self, val)
+										self.Application:getElementById("the-list"):addEntry { self.Label }
 										self:setValue("Label", "")
+										self:setValue("Focus", true)
 									end, ui.NOTIFY_VALUE
 								}
 							}
diff -r 8d23a4c37592 -r 75399584084f tek/class/ui/list.lua
--- a/tek/class/ui/list.lua	Tue Apr 22 23:13:35 2008 +0200
+++ b/tek/class/ui/list.lua	Wed Apr 23 15:20:43 2008 +0200
@@ -19,7 +19,7 @@ local remove = table.remove
 local remove = table.remove
 
 module("tek.class.ui.list", tek.class.ui.scrollgroup)
-_VERSION = "List 0.17"
+_VERSION = "List 0.18"
 local List = _M
 
 -------------------------------------------------------------------------------
@@ -94,8 +94,8 @@ function ListGadget:prepare()
 	local w, h
 	local p = self.PaddingAndBorder
 	local y = p[2]
+	local maxw = 0
 	local l = { }
-	local maxw = 0
 	self.Lines = l
 	if self.List then
 		for i, line in ipairs(self.List) do
@@ -108,6 +108,30 @@ function ListGadget:prepare()
 	self.MinWidth = maxw
 	self.Parent:setWidth(maxw)
 	self.Height = y
+end
+
+function ListGadget:getLineOnScreen(lnr)
+	local l = self.Lines[lnr]
+	if l then
+		local c = self.Parent.Canvas
+		local r = c.Rect
+		local v1 = c.Left
+		local v2 = c.Top
+		local v3 = v1 + r[3] - r[1]
+		local v4 = v2 + r[4] - r[2]
+		return overlap(v1, v2, v3, v4, l[1], l[2], c.Width - 1, l[4])
+	end
+end
+
+function ListGadget:addLine(entry)
+	insert(self.List, entry)
+	self:prepare()
+	local c = self.Parent.Canvas
+	self:layout(0, 0, c.Width - 1, c.Height - 1)
+	local r1, r2, r3, r4 = self:getLineOnScreen(#self.List)
+	if r1 then
+		self:markDamage(r1, r2, r3, r4)
+	end
 end
 
 function ListGadget:draw()
@@ -167,6 +191,7 @@ end
 end
 
 function ListGadget:layout(r1, r2, r3, r4, markdamage)
+
 	local width = r3 - r1 + 1
 	local r = self.Rect
 	if self:simpleLayout(r1, r2, r3, r2 + self.Height - 1) then
@@ -303,3 +328,8 @@ function List.new(class, self)
 
 	return ScrollGroup.new(class, self)
 end


More information about the tekui-devel mailing list