Lately I've been thinking about how to go about coding a "fill in the gap" exercise. This kind of exercise is very popular in e-learning applications : the user is presented with text in which a few words are missing, and he has to type them in (or select them from a list).
Now, prior to Text Layout Framework, you would probably be forced to break down your text into single words, adding each one as a Label to a container (and of course a TextInput where needed). While this sounds relatively easy, it's actually not once you start realizing that you need to position the labels yourself, taking into consideration things like line breaks, mixed RTL/LTR text, nested text styling, etc. etc., which no programmer should ever have be left to deal with on his own (that is, unless what he's actually coding IS a text framework).
Luckily, now that we do have the TLF available to us in Flex 4, things are much more simple. The example below is pretty straightforward (and very well commented), but the idea is: We add each word or phrase as a SpanElement inside a ParagraphElement. For the blank gaps we add an empty InlineGraphicElement to serve as a placeholder. Once we update the display all we have left to do is calculate where that InlineGraphicElement is (x,y), and add our own flex-UIComponent-based component in its place.
This example is a very basic one. I might post a more extensive one (based on given XML, etc.) if/when I ever get to writing one.
Now, prior to Text Layout Framework, you would probably be forced to break down your text into single words, adding each one as a Label to a container (and of course a TextInput where needed). While this sounds relatively easy, it's actually not once you start realizing that you need to position the labels yourself, taking into consideration things like line breaks, mixed RTL/LTR text, nested text styling, etc. etc., which no programmer should ever have be left to deal with on his own (that is, unless what he's actually coding IS a text framework).
Luckily, now that we do have the TLF available to us in Flex 4, things are much more simple. The example below is pretty straightforward (and very well commented), but the idea is: We add each word or phrase as a SpanElement inside a ParagraphElement. For the blank gaps we add an empty InlineGraphicElement to serve as a placeholder. Once we update the display all we have left to do is calculate where that InlineGraphicElement is (x,y), and add our own flex-UIComponent-based component in its place.
This example is a very basic one. I might post a more extensive one (based on given XML, etc.) if/when I ever get to writing one.
|
exlellent, this is what I searched for my mobile app
ReplyDeleteI have added an InlineGraphicsElement in TextFlow which has some text in it. and i want to align the text vertically. ie. the text should be vertically aligned middle to the InlineGraphicsElement. rite now it is bottom aligned. how can i make it to middle aligned. please help me..?
ReplyDelete