can someone help me to align this text from both sides (left and right). I want it to be justified within both sides of screen ? with following code m it is right aligned.
local myText = “تتمتع عمان بوضع سياسي واقتصادي مستقر في العموم، مع ذلك شهدت السلطنة احتجاجات محدودة في ولاية صحار مطالبين برفع الرواتب وإنهاء الفساد وإيجاد المزيد من الفرص الوظيفية، المزيد من حرية التعبير وتقليل الرقابة الحكومية على الإعلام ولم تطالب بإسقاط نظام الحكم [10] رد السلطان قابوس بن سعيد بإقالة ثلث أعضاء حكومته من مناصبهم [11] وتشتهر عمان بأنها أحد أهم مراكز المذهب الإباضي، حيث يعتبر المذهب الآساسي في الحكم ، بالاضافة لوجود المذهب السني والشيعي.[12]”
local paragraph
– scrollView
local scrollView = widget.newScrollView
{
top = display.statusBarHeight,
left = 10,
width = display.contentWidth -20,
height = display.contentHeight - display.statusBarHeight*2,
scrollWidth = display.contentWidth -20,
scrollHeight = 1000
}
— paragram
local options = {
text = myText,
width = 280,
font = native.systemFont,
fontSize = 12,
align = “right”,
y=100
}
I have some old justification code somewhere in my old libraries (before left/right/center was supported by Corona). I didn’t implement “full”, but I might be able to have a look at it to see if it will work. I don’t know if it will handle RTL text though. Anyway, I’ll have a look and get back to you on this thread. However it may take a few days…
I dug out my old justification functions, but full justification required me to write a brand new function:
justifyFull()
Overview
Adjusts the spacing between the words on each line of the given text so that the left and right margins are the same.
The function returns a display group with a top-left anchor point.
Syntax
justifyFull( options )
This function takes a single argument, options, which is a table that accepts the following parameters:
maxWidth (optional)
Number. The maximum width of each line. Defaults to display.contentWidth.
rtl (optional)
Boolean. Set to true if using an RTL text string (like Arabic). Defaults to false
text (required)
String. The text to justify.
font (optional)
String. Name of the font. Defaults to native.systemFont.
fontSize (optional)
Number. Font size. Defaults to 12.
fillColor (optional)
Table. A table with RGBA color values. Defaults to {1}.
Gotchas
You can’t change the anchor point of the returned display group. It’s fixed at 0, 0.
The justified text can’t be modified. If you need to modify a word within the text the whole paragraph must be recreated.
This was fast and extremely helpful. I liked your professionalism of handling this problem. This is ideal and optimal way of solving issues. I would this is the rare model responses in this forum. i appreciate your help man .
just noticed one thing… if you reduce the width of text using maxWidth , The text x position will slide lttle to the left. I am not sure if this normal behaviour. As per my understanding , it should shorten the width of the whole text but not changing the x position of it.
However in your example, if you reduce maxWidth it will seem like you end up with a wider right margin, right? However it isn’t. The display group returned by my function knows nothing about its parent, so if you reduce maxWidth, you’ll need to adjust the x property so that it will be placed properly within its container.
If you look at the sample project on github, I’ve set paragraph.x=10 to position it properly within the scrollview. If you change the width of the scrollview or maxWidth, you’ll need to adjust the x property accordingly.
I have some old justification code somewhere in my old libraries (before left/right/center was supported by Corona). I didn’t implement “full”, but I might be able to have a look at it to see if it will work. I don’t know if it will handle RTL text though. Anyway, I’ll have a look and get back to you on this thread. However it may take a few days…
I dug out my old justification functions, but full justification required me to write a brand new function:
justifyFull()
Overview
Adjusts the spacing between the words on each line of the given text so that the left and right margins are the same.
The function returns a display group with a top-left anchor point.
Syntax
justifyFull( options )
This function takes a single argument, options, which is a table that accepts the following parameters:
maxWidth (optional)
Number. The maximum width of each line. Defaults to display.contentWidth.
rtl (optional)
Boolean. Set to true if using an RTL text string (like Arabic). Defaults to false
text (required)
String. The text to justify.
font (optional)
String. Name of the font. Defaults to native.systemFont.
fontSize (optional)
Number. Font size. Defaults to 12.
fillColor (optional)
Table. A table with RGBA color values. Defaults to {1}.
Gotchas
You can’t change the anchor point of the returned display group. It’s fixed at 0, 0.
The justified text can’t be modified. If you need to modify a word within the text the whole paragraph must be recreated.
This was fast and extremely helpful. I liked your professionalism of handling this problem. This is ideal and optimal way of solving issues. I would this is the rare model responses in this forum. i appreciate your help man .