From dd479f8cd1d370733e217e037ee2a3a0877ed4ad Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 9 Jun 2023 15:44:20 +0200 Subject: [PATCH] Add top tab margins (#1479) adapted from #810 to allow styles to decide upon the top margin of the tab list --- data/core/node.lua | 21 +++++++++++++++------ data/core/style.lua | 12 +++++++++++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/data/core/node.lua b/data/core/node.lua index 0ea2c07e..3ae9b256 100644 --- a/data/core/node.lua +++ b/data/core/node.lua @@ -334,10 +334,17 @@ function Node:get_child_overlapping_point(x, y) return child:get_child_overlapping_point(x, y) end +-- returns: total height, text padding, top margin +local function get_tab_y_sizes() + local height = style.font:get_height() + local padding = style.padding.y + local margin = style.margin.tab.top + return height + (padding * 2) + margin, padding, margin +end function Node:get_scroll_button_rect(index) local w, pad = get_scroll_button_width() - local h = style.font:get_height() + style.padding.y * 2 + local h = get_tab_y_sizes() local x = self.position.x + (index == 1 and self.size.x - w * 2 or self.size.x - w) return x, self.position.y, w, h, pad end @@ -348,8 +355,8 @@ function Node:get_tab_rect(idx) local x0 = self.position.x local x1 = x0 + common.clamp(self.tab_width * (idx - 1) - self.tab_shift, 0, maxw) local x2 = x0 + common.clamp(self.tab_width * idx - self.tab_shift, 0, maxw) - local h = style.font:get_height() + style.padding.y * 2 - return x1, self.position.y, x2 - x1, h + local h, pad_y, margin_y = get_tab_y_sizes() + return x1, self.position.y, x2 - x1, h, margin_y end @@ -540,6 +547,7 @@ function Node:draw_tab_borders(view, is_active, is_hovered, x, y, w, h, standalo if is_active then color = style.text renderer.draw_rect(x, y, w, h, style.background) + renderer.draw_rect(x, y, w, ds, style.divider) renderer.draw_rect(x + w, y, ds, h, style.divider) renderer.draw_rect(x - ds, y, ds, h, style.divider) end @@ -547,7 +555,8 @@ function Node:draw_tab_borders(view, is_active, is_hovered, x, y, w, h, standalo end function Node:draw_tab(view, is_active, is_hovered, is_close_hovered, x, y, w, h, standalone) - x, y, w, h = self:draw_tab_borders(view, is_active, is_hovered, x, y, w, h, standalone) + local _, padding_y, margin_y = get_tab_y_sizes() + x, y, w, h = self:draw_tab_borders(view, is_active, is_hovered, x, y + margin_y, w, h - margin_y, standalone) -- Close button local cx, cw, cpad = close_button_location(x, w) local show_close_button = ((is_active or is_hovered) and not standalone and config.tab_close_button) @@ -768,7 +777,7 @@ function Node:get_drag_overlay_tab_position(x, y, dragged_node, dragged_index) tab_index = self:get_visible_tabs_number() + (self.tab_offset - 1 or 0) end end - local tab_x, tab_y, tab_w, tab_h = self:get_tab_rect(tab_index) + local tab_x, tab_y, tab_w, tab_h, margin_y = self:get_tab_rect(tab_index) if x > tab_x + tab_w / 2 and tab_index <= #self.views then -- use next tab tab_x = tab_x + tab_w @@ -779,7 +788,7 @@ function Node:get_drag_overlay_tab_position(x, y, dragged_node, dragged_index) tab_index = tab_index - 1 tab_x = tab_x - tab_w end - return tab_index, tab_x, tab_y, tab_w, tab_h + return tab_index, tab_x, tab_y + margin_y, tab_w, tab_h - margin_y end return Node diff --git a/data/core/style.lua b/data/core/style.lua index dbe92994..9857ed07 100644 --- a/data/core/style.lua +++ b/data/core/style.lua @@ -1,13 +1,23 @@ local common = require "core.common" local style = {} -style.padding = { x = common.round(14 * SCALE), y = common.round(7 * SCALE) } style.divider_size = common.round(1 * SCALE) style.scrollbar_size = common.round(4 * SCALE) style.expanded_scrollbar_size = common.round(12 * SCALE) style.caret_width = common.round(2 * SCALE) style.tab_width = common.round(170 * SCALE) +style.padding = { + x = common.round(14 * SCALE), + y = common.round(7 * SCALE), +} + +style.margin = { + tab = { + top = common.round(-style.divider_size * SCALE) + } +} + -- The function renderer.font.load can accept an option table as a second optional argument. -- It shoud be like the following: --