summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-01-18 22:35:15 +0800
committerruki <[email protected]>2018-01-18 09:31:31 +0800
commitafdb22dcfeb898e051ed360fce04152b861aa3ad (patch)
tree5a8f56a1a527b86b282a1bb726fe1c497c6ef04e
parent921a48f8332381d30c814419bfa05230155d342c (diff)
improve bounds for view
-rw-r--r--xmake/core/ui/boxdialog.lua1
-rw-r--r--xmake/core/ui/dialog.lua1
-rw-r--r--xmake/core/ui/panel.lua12
-rw-r--r--xmake/core/ui/program.lua3
-rw-r--r--xmake/core/ui/rect.lua10
-rw-r--r--xmake/core/ui/textdialog.lua1
-rw-r--r--xmake/core/ui/view.lua37
-rw-r--r--xmake/core/ui/window.lua2
8 files changed, 46 insertions, 21 deletions
diff --git a/xmake/core/ui/boxdialog.lua b/xmake/core/ui/boxdialog.lua
index 7174da28a..be9282ca3 100644
--- a/xmake/core/ui/boxdialog.lua
+++ b/xmake/core/ui/boxdialog.lua
@@ -43,6 +43,7 @@ function boxdialog:init(name, bounds, title)
-- resize text
self:text():bounds().ey = 3
+ self:text():invalidate(true)
-- select buttons by default
self:panel():select(self:buttons())
diff --git a/xmake/core/ui/dialog.lua b/xmake/core/ui/dialog.lua
index 57d94b64b..b6a138e20 100644
--- a/xmake/core/ui/dialog.lua
+++ b/xmake/core/ui/dialog.lua
@@ -77,6 +77,7 @@ function dialog:button_add(name, text, command)
x = math.max(0, width - v:width())
end
v:bounds():move2(x, 0)
+ v:invalidate(true)
index = index + 1
end
diff --git a/xmake/core/ui/panel.lua b/xmake/core/ui/panel.lua
index 43c71315e..a43bf864b 100644
--- a/xmake/core/ui/panel.lua
+++ b/xmake/core/ui/panel.lua
@@ -107,15 +107,20 @@ function panel:insert(v, opt)
-- center this view if centerx or centery are set
local bounds = v:bounds()
+ local center = false
local org = point {bounds.sx, bounds.sy}
if opt and opt.centerx then
org.x = math.floor((self:width() - v:width()) / 2)
+ center = true
end
if opt and opt.centery then
org.y = math.floor((self:height() - v:height()) / 2)
+ center = true
+ end
+ if center then
+ bounds:move(org.x - bounds.sx, org.y - bounds.sy)
+ v:invalidate(true)
end
- bounds:move(org.x - bounds.sx, org.y - bounds.sy)
- v:bounds_set(bounds)
-- insert this view
self._VIEWS:push(v)
@@ -145,6 +150,9 @@ function panel:remove(v)
self._VIEWS:remove(v)
self._VIEWS_CACHE[v:name()] = nil
+ -- clear parent
+ v:parent_set(nil)
+
-- select next view
if self:current() == v then
self:select_next(nil, true)
diff --git a/xmake/core/ui/program.lua b/xmake/core/ui/program.lua
index 82ada0bcf..ff152584f 100644
--- a/xmake/core/ui/program.lua
+++ b/xmake/core/ui/program.lua
@@ -156,10 +156,11 @@ function program:event_on(e)
-- do event for focused views
while focused_view and focused_view ~= self do
+ local parent = focused_view:parent()
if focused_view:event_on(e) then
return true
end
- focused_view = focused_view:parent()
+ focused_view = parent
end
-- quit program?
diff --git a/xmake/core/ui/rect.lua b/xmake/core/ui/rect.lua
index 4e91ff702..005385922 100644
--- a/xmake/core/ui/rect.lua
+++ b/xmake/core/ui/rect.lua
@@ -45,6 +45,16 @@ function rect:size()
return point { self.ex - self.sx, self.ey - self.sy }
end
+-- get width
+function rect:width()
+ return self.ex - self.sx
+end
+
+-- get height
+function rect:height()
+ return self.ey - self.sy
+end
+
-- resize rect
function rect:resize(w, h)
self.ex = self.sx + w
diff --git a/xmake/core/ui/textdialog.lua b/xmake/core/ui/textdialog.lua
index 74fb7008b..42dc3f45b 100644
--- a/xmake/core/ui/textdialog.lua
+++ b/xmake/core/ui/textdialog.lua
@@ -25,6 +25,7 @@
-- load modules
local log = require("ui/log")
local rect = require("ui/rect")
+local event = require("ui/event")
local dialog = require("ui/dialog")
local curses = require("ui/curses")
local textarea = require("ui/textarea")
diff --git a/xmake/core/ui/view.lua b/xmake/core/ui/view.lua
index 00c27132a..2512c5f10 100644
--- a/xmake/core/ui/view.lua
+++ b/xmake/core/ui/view.lua
@@ -110,37 +110,25 @@ end
-- set window bounds
function view:bounds_set(bounds)
-
- -- close the previous windows first
- if self:window() then
- self:window():close()
+ if bounds and self:bounds() ~= bounds then
+ self._BOUNDS = bounds()
+ self:invalidate(true)
end
-
- -- init size and bounds
- self._SIZE = bounds:size()
- self._BOUNDS = bounds()
-
- -- create a new window
- self._WINDOW = curses.new_pad(self:height() > 0 and self:height() or 1, self:width() > 0 and self:width() or 1)
- assert(self._WINDOW, "cannot create window!")
-
- -- disable cursor
- self:window():leaveok(true)
end
-- get view width
function view:width()
- return self._SIZE.x
+ return self:bounds():width()
end
-- get view height
function view:height()
- return self._SIZE.y
+ return self:bounds():height()
end
-- get view size
function view:size()
- return self._SIZE
+ return self:bounds():size()
end
-- get the parent view
@@ -392,6 +380,19 @@ function view:_mark_resize()
-- need resize it
self:state_set("resize", true)
+
+ -- close the previous windows first
+ if self:window() then
+ self:window():close()
+ self._WINDOW = nil
+ end
+
+ -- create a new window
+ self._WINDOW = curses.new_pad(self:height() > 0 and self:height() or 1, self:width() > 0 and self:width() or 1)
+ assert(self._WINDOW, "cannot create window!")
+
+ -- disable cursor
+ self:window():leaveok(true)
end
-- need redraw view
diff --git a/xmake/core/ui/window.lua b/xmake/core/ui/window.lua
index 6ce486d3d..eb66eeeb3 100644
--- a/xmake/core/ui/window.lua
+++ b/xmake/core/ui/window.lua
@@ -46,6 +46,7 @@ function window:init(name, bounds, title, shadow)
if shadow then
self:insert(self:shadow())
self:frame():bounds():movee(-2, -1)
+ self:frame():invalidate(true)
end
-- insert border
@@ -78,6 +79,7 @@ function window:panel()
if not self._PANEL then
self._PANEL = panel:new("window.panel", self:frame():bounds())
self._PANEL:bounds():grow(-1, -1)
+ self._PANEL:invalidate(true)
end
return self._PANEL
end