Move single tab drawing to its own function
This commit is contained in:
parent
2ac7c7f09b
commit
86632b68de
|
@ -513,47 +513,28 @@ function Node:update()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Node:draw_tab(text, is_active, is_hovered, is_close_hovered, x, y, w, h, standalone)
|
||||||
function Node:draw_tabs()
|
|
||||||
local x, y, w, h, scroll_padding = self:get_scroll_button_rect(1)
|
|
||||||
local ds = style.divider_size
|
local ds = style.divider_size
|
||||||
local dots_width = style.font:get_width("…")
|
local dots_width = style.font:get_width("…")
|
||||||
core.push_clip_rect(x, y, self.size.x, h)
|
|
||||||
renderer.draw_rect(x, y, self.size.x, h, style.background2)
|
|
||||||
renderer.draw_rect(x, y + h - ds, self.size.x, ds, style.divider)
|
|
||||||
|
|
||||||
if self.tab_offset > 1 then
|
|
||||||
local button_style = self.hovered_scroll_button == 1 and style.text or style.dim
|
|
||||||
common.draw_text(style.icon_font, button_style, "<", nil, x + scroll_padding, y, 0, h)
|
|
||||||
end
|
|
||||||
|
|
||||||
local tabs_number = self:get_visible_tabs_number()
|
|
||||||
if #self.views > self.tab_offset + tabs_number - 1 then
|
|
||||||
local xrb, yrb, wrb = self:get_scroll_button_rect(2)
|
|
||||||
local button_style = self.hovered_scroll_button == 2 and style.text or style.dim
|
|
||||||
common.draw_text(style.icon_font, button_style, ">", nil, xrb + scroll_padding, yrb, 0, h)
|
|
||||||
end
|
|
||||||
|
|
||||||
for i = self.tab_offset, self.tab_offset + tabs_number - 1 do
|
|
||||||
local view = self.views[i]
|
|
||||||
local x, y, w, h = self:get_tab_rect(i)
|
|
||||||
local text = view:get_name()
|
|
||||||
local color = style.dim
|
local color = style.dim
|
||||||
local padding_y = style.padding.y
|
local padding_y = style.padding.y
|
||||||
renderer.draw_rect(x + w, y + padding_y, ds, h - padding_y * 2, style.dim)
|
renderer.draw_rect(x + w, y + padding_y, ds, h - padding_y * 2, style.dim)
|
||||||
if view == self.active_view then
|
if standalone then
|
||||||
|
renderer.draw_rect(x-1, y-1, w+2, h+2, style.background2)
|
||||||
|
end
|
||||||
|
if is_active then
|
||||||
color = style.text
|
color = style.text
|
||||||
renderer.draw_rect(x, y, w, h, style.background)
|
renderer.draw_rect(x, y, w, h, style.background)
|
||||||
renderer.draw_rect(x + w, y, ds, h, style.divider)
|
renderer.draw_rect(x + w, y, ds, h, style.divider)
|
||||||
renderer.draw_rect(x - ds, y, ds, h, style.divider)
|
renderer.draw_rect(x - ds, y, ds, h, style.divider)
|
||||||
end
|
end
|
||||||
local cx, cw, cspace = close_button_location(x, w)
|
local cx, cw, cspace = close_button_location(x, w)
|
||||||
local show_close_button = ((view == self.active_view or i == self.hovered_tab) and config.tab_close_button)
|
local show_close_button = ((is_active or is_hovered) and not standalone and config.tab_close_button)
|
||||||
if show_close_button then
|
if show_close_button then
|
||||||
local close_style = self.hovered_close == i and style.text or style.dim
|
local close_style = is_close_hovered and style.text or style.dim
|
||||||
common.draw_text(style.icon_font, close_style, "C", nil, cx, y, 0, h)
|
common.draw_text(style.icon_font, close_style, "C", nil, cx, y, 0, h)
|
||||||
end
|
end
|
||||||
if i == self.hovered_tab then
|
if is_hovered then
|
||||||
color = style.text
|
color = style.text
|
||||||
end
|
end
|
||||||
local padx = style.padding.x
|
local padx = style.padding.x
|
||||||
|
@ -578,6 +559,34 @@ function Node:draw_tabs()
|
||||||
end
|
end
|
||||||
common.draw_text(style.font, color, text, align, x, y, w, h)
|
common.draw_text(style.font, color, text, align, x, y, w, h)
|
||||||
core.pop_clip_rect()
|
core.pop_clip_rect()
|
||||||
|
end
|
||||||
|
|
||||||
|
function Node:draw_tabs()
|
||||||
|
local x, y, w, h, scroll_padding = self:get_scroll_button_rect(1)
|
||||||
|
local ds = style.divider_size
|
||||||
|
local dots_width = style.font:get_width("…")
|
||||||
|
core.push_clip_rect(x, y, self.size.x, h)
|
||||||
|
renderer.draw_rect(x, y, self.size.x, h, style.background2)
|
||||||
|
renderer.draw_rect(x, y + h - ds, self.size.x, ds, style.divider)
|
||||||
|
|
||||||
|
if self.tab_offset > 1 then
|
||||||
|
local button_style = self.hovered_scroll_button == 1 and style.text or style.dim
|
||||||
|
common.draw_text(style.icon_font, button_style, "<", nil, x + scroll_padding, y, 0, h)
|
||||||
|
end
|
||||||
|
|
||||||
|
local tabs_number = self:get_visible_tabs_number()
|
||||||
|
if #self.views > self.tab_offset + tabs_number - 1 then
|
||||||
|
local xrb, yrb, wrb = self:get_scroll_button_rect(2)
|
||||||
|
local button_style = self.hovered_scroll_button == 2 and style.text or style.dim
|
||||||
|
common.draw_text(style.icon_font, button_style, ">", nil, xrb + scroll_padding, yrb, 0, h)
|
||||||
|
end
|
||||||
|
|
||||||
|
for i = self.tab_offset, self.tab_offset + tabs_number - 1 do
|
||||||
|
local view = self.views[i]
|
||||||
|
local x, y, w, h = self:get_tab_rect(i)
|
||||||
|
self:draw_tab(view:get_name(), view == self.active_view,
|
||||||
|
i == self.hovered_tab, i == self.hovered_close,
|
||||||
|
x, y, w, h)
|
||||||
end
|
end
|
||||||
|
|
||||||
core.pop_clip_rect()
|
core.pop_clip_rect()
|
||||||
|
|
Loading…
Reference in New Issue