From caf106be1d49479cee1acead906d2088ef93f40c Mon Sep 17 00:00:00 2001 From: Guldoman Date: Fri, 1 Jul 2022 05:26:07 +0200 Subject: [PATCH 1/3] `LogView`: Don't draw invisible items --- data/core/logview.lua | 62 ++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/data/core/logview.lua b/data/core/logview.lua index d079a5de..5a7224ac 100644 --- a/data/core/logview.lua +++ b/data/core/logview.lua @@ -154,44 +154,46 @@ function LogView:draw() local tw = style.font:get_width(datestr) for _, item, x, y, w, h in self:each_item() do - core.push_clip_rect(x, y, w, h) - x = x + style.padding.x + if y + h >= self.position.y and y <= self.position.y + self.size.y then + core.push_clip_rect(x, y, w, h) + x = x + style.padding.x - x = common.draw_text( - style.icon_font, - style.log[item.level].color, - style.log[item.level].icon, - "center", - x, y, iw, lh - ) - x = x + style.padding.x + x = common.draw_text( + style.icon_font, + style.log[item.level].color, + style.log[item.level].icon, + "center", + x, y, iw, lh + ) + x = x + style.padding.x - -- timestamps are always 15% of the width - local time = os.date(nil, item.time) - common.draw_text(style.font, style.dim, time, "left", x, y, tw, lh) - x = x + tw + style.padding.x + -- timestamps are always 15% of the width + local time = os.date(nil, item.time) + common.draw_text(style.font, style.dim, time, "left", x, y, tw, lh) + x = x + tw + style.padding.x - w = w - (x - self:get_content_offset()) + w = w - (x - self:get_content_offset()) - if is_expanded(item) then - y = y + common.round(style.padding.y / 2) - _, y = draw_text_multiline(style.font, item.text, x, y, style.text) + if is_expanded(item) then + y = y + common.round(style.padding.y / 2) + _, y = draw_text_multiline(style.font, item.text, x, y, style.text) - local at = "at " .. common.home_encode(item.at) - _, y = common.draw_text(style.font, style.dim, at, "left", x, y, w, lh) + local at = "at " .. common.home_encode(item.at) + _, y = common.draw_text(style.font, style.dim, at, "left", x, y, w, lh) - if item.info then - _, y = draw_text_multiline(style.font, item.info, x, y, style.dim) + if item.info then + _, y = draw_text_multiline(style.font, item.info, x, y, style.dim) + end + else + local line, has_newline = string.match(item.text, "([^\n]+)(\n?)") + if has_newline ~= "" then + line = line .. " ..." + end + _, y = common.draw_text(style.font, style.text, line, "left", x, y, w, lh) end - else - local line, has_newline = string.match(item.text, "([^\n]+)(\n?)") - if has_newline ~= "" then - line = line .. " ..." - end - _, y = common.draw_text(style.font, style.text, line, "left", x, y, w, lh) + + core.pop_clip_rect() end - - core.pop_clip_rect() end end From b84a510d427909e01ba8b6374df3f493d93c2e68 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Fri, 1 Jul 2022 05:27:18 +0200 Subject: [PATCH 2/3] Increase default maximum number of log items The low number in some cases resulted in hidden errors. --- data/core/config.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/core/config.lua b/data/core/config.lua index 1ae50a1e..efbe1f1b 100644 --- a/data/core/config.lua +++ b/data/core/config.lua @@ -1,7 +1,7 @@ local config = {} config.fps = 60 -config.max_log_items = 80 +config.max_log_items = 800 config.message_timeout = 5 config.mouse_wheel_scroll = 50 * SCALE config.animate_drag_scroll = false From 7888bf08e916b49689f7dfb1660701fcbe8df2db Mon Sep 17 00:00:00 2001 From: Guldoman Date: Fri, 1 Jul 2022 05:28:56 +0200 Subject: [PATCH 3/3] `LogView`: Show scrollbar --- data/core/logview.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/data/core/logview.lua b/data/core/logview.lua index 5a7224ac..15aec22e 100644 --- a/data/core/logview.lua +++ b/data/core/logview.lua @@ -1,5 +1,6 @@ local core = require "core" local common = require "core.common" +local config = require "core.config" local keymap = require "core.keymap" local style = require "core.style" local View = require "core.view" @@ -81,6 +82,19 @@ function LogView:each_item() end +function LogView:get_scrollable_size() + local _, y_off = self:get_content_offset() + local last_y, last_h = 0, 0 + for i, item, x, y, w, h in self:each_item() do + last_y, last_h = y, h + end + if not config.scroll_past_end then + return last_y + last_h - y_off + style.padding.y + end + return last_y + self.size.y - y_off +end + + function LogView:on_mouse_pressed(button, px, py, clicks) if LogView.super.on_mouse_pressed(self, button, px, py, clicks) then return true @@ -195,6 +209,7 @@ function LogView:draw() core.pop_clip_rect() end end + LogView.super.draw_scrollbar(self) end