Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] SWT Styledtext word wrap

Hi,

Am 05.09.2012 10:17, schrieb Marek Jasovsky:
initially I set the text of Styledtext as " word word word word
longword longword longword longword "

I have no \n there.

as soon as I insert it, does Styledtext break this in lines? using \n ?

StyledText does not wrap text by inserting or removing \n characters. Like I said, if your original text contains \n characters, then it will use one TextLayout per section between \n characters. Each such section is considered a "line". But depending on the width of the StyledText control, these "lines" (really paragraphs) may be soft wrapped into multiple lines (which has nothing to do with \n anymore). The wrapping is actually done by the TextLayout implementation (using native platform APIs).

So, if you have no \n in your editable section, then this whole section is considered a single "line" by StyledText, no matter how many visual lines it is wrapped into. This is important when using the StyledText API that deals with "line" indexes. For example getTopIndex() would always return the index of this section, even when you scroll the StyledText up so that some of the wrapped lines are scrolled out of view.

and protected area is part of text, with different color background,
where I do not want the user, to edit this part. I want to adjust the
styledtext for translations of texts, where you have only one paragraph
at time to edit. other paragraphs, including source language of current
paragraph have to be read-only

so you have

some other stuff
-------------
originaltext auf deutsch
--------------
my translation in english
---------------
another stuff


other and another stuff has to be read only

german text is too read only

It is probably a lot easier to simply put these sections into separate controls. It's also possible to make them layout such that no scrolling is needed (i.e. the bottom controls make room as the editable area grows), but maybe scrolling wouldn't even be so bad.

english translation is editable, no matter, how many lines I have there.
then.. if I have 100 words in translation, but I manually do not insert
new line, but just type and type... does styledtext enter \n there?

No it does not. Definitely.

if I
ask styledtext to extract lines 5-10, where I know that this is "my
translation in english" part... will I become \n there?

No, there will be no \n inserted because of soft wrapping (which is what happens here). BUT you would not extract "lines 5-10", since (which is I what I am trying to tell you) StyledText considers the whole block of wrapped text a *single* line. Really, this is just misnamed in StyledText, it should have been called a "paragraph". You won't believe how confusing it gets when you look at the actual StyledText code.

> in MS-Word you
have a distinction between soft line break and hard line break. soft is
wrapped text by word, hard is manually entered paragraph break.

do you now unterstand what I mean?

Perfectly.

thanks a lot

No problem.



Back to the top