[tekui-devel] tekui: Improved examples; Object: setValue() to nil is no prohib...
Timm S. Mueller
tmueller at neoscientists.org
Tue Apr 1 15:36:30 CEST 2008
details: http://hg.teklib.org/tekui/rev/f78f2dd12cdd
changeset: 399:f78f2dd12cdd
user: Timm S. Mueller <tmueller at neoscientists.org>
date: Mon Mar 31 21:33:06 2008 +0200
description:
Improved examples; Object: setValue() to nil is no prohibited; Window,
TextInput, PopItem: input handlers are now stacked and initialized
dynamically; TextInput: reactivated; Window: messages are no longer passed to
the FocusElement implicitly, added addInputHandler/remInputHandler()
diffs (truncated from 492 to 100 lines):
diff -r ea3dbf7e3044 -r f78f2dd12cdd tek/app/ui/sudoku.lua
--- a/tek/app/ui/sudoku.lua Mon Mar 31 19:24:22 2008 +0200
+++ b/tek/app/ui/sudoku.lua Mon Mar 31 21:33:06 2008 +0200
@@ -7,8 +7,10 @@
--
require "tek.lib.sudoku"
-require "tek.lib.debug".level = 4
+local db = require "tek.lib.debug"
+db.level = 4
local ui = require "tek.lib.ui"
+local max = math.max
-- ui.DEBUG = true
math.randomseed(os.time())
@@ -94,22 +96,17 @@ end
-- sudokubutton class:
-------------------------------------------------------------------------------
-local NOTIFY_LABEL = { ui.NOTIFY_SELF, "setLabel", ui.NOTIFY_VALUE }
-
sudokubutton = ui.text:newClass()
-function sudokubutton.new(class, self)
- self = self or { }
+function sudokubutton.init(self)
+ self.changeable = true
self.Mode = self.Mode or "button"
self.FontSpec = self.FontSpec or "__main:24"
- self = ui.text:new(self)
- self:addNotify("Label", ui.NOTIFY_ALWAYS, NOTIFY_LABEL)
- return self
-end
-
-function sudokubutton:setLabel(label)
- self.Label = label
- self.Redraw = true
+ return ui.text.init(self)
+end
+
+function sudokubutton.new(class, self)
+ return ui.Text.new(class, self, sudokubutton.init(self or { }))
end
function sudokubutton:onRelease()
@@ -126,7 +123,7 @@ end
end
function sudokubutton:checkFocus()
- return self.changeable and ui.button.checkFocus(self)
+ return self.changeable and ui.text.checkFocus(self)
end
function sudokubutton:setState()
@@ -140,6 +137,25 @@ function sudokubutton:setState()
end
self.Background = b
self.Redraw = true
+end
+
+function sudokubutton:askMinMax()
+ local priv = self:getPrivate()
+
+ local m1, m2 = ui.Display:textSize(priv.Font, "W")
+ m1 = m1 + 1 -- +1 for disabled state
+ m2 = m2 + 1 -- +1 for disabled state
+
+ local m = self.TextMargin
+ local p = self.PaddingAndBorder
+ m1 = m1 + m[1] + m[3] + p[1] + p[3]
+ m2 = m2 + m[2] + m[4] + p[2] + p[4]
+
+ local m3 = self.MaxWidth and max(self.MaxWidth, m1) or nil
+ local m4 = self.MaxHeight and max(self.MaxHeight, m2) or nil
+
+ return m1, m2, m3, m4
+
end
-------------------------------------------------------------------------------
@@ -206,7 +222,7 @@ function sudoku.new(class, self)
set = function(self, s, c)
foreachfield(self, function(element, idx)
local v = s[idx]
- element:setValue("Label", (v ~= 0) and tostring(v) or nil)
+ element:setValue("Label", (v ~= 0) and tostring(v) or "")
if c then
element.changeable = c[idx]
else
diff -r ea3dbf7e3044 -r f78f2dd12cdd tek/class/ui/object.lua
--- a/tek/class/ui/object.lua Mon Mar 31 19:24:22 2008 +0200
+++ b/tek/class/ui/object.lua Mon Mar 31 21:33:06 2008 +0200
@@ -20,6 +20,7 @@
local Class = require "tek.class"
local ui = require "tek.lib.ui"
+local assert = assert
local error = error
local insert = table.insert
local ipairs = ipairs
More information about the tekui-devel
mailing list