more changes to logview
- remove draw_text_elipsis - remove clip rect operations - fix text drawing when expanded - simplify code
This commit is contained in:
parent
2fec3052ce
commit
6ac1428b51
|
@ -122,29 +122,12 @@ end
|
||||||
|
|
||||||
local function draw_text_multiline(font, text, x, y, color)
|
local function draw_text_multiline(font, text, x, y, color)
|
||||||
local th = font:get_height()
|
local th = font:get_height()
|
||||||
local resx, resy = x, y
|
local resx = x
|
||||||
for line in text:gmatch("[^\n]+") do
|
for line in text:gmatch("[^\n]+") do
|
||||||
resy = y
|
|
||||||
resx = renderer.draw_text(style.font, line, x, y, color)
|
resx = renderer.draw_text(style.font, line, x, y, color)
|
||||||
y = y + th
|
y = y + th
|
||||||
end
|
end
|
||||||
return resx, resy
|
return resx, y
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function draw_text_elipsis(font, color, text, x, y, w, h, elipsis_style)
|
|
||||||
elipsis_style = elipsis_style or "end"
|
|
||||||
local c = font:get_width("_")
|
|
||||||
local approxc = math.floor(w / c)
|
|
||||||
if #text > approxc then
|
|
||||||
if elipsis_style == "end" then
|
|
||||||
text = string.sub(text, 1, approxc - 3) .. "..."
|
|
||||||
elseif elipsis_style == "middle" then
|
|
||||||
local mid = math.floor(#text / 2)
|
|
||||||
text = string.sub(text, 1, mid - 3) .. "..." .. string.sub(text, mid)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return common.draw_text(font, color, text, "left", x, y, w, h)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -154,7 +137,6 @@ function LogView:draw()
|
||||||
local th = style.font:get_height()
|
local th = style.font:get_height()
|
||||||
local lh = th + style.padding.y -- for one line
|
local lh = th + style.padding.y -- for one line
|
||||||
for _, item, x, y, w, h in self:each_item() do
|
for _, item, x, y, w, h in self:each_item() do
|
||||||
core.push_clip_rect(x, y, w, h)
|
|
||||||
x = x + style.padding.x
|
x = x + style.padding.x
|
||||||
|
|
||||||
local time = os.date(nil, item.time)
|
local time = os.date(nil, item.time)
|
||||||
|
@ -167,22 +149,21 @@ function LogView:draw()
|
||||||
|
|
||||||
if is_expanded(item) then
|
if is_expanded(item) then
|
||||||
y = y + common.round(style.padding.y / 2)
|
y = y + common.round(style.padding.y / 2)
|
||||||
draw_text_multiline(style.font, item.text, x, y, style.text)
|
_, y = draw_text_multiline(style.font, item.text, x, y, style.text)
|
||||||
y = y + th
|
|
||||||
|
|
||||||
local at = "at " .. common.home_encode(item.at)
|
local at = "at " .. common.home_encode(item.at)
|
||||||
draw_text_elipsis(style.font, style.dim, at, x, y, w, lh, "middle")
|
_, y = common.draw_text(style.font, style.dim, at, "left", x, y, w, lh)
|
||||||
y = y + th
|
|
||||||
|
|
||||||
if item.info then
|
if item.info then
|
||||||
draw_text_multiline(style.font, item.info, x, y, style.dim)
|
_, y = draw_text_multiline(style.font, item.info, x, y, style.dim)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
draw_text_elipsis(style.font, style.text, item.text, x, y, w, lh)
|
local line, has_newline = string.match(item.text, "([^\n]+)(\n?)")
|
||||||
y = y + th
|
if has_newline ~= "" then
|
||||||
|
line = line .. " ..."
|
||||||
|
end
|
||||||
|
_, y = common.draw_text(style.font, style.text, line, "left", x, y, w, lh)
|
||||||
end
|
end
|
||||||
|
|
||||||
core.pop_clip_rect()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue