Skip to content

Commit 3685db8

Browse files
committed
*Improved text positioning of MultilineLabel.
1 parent 7a7b67d commit 3685db8

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/libs/beGUI/beGUI_Basics.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ local MultilineLabel = beClass.class({
298298
end
299299
local initPos = Vec2.new(posX, posY)
300300
local lineMargin = 1
301-
local spaceW = measure(' ', font_.resource)
301+
local spaceW, _ = measure(' ', font_.resource)
302302
for i, v in ipairs(words) do
303303
local w_, h_ = measure(v.text, font_.resource)
304304
if self._lineHeight ~= nil then
@@ -351,7 +351,7 @@ local MultilineLabel = beClass.class({
351351
local x_, y_, w_, h_ = x + v.position.x, y + v.position.y, w, height
352352
local intersects = Math.intersects(canvasRect, Rect.byXYWH(x_, y_, w_, h_))
353353
if intersects then
354-
beUtils.textLeft(v.text, v, x_, y_, w_, h_, elem.content_offset, self.transparency)
354+
beUtils.textLeftSameLine(v.text, v, x_, y_, w_, h_, elem.content_offset, self.transparency)
355355
end
356356
end
357357
if self._theme and self._theme ~= 'font' then

src/libs/beGUI/beGUI_Utils.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,17 @@ local function tex9Grid(elem, x, y, w, h, permeation, alpha, color_)
327327
end
328328
end
329329

330+
local function textLeftSameLine(txt, font_, x, y, w, h, offset_, alpha)
331+
local dx = offset_ and offset_[1] or 0
332+
local dy = offset_ and offset_[2] or 0
333+
local textWidth, textHeight = measure(txt, font_.resource)
334+
local fx, fy = x + dx, y + dy
335+
local col = alpha and Color.new(font_.color.r, font_.color.g, font_.color.b, alpha) or font_.color
336+
text(txt, fx, fy, col)
337+
338+
return fx, fy, textWidth, textHeight
339+
end
340+
330341
local function textLeft(txt, font_, x, y, w, h, offset_, alpha)
331342
local dx = offset_ and offset_[1] or 0
332343
local dy = offset_ and offset_[2] or 0
@@ -379,6 +390,7 @@ return {
379390
merge = merge,
380391
tex3Grid = tex3Grid,
381392
tex9Grid = tex9Grid,
393+
textLeftSameLine = textLeftSameLine,
382394
textLeft = textLeft,
383395
textCenter = textCenter,
384396
textRight = textRight

src/main.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,9 @@ function setup()
447447
:put(0, 90)
448448
:resize(P(100), 60)
449449
:addChild(
450-
beGUI.MultilineLabel.new('The Quick Brown Fox Jumps Over the Lazy Dog.\n[col=0xff0000ff]ABCDEFG[/col] [col=0x00ff00ff]HIJKLMN[/col] [col=0x0000ffff]OPQRST[/col] UVWXYZ abcdefg hijklmn opqrst uvwxyz 1234567890 ! @ # $ % ^ & * ( ) ` - = [ ] \\ ; \' , . / ~ _ + { } | : " < > ?')
450+
beGUI.MultilineLabel.new('The Quick Brown Fox Jumps Over the Lazy Dog.\n[col=0xff0000ff]ABCDEFG[/col] [col=0x00ff00ff]HIJKLMN[/col] [col=0x0000ffff]OPQRST[/col] UVWXYZ abcdefg hijklmn opqrst uvwxyz 1234567890 ! @ # $ % ^ & * ( ) ` - = [ ] \\ ; \' , . / ~ _ + { } | : " < > ?\n')
451451
:setId('multilinelabel')
452-
:put(P(1), 0)
452+
:put(P(1), 2)
453453
:resize(P(98), 0) -- Height is automatically calculated.
454454
)
455455
)

0 commit comments

Comments
 (0)