How can I draw only one char of a string, without moving its position? - xna

I have a string : School
i'm trying to have only 1 letter of this string to show in a different color, and move this letter back and forth.
this works somewhat ; I use a string(index) and move the index with a timer, than draw the 2nd string ("S", " c", " h", etc ) on top of the 1st.
my problem is that I cannot stack those 2 string exactly ... the space isnt the same size as the other characters.
moving orange letter
I guess I could use a Font.measureString from the part of the string "School" I want to skip, and move my orange letter according to it and tweek it depending of each letters ... but it seems a tedious way of doing this...
Is there a simpler/ better! way to do it ?

Related

Weird behaviour on joining mixed right-to-left and left-to-right language strings

Input:
tempTextArray:
▿ 3 elements
- 0 : "זה מבחן"
- 1 : "7 x 5 abc"
- 2 : "other text"
When doing a simple tempText = tempTextArray.joined(" | ") the result is not placing all elements where I'd expect them... result:
Printing description of tempText:
"זזה מבחן | 7 x 5 abc | other text"
its my first time combining right-to-left with left-to-right texts, has anyone dealt with a similar situation before?
My app is receiving translations from backend, so I don't know what elements are translated to (in this case) Hebrew, and which I will receive in my default language (English)
This is caused by the Unicode BIDI (Bidirectional Text) algorithm. First, I'll explain how to fix it, since it's fairly straightforward, then I'll explain what's happening in case you want more information.
You need to add LTR (Left-To-Right Mark) characters at each place you want to reset the text direction to be LTR. In your case that's at the start of the string and at the start of each | block:
let ltr = "\u{200e}"
let tempText = ltr + tempTextArray.joined(separator: "\(ltr) | ")
// => ‎זה מבחן‎ | 7 x 5 abc‎ | other text
If you're going to do work with Hebrew, you absolutely want to read Cal Henderson's fantastic explanation of the algorithm: Understanding Bidirectional (BIDI) Text in Unicode.
Now to explain what's happening. You're printing a single string whose first character is the ז in "זה מבחן," and last character is the final t in "text." It is not three strings separated by |, it's just one long string. When you display that string, and the BIDI algorithm has to decide where all the characters go.
The first character (ז) is a RTL character, so it decides that this is a RTL string that has some LTR text embedded. That's the opposite of what you want. You want this to be a LTR string with some RTL text embedded. So you need to start with a LTR character such as Left-To-Right Mark.
The BIDI algorithm's job is to tell the system in which direction the next character should go. Each of the characters in זה are RTL, so that's easy, keep going left. But what about the space between זה and מבחן? Space is neutral in direction, and the last character was RTL, so the space goes to the left. But then we come to the space between מבחן and |. Space is neutral and | is neutral, so the BIDI algorithm would put the space and | to the left again. You want the space and | to be LTR, so you need to add another LTR character there.
7 is also neutral, but x is LATIN SMALL LETTER X which is LTR (not MULTIPLICATION X which is neutral).
The final result is that the BIDI algorithm decides this is a RTL string that begins 7 | זה מבחן and then is followed (to the left) by an embedded LTR string x 5 abc | other text. (In other words, this is a Hebrew string that happens to have some English in it, not an English string that happens to have some Hebrew.)
I expect what's actually displayed in your question above isn't what you're seeing (because of how BIDI algorithms get applied on Stack Overflow). I expect it actually looks like this:
And if you read this right to left, it should make more sense now what's happening.

How to print string diagonally from right to left?

How can I print something diagonally , for example stars * , but diagonally from right to left? I know for the normal diagonal left-to right we just use a for loop with variable "i" in another for loop with variable "j" and put if function to print the string if i=j. but how to do it opposite?

How can i start this remain text underneath it's upper text in UILabel?

I want to show remain text of line underneath it's upper line in UILabel. How can i do that? I used UILabel for to show this text and i set Lines = 0. Any help would be greatly appreciated.
cell.Describtionlabel.text = "Intelligient Keyboard Engine (IKE™) \n\t- When typing up IKE will give you suggestions and ideas. \nDictate \n\t- We also have audio mode which allows you to dictate your report and we type it up for you.\nSelf Transcribe\n\t- If you wish to type up yourself just select self transcribe as your delivery option."
Check for the alignment, set label alignment to left,
Check if there is any initial space when you are setting the text to your label.If yes, remove that.
This will solve your issue.
User Swift Multiline String Literals
From the Doc
Multiline String Literals
If you need a string that spans several lines, use a multiline string literal—a sequence of characters surrounded by three double quotation marks:
let quotation = """
The White Rabbit put on his spectacles. "Where shall I begin,
please your Majesty?" he asked.
"Begin at the beginning," the King said gravely, "and go on
till you come to the end; then stop."
"""

Display long text in fixed frame in Corona

so at the moment I have to do an assignment at school which requires me to create a Calculator for mobile devices using Corona, ive got the buttons and display classes to work.
In the display class, Ive created 2 frame (one to display the method and the others for result). The final result im looking for is something like a handheld graphical calculator's UI (Casio fx series..).
Which means you can type in a long and continuous method (the whole text will move toe the left and always show you the END of the method) as you press "=" the calculator will give you the result.
What I've got up to so far is that I created a frame which can fit 2 lines of text for displaying the method, but once you've filled up the frame with numbers, Corona will crop out the end of the string .
so what i'm going to do is by having 2 strings, the 1st one is the main one to store what the user type in (the whole method) I will select the last 10 characters from the main string and save it in the second string and display the second string.
So do you know if there's any code that i can use to select a number of characters from a string ?
You can use the built in LUA method
string.sub (yourString, startIndex , endIndex )
http://pgl.yoyo.org/luai/i/string.sub`

Align UITextView Right and Left.

I have UITextView, which is left aligned.
When last word does not fit on current line it goes to next line leaving spaces on end of line.
which does not give good look and feel.
So, what I want that if words of particular line feels the spaces left at end.
i.e. Spaces between two words can dynamically varies.
Here I am giving example of Scenario:
The width of text view,never put off until (here tomorrow does not fit,so it goes to next line leaving spaces).
Tomorrow what you can avoid all together.
So, problem is it does look good.
What I want is:
The width of text view never put off, until (varying spaces shown by)
tomorrow -what -you -can
avoid --all -- together.
Thanks in Advance.
There is no setting for justified aligment for text you only have center, left and right. If you want justified aligment where every line has the same amount of characters or something like that you can format the text entered to have carriage returns after x amount of characters or words, or something like that.

Resources