[Closed] edittext #align
Is there a way to set the alignment of the string going into any UI element…specifically a edittext box?
I’m making a calculator tool and i’d like the string to be aligned to the right, like how most calculators are. I’ve tried the align:#right call next to my creation code for the edittext, but that doesn’t seem to do it…or i guess i’m utilizing it wrong.
Only other way i thought of doing it was filling the edittext with a specific number of spaces, and aligning it that way, but that seems tedious.
Suggestions?
Thanks
you could use offset:[10,0] to move the element but everytime you make a layout change you will need to adjust this.
Instead of trying to align the text within the box to the right, you could align a label ui item to the right and just update its .text property with your numeric answer. You wouldn’t be able to highlight and copy it though. If you want to try adding spaces to buffer the text, you could look at the gw.getTextExtent < string > method. From the docs:
Returns the text extents of the string as it would be displayed in the viewports as a point2 value.
Here’s an example usage:
(
rollout testString "Test"
(
edittext testField "Random:" width:183 readonly:true
button testBtn "Generate"
fn adjustString nString targetWidth =
(
local spaceLen = 3 --width of a single whitespace
local textLen = (gw.gettextextent nString).x
local spaceAmt = (targetWidth - textLen) / 3 - 2
for x = 1 to spaceAmt do nString = " " + nString
testField.text = nString
)
on testBtn pressed do
(
local newText = random 0. 10000. as string
adjustString newText testField.width
)
on testString open do testBtn.pressed()
)
createdialog testString width:200
)