From bb8a982842b1a447b3da54538a8b245888ccbd86 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 13 Jan 2018 00:58:21 +0800 Subject: improve canvas puts --- xmake/core/ui/canvas.lua | 14 ++++++++++++-- xmake/core/ui/label.lua | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/xmake/core/ui/canvas.lua b/xmake/core/ui/canvas.lua index 33e33b267..bf70216d4 100644 --- a/xmake/core/ui/canvas.lua +++ b/xmake/core/ui/canvas.lua @@ -95,8 +95,18 @@ function canvas:putchar(ch, n, vertical) end -- put a string to canvas -function canvas:puts(str, len) - self._window:addstr(str, len) +function canvas:puts(str) + local sy, sx = self._window:getyx() + local ey, _ = self._window:getmaxyx() + for _, line in ipairs(str:split('\n')) do + self._window:addstr(line) + local _, y = self:pos() + if y + 1 < ey then + self:move(sx, y + 1) + else + break + end + end return self end diff --git a/xmake/core/ui/label.lua b/xmake/core/ui/label.lua index 23395c8c3..524326540 100644 --- a/xmake/core/ui/label.lua +++ b/xmake/core/ui/label.lua @@ -52,7 +52,7 @@ function label:draw() -- get the text attribute value local textattr = self:textattr_val() - -- strip text string + -- draw text string local str = self:text() if str and #str > 0 and textattr then self:canvas():attr(textattr):move(0, 0):puts(str) -- cgit v1.3.1