From e861ea1d6697403d847e835d32c5b8b1738661be Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sat, 27 Feb 2021 17:19:47 +0100 Subject: [PATCH] Ensure tab's text and close button don't overlaps --- data/core/rootview.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 7ff0f2f4..2bb58281 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -234,10 +234,10 @@ function Node:get_tab_overlapping_point(px, py) end -local function close_button_location(x, y, w, h) +local function close_button_location(x, w) local cw = style.icon_font:get_width("C") local pad = style.padding.y - return x + w - pad - cw, y, cw, h + return x + w - pad - cw, cw, pad end @@ -245,8 +245,8 @@ function Node:tab_mouse_moved(px, py) local tab_index = self:get_tab_overlapping_point(px, py) if tab_index then local x, y, w, h = self:get_tab_rect(tab_index) - local cx, cy, cw, ch = close_button_location(x, y, w, h) - if px >= cx and px < cx + cw and py >= cy and py < cy + ch then + local cx, cw = close_button_location(x, w) + if px >= cx and px < cx + cw and py >= y and py < y + h then self.hovered_close = tab_index return end @@ -401,15 +401,15 @@ function Node:draw_tabs() renderer.draw_rect(x + w, y, ds, h, style.divider) renderer.draw_rect(x - ds, y, ds, h, style.divider) end + local cx, cw, cspace = close_button_location(x, w) if view == self.active_view or i == self.hovered_tab then - local cx, cy, cw, ch = close_button_location(x, y, w, h) local close_style = self.hovered_close == i and style.text or style.dim - common.draw_text(style.icon_font, close_style, "C", nil, cx, cy, 0, ch) + common.draw_text(style.icon_font, close_style, "C", nil, cx, y, 0, h) end if i == self.hovered_tab then color = style.text end - core.push_clip_rect(x, y, w, h) + core.push_clip_rect(x, y, cx - x - cspace, h) x, w = x + style.padding.x, w - style.padding.x * 2 local align = style.font:get_width(text) > w and "left" or "center" common.draw_text(style.font, color, text, align, x, y, w, h)