Skip to content

Commit

Permalink
Option for compact Labels
Browse files Browse the repository at this point in the history
  • Loading branch information
immortalx74 committed Nov 25, 2022
1 parent 5d842f4 commit 6d572e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ If `width` is provided, it will be taken into account only if it exceeds the wid
|Argument|Type|Description
|:---|:---|:---|
|`text`|string|label text
|`compact` _[opt]_|boolean|ignore vertical margins

<span style="color:DeepSkyBlue">Returns:</span> `nothing`

Expand Down
11 changes: 8 additions & 3 deletions ui/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1762,16 +1762,21 @@ function UI.SliderFloat( text, v, v_min, v_max, width, num_decimals )
return result, v
end

function UI.Label( text )
function UI.Label( text, compact )
local text_w = font.handle:getWidth( text )
local text_h = font.handle:getHeight()
local num_lines = GetLineCount( text )

local mrg = (2 * margin)
if compact then
mrg = 0
end

local bbox = {}
if layout.same_line then
bbox = { x = layout.prev_x + layout.prev_w + margin, y = layout.prev_y, w = text_w, h = (2 * margin) + (num_lines * text_h) }
bbox = { x = layout.prev_x + layout.prev_w + margin, y = layout.prev_y, w = text_w, h = mrg + (num_lines * text_h) }
else
bbox = { x = margin, y = layout.prev_y + layout.row_h + margin, w = text_w, h = (2 * margin) + (num_lines * text_h) }
bbox = { x = margin, y = layout.prev_y + layout.row_h + margin, w = text_w, h = mrg + (num_lines * text_h) }
end

UpdateLayout( bbox )
Expand Down

0 comments on commit 6d572e2

Please sign in to comment.