I'm wondering how would I keep the exact same distance between 2 points because I'm currently doing an hud at the moment and when the user's balance increases a digit, the rectangles width increases and there's 2 rectangles one money & one group and when the user's money has a certain amount of digits the width of the money box will overlap the group's box.
visual:
@@@ -- Money Balance rectangle
### -- Group Balance rectangle
{space} -- space between the 2 rectangle
------------------------
@@@{space}### <--- This is how the user's hud looks like when there's 1 digit
-----------------------
------------------------
@@@### <--- This is how the user's hud looks like when there's 2 digit (There overlapping)
-----------------------
I'm going to assume you are using draw.SimpleText (also applies to draw.Text).
When using draw.SimpleText, it returns the width and height of the text which can be used in positioning the second text element.
[lua]
local x, y = 100, 100
local w = draw.SimpleText("Text 1", "DermaLarge", x, y, Color(255, 255, 255))
draw.SimpleText("Text 2", "DermaLarge", x + w + 50, y, Color(255, 255, 255))
[/lua]
If you're using draw.DrawText, surface.GetTextSize might work as an alternative to draw.SimpleText's return values.
If you're using Derma/VGUI, docking should work nicely here in combination with DockMargin.
[QUOTE=Bo98;50417098]I'm going to assume you are using draw.SimpleText (also applies to draw.Text).
When using draw.SimpleText, it returns the width and height of the text which can be used in positioning the second text element.
[lua]
local x, y = 100, 100
local w = draw.SimpleText("Text 1", "DermaLarge", x, y, Color(255, 255, 255))
draw.SimpleText("Text 2", "DermaLarge", x + w + 50, y, Color(255, 255, 255))
[/lua]
If you're using draw.DrawText, surface.GetTextSize might work as an alternative to draw.SimpleText's return values.
If you're using Derma/VGUI, docking should work nicely here in combination with DockMargin.[/QUOTE]
I'm trying to achieve this with rectangles not text. But I'm assuming I would do the same thing. Also I'm using surface library.
Edit: Do you have a different solution for surface.DrawRect()
[QUOTE=Good;50417223]I'm trying to achieve this with rectangles not text. But I'm assuming I would do the same thing. Also I'm using surface library.[/QUOTE]
If you're trying to find the width (and height) values of a string of text with the surface library you can use [URL="https://wiki.garrysmod.com/page/surface/GetTextSize"]surface.GetTextSize[/URL] with [URL="https://wiki.garrysmod.com/page/surface/SetFont"]surface.SetFont[/URL]. You can use these values to change the position of the rectangles - though you probably don't need to be told that.
So where does the "digits" part come in? Is there any text at all? Is it a rectangle surrounding text or what?
[QUOTE=Bo98;50417505]So where does the "digits" part come in? Is there any text at all? Is it a rectangle surrounding text or what?[/QUOTE]
Updated the original thread.
Not entirely sure what SCREEN_WIDTH is referring too (doesn't look like it would be ScrW()) but how you deal with it seems to be inconsistent in your surface.DrawRect calls: sometimes you seem to add it to a static value, sometimes you multiply. It that intentional?
[QUOTE=Bo98;50417560]Not entirely sure what SCREEN_WIDTH is referring too (doesn't look like it would be ScrW()) but how you deal with it seems to be inconsistent in your surface.DrawRect calls: sometimes you seem to add it to a static value, sometimes you multiply. It that intentional?[/QUOTE]
[CODE]
local w, h = ScrW(), ScrH()
SCREEN_WIDTH = w / 1600
SCREEN_HEIGHT = h / 900
[/CODE]
That's me trying to solve the problem
GetTextSize was returning the incorrect value which resulted it not working properly I found a snippet of a more efficient GetTextSize.
It solved my problem.
[code]
function GetTextSize(text, font)
surface.SetFont(font)
local w, h = surface.GetTextSize(text)
return w, h
end
[/code]
Sorry, you need to Log In to post a reply to this thread.