@ -145,18 +145,21 @@ function KeyValueItem:init()
local frame_padding = Size.padding . default
local frame_padding = Size.padding . default
local frame_internal_width = self.width - frame_padding * 2
local frame_internal_width = self.width - frame_padding * 2
local middle_padding = Size.padding . default -- min enforced padding between key and value
local available_width = frame_internal_width - middle_padding
-- Default widths (and position of value widget) if each text fits in 1/2 screen width
-- Default widths (and position of value widget) if each text fits in 1/2 screen width
local key_w = frame_internal_width / 2
local key_w = frame_internal_width / 2 - middle_padding
local value_w = frame_internal_width / 2
local value_w = frame_internal_width / 2
local key_widget = TextWidget : new {
local key_widget = TextWidget : new {
text = self.key ,
text = self.key ,
max_width = frame_internal _width,
max_width = available _width,
face = self.tface ,
face = self.tface ,
}
}
local value_widget = TextWidget : new {
local value_widget = TextWidget : new {
text = tvalue ,
text = tvalue ,
max_width = frame_internal _width,
max_width = available _width,
face = self.cface ,
face = self.cface ,
}
}
local key_w_rendered = key_widget : getWidth ( )
local key_w_rendered = key_widget : getWidth ( )
@ -165,26 +168,23 @@ function KeyValueItem:init()
-- As both key_widget and value_width will be in a HorizontalGroup,
-- As both key_widget and value_width will be in a HorizontalGroup,
-- and key is always left aligned, we can just tweak the key width
-- and key is always left aligned, we can just tweak the key width
-- to position the value_widget
-- to position the value_widget
local value_prepend_space = false
local value_align_right = false
local value_align_right = false
local fit_right_align = true -- by default, really right align
local fit_right_align = true -- by default, really right align
if key_w_rendered > key_w or value_w_rendered > value_w then
if key_w_rendered > key_w or value_w_rendered > value_w then
-- One (or both) does not fit in 1/2 width
-- One (or both) does not fit in 1/2 width
if key_w_rendered + value_w_rendered > frame_internal _width then
if key_w_rendered + value_w_rendered > available _width then
-- Both do not fit: one has to be truncated so they fit
-- Both do not fit: one has to be truncated so they fit
if key_w_rendered >= value_w_rendered then
if key_w_rendered >= value_w_rendered then
-- Rare case: key larger than value.
-- Rare case: key larger than value.
-- We should have kept our keys small, smaller than 1/2 width.
-- We should have kept our keys small, smaller than 1/2 width.
-- If it is larger than value, it's that value is kinda small,
-- If it is larger than value, it's that value is kinda small,
-- so keep the whole value, and truncate the key
-- so keep the whole value, and truncate the key
key_w = frame_internal _width - value_w_rendered
key_w = available _width - value_w_rendered
else
else
-- Usual case: value larger than key.
-- Usual case: value larger than key.
-- Keep our small key, fit the value in the remaining width,
-- Keep our small key, fit the value in the remaining width.
-- prepend some space to separate them
key_w = key_w_rendered
key_w = key_w_rendered
value_prepend_space = true
end
end
value_align_right = true -- so the ellipsis touches the screen right border
value_align_right = true -- so the ellipsis touches the screen right border
if self.value_overflow_align ~= " right " and self.value_align ~= " right " then
if self.value_overflow_align ~= " right " and self.value_align ~= " right " then
@ -204,28 +204,24 @@ function KeyValueItem:init()
else
else
-- Both can fit: break the 1/2 widths
-- Both can fit: break the 1/2 widths
if self.value_overflow_align == " right " or self.value_align == " right " then
if self.value_overflow_align == " right " or self.value_align == " right " then
key_w = frame_internal _width - value_w_rendered
key_w = available _width - value_w_rendered
value_align_right = true
value_align_right = true
else
else
key_w = key_w_rendered
key_w = key_w_rendered
value_prepend_space = true
end
end
end
end
-- In all the above case, we set the right key_w to include any
-- In all the above case, we set the right key_w to include any
-- needed in-between padding: value_w is what's left.
-- needed additional in-between padding: value_w is what's left.
value_w = frame_internal _width - key_w
value_w = available _width - key_w
else
else
if self.value_align == " right " then
if self.value_align == " right " then
key_w = frame_internal _width - value_w_rendered
key_w = available _width - value_w_rendered
value_w = value_w_rendered
value_w = value_w_rendered
value_align_right = true
value_align_right = true
end
end
end
end
-- Adjust widgets' max widths and text as needed
-- Adjust widgets' max widths if needed
if value_prepend_space then
value_widget : setText ( " " .. tvalue )
end
value_widget : setMaxWidth ( value_w )
value_widget : setMaxWidth ( value_w )
if fit_right_align and value_align_right and value_widget : getWidth ( ) < value_w then
if fit_right_align and value_align_right and value_widget : getWidth ( ) < value_w then
-- Because of truncation at glyph boundaries, value_widget
-- Because of truncation at glyph boundaries, value_widget
@ -250,6 +246,9 @@ function KeyValueItem:init()
} ,
} ,
key_widget ,
key_widget ,
} ,
} ,
HorizontalSpan : new {
width = middle_padding ,
} ,
LeftContainer : new {
LeftContainer : new {
dimen = {
dimen = {
w = value_w ,
w = value_w ,