Ensure tab's text and close button don't overlaps
This commit is contained in:
parent
4cda8fc122
commit
e861ea1d66
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue