diff options
| author | ruki <[email protected]> | 2018-01-13 00:58:21 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-01-12 23:50:10 +0800 |
| commit | bb8a982842b1a447b3da54538a8b245888ccbd86 (patch) | |
| tree | b9e7f11b99a769436663dae9da2d83cc2ad8aeb4 | |
| parent | 788f52e46e4333be8522f80cd033eba206fda3ff (diff) | |
improve canvas puts
| -rw-r--r-- | xmake/core/ui/canvas.lua | 14 | ||||
| -rw-r--r-- | 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) |
