How to align text from both sides ?

Hi all,

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.

http://uploads.im/LuJAe.png

[lua]

local widget = require( “widget” )

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
}

paragraph = display.newText(options )
paragraph.anchorX = 0
paragraph.anchorY = 0
paragraph:setFillColor( 0,0,0 )
scrollView:insert( paragraph )

[/lua]

Thanks

Abdul

At the moment it’s not possible to do “full” justification in Corona.

You can add a feature request for it here:

http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback.

PS.

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…

ingemar,

Thanks for passing and commenting… I will wait for you on this and I appreciate your help.

thanks

Abdul

It’s solved  :slight_smile:

 
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.
 
 
Sample code

https://github.com/swipeware/justify

@Ingemar, nice stuff dude :wink:

I put up the code with sample project on github for anyone interested.  :slight_smile:

Super ignemar,

 

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 .  :wink:

 

 

 

Regards

Abdul

عفوا  :slight_smile:

:)  أحسنت يا مبدع

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.

thanks

Abdul

[quote name=“Gremlin Interactive™” post=“254159” timestamp=“1404294423”]@Ingemar, nice stuff dude ;)[/quote] Absolutely amazing!!!

@alzaabi98

I’m not sure what you mean.

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.

exactly… That what I did … If I reduce the maxwidth, i change the x proprety to poistion it again to right , and it worked nicely…

 

thanks

Abdul

@alzaabi98

Great!

At the moment it’s not possible to do “full” justification in Corona.

You can add a feature request for it here:

http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback.

PS.

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…

ingemar,

Thanks for passing and commenting… I will wait for you on this and I appreciate your help.

thanks

Abdul

It’s solved  :slight_smile:

 
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.
 
 
Sample code

https://github.com/swipeware/justify

@Ingemar, nice stuff dude :wink:

I put up the code with sample project on github for anyone interested.  :slight_smile:

Super ignemar,

 

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 .  :wink:

 

 

 

Regards

Abdul

عفوا  :slight_smile: