adding space to text

Posted By: Reconnoiter

adding space to text - 05/16/15 11:40

Howdy,

How come to following code only works for text objects that don't have a font set (so it uses the standard / build in? gs3d font):

Code:
function list_addspaces(var maxcheck)
{
  var length = str_len(mystring);
  var addspace = clamp(maxcheck - length,    1,   maxcheck);
  var i;
  for (i = 0; i < addspace; i++) str_cat(mystring, " ");	
}


function writestrings()
{
  ...
  list_addspaces(10);
  ...
}



I want to use this for a big list.
Posted By: Quad

Re: adding space to text - 05/16/15 13:49

str_len takes STRING* as parameter not TEXT*
Posted By: Reconnoiter

Re: adding space to text - 05/16/15 14:00

I accidently typed mytext here instead of mystring when writing this post.

But anyway, how to get the above working for a text with a font set to it (like arial, calibri whatever)? It does work when not setting a font, but when I set a font it does not work anymore. Does this have to with differences in pixel width between letters and spaces in fonts?
Posted By: DLively

Re: adding space to text - 05/16/15 14:47

I didn't want to suggest this because it may seem redundant or even stupid at worst - to some. But make sure you spelt it right laugh : FONT* arial_font = "Arial#20b";

I seriously doubt the above is the problem - but the engine will allow you to run the game even if you don't correctly type in your font names.

Just a thought... laugh
Posted By: Wjbender

Re: adding space to text - 05/16/15 15:25

try replacing the space with another caracter to see what happen .. (havent really looked in to it)

but after that I think try something like chr() or ascii() I cannot remember right now , dont know if gamestudio has it
Posted By: Anonymous

Re: adding space to text - 05/16/15 16:08

I know you are looking to solve this. However, a very easy way is to use different TEXT* object for each column. If you are making a list then this is a fine solution. But this is a design solution to a code problem.

also try str_length(myText->pstring[0])

that's wrong but you get the idea.
str_len((my_text.pstring)[7]);
Posted By: Reconnoiter

Re: adding space to text - 05/16/15 16:32

ty for all the fast reactions;

@DLively, double checked it just to be sure, the font itself looks fine.

Quote:
try replacing the space with another caracter to see what happen .. (havent really looked in to it)
, yes this makes a difference, the "_" seems to be working alot better than " ". Probably cause its pixel size is bigger(?). Still not perfect, but I will try to toy around with str_width.

Quote:
but after that I think try something like chr() or ascii() I cannot remember right now , dont know if gamestudio has it
, there is _chr and _str, but that doesn't seem to have any effect.

Quote:
also try str_length(myText->pstring[0])
, yes I am actually using an text array with pstring already, but I wanted it to keep it clear here.

Quote:
I know you are looking to solve this. However, a very easy way is to use different TEXT* object for each column. If you are making a list then this is a fine solution. But this is a design solution to a code problem.
, this is probably the best solution, as in multiple strings per text objects for each column. Though I am a bit wary of using multiple strings cause the list is going to be enormous (with a slider etc to scroll quickly through it). It should able to contain a 1000 lines atleast. So I was thinking adding multiple strings would increase memory usage to much, but maybe I am wrong here?? I hope to be wrong at that grin
Posted By: Reconnoiter

Re: adding space to text - 05/16/15 17:56

I quess it is not possible to set the position of strings of a text object, right? Would be nice if I can use them as columns. Or atleast to try it out.

-edit

str_width works better than str_length, its not yet perfect though:

Code:
function list_addspaces(var count, var maxcheck)
{
  var length = str_width( mystring, calibri15_font) / 10;
  var addspace = clamp(maxcheck - length,    1,   maxcheck);
  var i;
  for (i = 0; i < addspace; i++) str_cat( mystring, "    ");	
}

Posted By: Anonymous

Re: adding space to text - 05/16/15 19:23

Quote:
I quess it is not possible to set the position of strings of a text object, right?



check out offset_y http://www.conitec.net/beta/atext-offset_y.htm

and
FLAGS CENTER_X CENTER_Y http://www.conitec.net/beta/atext-flags.htm
Posted By: Reconnoiter

Re: adding space to text - 05/17/15 15:09

Thanks but that effects the whole text object instead of only part of it and it effects the y pos not the x pos.

But there is a solution, monospaced fonts do the trick when combining with my first code example (the one that use str_len instead of str_width), cause in a monospaced font every letter has the same size laugh . It can look a bit uglier, but so far I am happy with FONT* CourierNew18 = "Courier New#18"; .

-edit LucidaConsole14 is a very good choice if you don't have much space while still wanting to keep it a bit clear.
© 2023 lite-C Forums