This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Aligning text


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
purple_pixie
Veteran Member
Join Date: Jun 2007
Location: Winchester, England
Old 08-22-2007 , 14:38   Aligning text
Reply With Quote #1

I've been trying to make a nice looking skill select menu, showing the skill names and your current level in it.

Naturally I wanted the skill levels to line up (on the right)

something like:
Code:
Select Skills 1. Skill1    0 2. Skill2    3 3. Skill3    1

(Is there anything other than "small" tags that will stop spaces being trimmed? "pre" tags don't exist )

I've tried looping through the array from strlen(array) up to the last index, setting each to 32 (space) and then setting the last to 48+skill level (the integer in ASCII )

But of course different letters have different widths ...

Even setting each level to 9 ( a tab ) keeps them mis-aligned. (And I tried just using 3 tabs ... still no joy)

In case it's relevant, here's my code:
Code:
{     new name[37]="";         skill=CLASS_SKILLS[PlayerClass[id]][i] // get the skill         formatex(name,40,"%L",id,SKILLS[skill]) // and its name         for ( j=strlen(name) ; j < 35 ; j ++ )  // from the end of the string to the end of the array             name[j]=9 // add a tab         name[++j]=48+PlayerSkills[id][skill] //  Integer  + 48 =  its ascii value. ( for an integer < 10 )         name[++j]=0 // terminate the string         menu_additem(skillmenu,name,skills[i],0,1) // add the option }

Last edited by purple_pixie; 08-22-2007 at 14:46.
purple_pixie is offline
thebobjones34
Member
Join Date: Oct 2006
Old 08-22-2007 , 19:58   Re: Aligning text
Reply With Quote #2

Code:
new len len = strlen(skill) if(len > 10 && len < 16) // for the sake of argument lets just say if its 10 characters it needs only 2 tabs     add(menu,1023,"1. %s        ") else if(len < 10)     add(menu,1023,"1. %s            ") else     add(menu,1023,"1. %s    ")
Stupid way of doing it, but i think that should get the job done if you set the "If" statments right, im just trying to get you headed in the right direction.
__________________
thebobjones34 is offline
Send a message via AIM to thebobjones34
_Master_
Senior Member
Join Date: Dec 2006
Old 08-23-2007 , 02:21   Re: Aligning text
Reply With Quote #3

Best way of doing that is NOT doing that. Text contains variable-length chars, for ex: "i" takes less space than "W". So if your text would be "iii" it would be aligned, but if it's "WWW" tho the length is the same, it would break alignement. Adding white spaces would do nothing unless you add them to the string itself and in specific amount. If your text is dynamicly computed then it's a dead end.

[EDIT] I could be wrong but I think there is a "%t" or something like that which adds white spaces but I doubt it measures the "screen size" of the text...

Last edited by _Master_; 08-23-2007 at 02:27.
_Master_ is offline
purple_pixie
Veteran Member
Join Date: Jun 2007
Location: Winchester, England
Old 08-23-2007 , 04:18   Re: Aligning text
Reply With Quote #4

Well that just plain annoys me :-D

Thanks for the help, people ...

I don't suppose you can change the font to one that's ... er, what's the word for a font with equal-sized letters?


Ah well, I'll settle for having it not line up ...

I could swear that WC3 mod's "ChangeRace" menu has the XP aligned on the right ... but then the source code doesn't seem to do it explicity.
Maybe I'm comparing the source of a version I haven't played to what I remember playing.

Ah well.
purple_pixie is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 08-23-2007 , 04:33   Re: Aligning text
Reply With Quote #5

Quote:
Originally Posted by _Master_ View Post
[EDIT] I could be wrong but I think there is a "%t" or something like that which adds white spaces but I doubt it measures the "screen size" of the text...
^t - You can use it to add a white space...
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
purple_pixie
Veteran Member
Join Date: Jun 2007
Location: Winchester, England
Old 08-23-2007 , 06:16   Re: Aligning text
Reply With Quote #6

Is that just the same as putting whitespace in the string?

(i.e. setting an array index to 32)
purple_pixie is offline
_Master_
Senior Member
Join Date: Dec 2006
Old 08-23-2007 , 11:53   Re: Aligning text
Reply With Quote #7

The font is called "fixed".
The alignment you mentioned is also to the left but the text is displayed on the right side of the screen.

@Alka: Right. Thx.
_Master_ is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:01.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode