From 7d62f639ccee72697214dc8536974f4b48f7b345 Mon Sep 17 00:00:00 2001 From: poire-z Date: Thu, 23 Mar 2023 18:37:36 +0100 Subject: [PATCH] ButtonTable: allow buttons to request a fixed width It is expected some button(s) in a row do not specify such a width, so they get distributed the remaining space from the ButtonTable specified width. --- frontend/ui/widget/buttontable.lua | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/frontend/ui/widget/buttontable.lua b/frontend/ui/widget/buttontable.lua index a3dc803af..8cc21089d 100644 --- a/frontend/ui/widget/buttontable.lua +++ b/frontend/ui/widget/buttontable.lua @@ -42,7 +42,17 @@ function ButtonTable:init() local horizontal_group = HorizontalGroup:new{} local row = self.buttons[i] local column_cnt = #row - local sizer_space = self.sep_width * (column_cnt - 1) + 2 + local available_width = self.width - self.sep_width * (column_cnt - 1) + local unspecified_width_buttons = 0 + for j = 1, column_cnt do + local btn_entry = row[j] + if btn_entry.width then + available_width = available_width - btn_entry.width + else + unspecified_width_buttons = unspecified_width_buttons + 1 + end + end + local default_button_width = math.floor(available_width / unspecified_width_buttons) for j = 1, column_cnt do local btn_entry = row[j] local button = Button:new{ @@ -63,7 +73,7 @@ function ButtonTable:init() hold_callback = btn_entry.hold_callback, allow_hold_when_disabled = btn_entry.allow_hold_when_disabled, vsync = btn_entry.vsync, - width = math.ceil((self.width - sizer_space)/column_cnt), + width = btn_entry.width or default_button_width, bordersize = 0, margin = 0, padding = Size.padding.buttontable, -- a bit taller than standalone buttons, for easier tap