From 8550049db81453ab2437a562b3d793a8a00f8275 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Tue, 28 Dec 2021 16:39:40 +0100 Subject: [PATCH] Draw NagView in overlay mode The NagView takes some actual space in the Y and when it appears it cause the documents' content to be displaced. The movement of the documents' content is annoying and should be avoided so we draw the NagView entirely in overlay mode using defer draw and we always keep its y size to zero to don't affect the other application contents. --- data/core/nagview.lua | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/data/core/nagview.lua b/data/core/nagview.lua index 3d448cd4..35ae9b43 100644 --- a/data/core/nagview.lua +++ b/data/core/nagview.lua @@ -16,6 +16,7 @@ local NagView = View:extend() function NagView:new() NagView.super.new(self) self.size.y = 0 + self.show_height = 0 self.force_focus = false self.queue = {} end @@ -50,16 +51,16 @@ function NagView:update() NagView.super.update(self) if core.active_view == self and self.title then - self:move_towards(self.size, "y", self:get_target_height()) + self:move_towards(self, "show_height", self:get_target_height()) self:move_towards(self, "underline_progress", 1) else - self:move_towards(self.size, "y", 0) + self:move_towards(self, "show_height", 0) end end -function NagView:draw_overlay() +function NagView:dim_window_content() local ox, oy = self:get_content_offset() - oy = oy + self.size.y + oy = oy + self.show_height local w, h = core.root_view.size.x, core.root_view.size.y - oy core.root_view:defer_draw(function() renderer.draw_rect(ox, oy, w, h, style.nagbar_dim) @@ -81,7 +82,7 @@ function NagView:each_option() bh = self:get_buttons_height() ox,oy = self:get_content_offset() ox = ox + self.size.x - oy = oy + self.size.y - bh - style.padding.y + oy = oy + self.show_height - bh - style.padding.y for i = #self.options, 1, -1 do opt = self.options[i] @@ -123,19 +124,21 @@ function NagView:on_text_input(text) end -function NagView:draw() - if self.size.y <= 0 or not self.title then return end +local function draw_nagview_message(self) + if self.show_height <= 0 or not self.title then return end - self:draw_overlay() - self:draw_background(style.nagbar) + self:dim_window_content() + -- draw message's background local ox, oy = self:get_content_offset() + renderer.draw_rect(ox, oy, self.size.x, self.show_height, style.nagbar) + ox = ox + style.padding.x -- if there are other items, show it if #self.queue > 0 then local str = string.format("[%d]", #self.queue) - ox = common.draw_text(style.font, style.nagbar_text, str, "left", ox, oy, self.size.x, self.size.y) + ox = common.draw_text(style.font, style.nagbar_text, str, "left", ox, oy, self.size.x, self.show_height) ox = ox + style.padding.x end @@ -170,6 +173,10 @@ function NagView:draw() end end +function NagView:draw() + core.root_view:defer_draw(draw_nagview_message, self) +end + function NagView:get_message_height() local h = 0 for str in string.gmatch(self.message, "(.-)\n") do