Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / EditBox Text Alignment(Right Justify, Centre Justify , Left Justify) etc

Author
Message
Rudders
12
Years of Service
User Offline
Joined: 20th Jan 2012
Location: Oxfordshire UK
Posted: 11th Mar 2015 10:33
Hi All,

Been away for so long now but back in earnest now and nearing the release of my beta version of a new Placement Editor Pro! See pic attached if interested...

Anyway... I am trying to 'Left Justify' text in an EditBox. The EditBox text is set by the program using 'SetEditBoxText(101,texta$). texta$ represents a floating point variable eg. 420.0345687635217738000. The EditBox is only wide enough to show 4 characters and only displays the last few characters of texta$ as the text is right scrolled. I understand that this is necessary when inputting text in order to see the characters you are typing in.... However I want to have the EditBox display the initial string Left Justified...

Hope clear and hope someone has an idea

Cheers

Rudders (back again)

Attachments

Login to view attachments
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 11th Mar 2015 17:19
I have exactly the same issue...so keen to hear solutions.

One solution is to read the float into a string and then manipulate that string to be only a certain number of digits...but wondering if there is a more elegant solution?

Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 11th Mar 2015 17:47
I'm curious as to why you would need to edit such a number in the first place!

<<It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.>> Dijkstra
Rudders
12
Years of Service
User Offline
Joined: 20th Jan 2012
Location: Oxfordshire UK
Posted: 11th Mar 2015 19:12
Thanks for the replies so far... Yes the 'string' solution is one that works but as you say not exactly elegant!

The reason for this requirement is that I set the EditBox text from the X and Y coordinates of a sprite. This is a float number and therefore displays as I have explained..

Justifying text (Right Align) in an EditBox would be useful when entering financial amounts so that the decimal point and pence amounts would line up, etc

Cheers
Impetus73
12
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 11th Mar 2015 21:43
using floats for maps, is not a very good solution, since floats are not exact numbers, they can fluctuate and variate between systems. Better to use an integer to store coordinates. A sprite can only be at a certain pixel anyways. If you need sub-pixel precision, maybe you can divide all the integer by a factor of 1000, so that 1234 = 1.234

----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.
Rudders
12
Years of Service
User Offline
Joined: 20th Jan 2012
Location: Oxfordshire UK
Posted: 12th Mar 2015 09:38
Hi, the reason for using float values for coordinates is that when Physics are activated for a sprite the X, Y values are float. You can notice this when you have built some kind of sprite structure and when it initially loads you get a slight 'bounce' while the sprites settle. Using float values and storing these after the 'bounce' enables you to load the structure with these float values for each sprite and the 'bounce' is eliminate.

Not a serious problem in most cases but if you have designed an intricate structure with say all the sprites balancing on each other (such as in Angry Birds) you can find the structure falling down every time it initially loads.

I have found this issue whilst developing my ne Sprite Placement Editor Professional that allows you to test Physics ON to you layout designs. With my editor you can enable Physics, allow the 'bounce' if any to settle and then save the coordinates of each sprite so that when loaded into a new app they are rock solid.

Cheers Rudders
Rudders
12
Years of Service
User Offline
Joined: 20th Jan 2012
Location: Oxfordshire UK
Posted: 12th Mar 2015 09:38
Hi, the reason for using float values for coordinates is that when Physics are activated for a sprite the X, Y values are float. You can notice this when you have built some kind of sprite structure and when it initially loads you get a slight 'bounce' while the sprites settle. Using float values and storing these after the 'bounce' enables you to load the structure with these float values for each sprite and the 'bounce' is eliminate.

Not a serious problem in most cases but if you have designed an intricate structure with say all the sprites balancing on each other (such as in Angry Birds) you can find the structure falling down every time it initially loads.

I have found this issue whilst developing my new Sprite Placement Editor Professional that allows you to test Physics ON to you layout designs. With my editor you can enable Physics, allow the 'bounce' if any to settle and then save the coordinates of each sprite so that when loaded into a new app they are rock solid.

Cheers Rudders
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 12th Mar 2015 12:37
I can see that, but if the user can edit the value it should be something in a sensible range. A spin-edit style would be a good way to do it.

<<It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.>> Dijkstra
Rudders
12
Years of Service
User Offline
Joined: 20th Jan 2012
Location: Oxfordshire UK
Posted: 12th Mar 2015 14:01
Yes limiting the user input is required and decimal places for X and Y coords input is not necessary.

What is 'spin-edit' style?\

Cheers Rudders
Rudders
12
Years of Service
User Offline
Joined: 20th Jan 2012
Location: Oxfordshire UK
Posted: 12th Mar 2015 14:07
I should say to any others interested that it is simple to define the number of decimal places shown in Text or EditBoxes by adding a parameter to the String command e.g.

X# = 12.3456789

X$ = str(x#,2) // the 2 parameter defines 2 decimal places... I do not think it rounds?

Print(X$) - Prints 12.34

Cheers

Login to post a reply

Server time is: 2024-06-16 22:03:22
Your offset time is: 2024-06-16 22:03:22