Hi, I'm messing around with some DLabels, parented to a DPanel.
However, I'm struggling by making the Text in center of the DPanel, and I have no idea why it wont center.
[CODE]
local DiamondInfo = vgui.Create( "DPanel", DiamondPNL )
DiamondInfo:SetPos( 1,0 )
DiamondInfo:SetSize( 200,900)
local Diamond = vgui.Create( "DLabel", DiamondInfo )
Diamond:SetText( "5.000.000" )
Diamond:Center()
Diamond:SetFont( "TheDefaultSettings" )
Diamond:SetTextColor( Color( 13, 189, 0, 255 ) )
[/CODE]
And is it possible for me to add one of the [URL="http://www.famfamfam.com/lab/icons/silk/preview.php"]GUI icons[/URL] write besides the text?
As I want it to say: "5.000.000"Dollar-icon-goes-here
Thanks
It would be easier for you to just override DiamondInfo:Paint( w,h ) and draw your text and icon there.
Diamond:CenterVertical()
Diamond:CenterHorizontal()
It most likely won't center because it's '0 pos' is to the left.
If you want to change the way it gets aligned, you have to use surface.GetTextSize( string text ), divide it by 2 and then sub the output from X.
[QUOTE=Robotboy655;43618018]It would be easier for you to just override DiamondInfo:Paint( w,h ) and draw your text and icon there.[/QUOTE]
Thanks, but how would I do that? And is it possible to parent it to the DPanel, or is that even necessary?
[lua]
Diamond:SizeToContents()
local x, y = Diamond:GetPos()
Diamond:SetPos( x - Diamond:GetWide() / 2, y )
[/lua]
That's how I do it anyway.
[QUOTE=arcaneex;43618101][lua]
Diamond:SizeToContents()
local x, y = Diamond:GetPos()
Diamond:SetPos( x - Diamond:GetWide() / 2, y )
[/lua]
That's how I do it anyway.[/QUOTE]
Thanks, however this made the text center left, eh..
btw, I'm having this issue with the text where it doesn't print out the full text. E.g if I wanted it to say "5.000.000", it would output "5.000.0.."
[lua]Diamond:SizeToContents()[/lua]
Tried it, still bugging like this: [url]http://puu.sh/6sThA.jpg[/url]
What do you mean it centered to the left? If you want it to be centered to the right replace the minus operator with a plus one.
Arcane, he's saying he wants it in the middle of the window I believe.
Yes, when I used Arcanes code, it turned out like this:
[url]http://puu.sh/6sTtk.jpg[/url]
[lua]
Diamond:SizeToContents()
local _, y = Diamond:GetPos()
Diamond:SetPos( DiamondInfo:GetWide() / 2 - Diamond:GetWide() / 2, y )
[/lua]
[QUOTE=arcaneex;43618235][lua]
Diamond:SizeToContents()
local _, y = Diamond:GetPos()
Diamond:SetPos( DiamondInfo:GetWide() / 2 - Diamond:GetWide() / 2, y )
[/lua][/QUOTE]
Thanks, that worked!
However I have no clue why the label won't print the whole message, but cut it off with a ...
My guess is that you're doing SizeToContents before setting font/text.
If I'm wrong then do this and see how it works out:
Diamond:SetSize( 100, 35 )
[code]
label:SizeToContents() -- Make sure the shit is the right size
label:SetContentAlignment( 5 ) -- Numpad style, 8 is top, 2 is bottom etc
[/code]
The text fixed when I called Diamond:SizeToContens after setting font / text.
And EvacX, that worked too, thanks a lot guys.
Sorry, you need to Log In to post a reply to this thread.