DLabel: crop left left part of text

Hello, how do I get DLabel like this to crop out left part of string?



local label = vgui.Create("DLabel", panel)
label:SetText(p)
label:SetDark(true)
label:SetContentAlignment(6)
label:Dock(RIGHT)
label:DockMargin(8, 0, 8, 0)
label:SetMouseInputEnabled(true)


Right now for string
“materials/models/weapons/kar98k/weapon_kar98k_dm.vmt”
it shows
“materials/models/weapons/kar98k/weapo…”
and I want it to show
“…s/weapons/kar98k/weapon_kar98k_dm.vmt”

Use


string.right

?

Im trying to avoid modifying string before passing it to label:SetText and rather tell label to use string.right internally when its parent’s panel is resized. Is there any switch for that in DLabel/DPanel class?

Panel:SetContentAlignment

I already use this to align label to the right of its parent panel, however it has no effect on text cropping within the label. Does DLabel have some internal member for text that I could call this on?

I doubt it, I think this is done in engine so you may have more luck looking in the Source SDK, if the VGUI files are even available.

Your best chance is registering your own label panel that does what you want it to do.

Make a function that has two arguments. One for the DLabel and one for the text. Get the width of the DLabel and use

surface.GetTextSize If that is past the width of the DLabel, then find how big a “…” would be using the same function as before. Then find out how many characters you can fit in (width of DLabel) - (… with surface.GetTextSize) probably with a loop. Then get the amount of characters that work and prepend “…” to it. Then set the text to that string.