Make TextField wrap to a new line, not overflow - input

I am using a simple TextField wrapped in a Container.
When the user types a long string, I want it to automatically wrap to a new line.
It currently flows off the screen, on a single line. How do I fix this?

Unlimited number of lines
new TextField(..., maxLines: null)
or limited number of lines
new TextField(..., maxLines: 3)
This way it starts scrolling when the content exceeds the height of the input field
https://docs.flutter.io/flutter/material/TextField/maxLines.html

You have to set maxLines property to null. It default to 1.

Related

How to remove all text color attributes from a QTextDocument?

I've got a QTextDocument read from an HTML file; given a QString of HTML data named topicFileData, I do topicFileTextDocument.setHtml(topicFileData);. I then want to strip off all of the color information, making the whole document just use the default foreground and background brush. (I do not want to explicitly set the text to be black text on a white background; I want to remove the color information from the document.) (Background info: the reason I need to do this is that there are spans within the document that are erroneously set with a black foreground color, rather than just having no color information set, and that causes those spans to display as black-on-black when my app is running in "dark mode", when Qt changes the default text background brush to be black instead of white.)
Here's what I tried:
QTextCursor tc(&topicFileTextDocument);
tc.select(QTextCursor::Document);
QTextCharFormat noColorFormat;
noColorFormat.clearForeground();
noColorFormat.clearBackground();
tc.mergeCharFormat(noColorFormat);
This does not work, unfortunately; it looks like mergeCharFormat() does not understand that I want the clearForeground() and clearBackground() actions to be merged in to strip off those attributes.
I can do tc.setCharFormat(noColorFormat); instead, of course, and that does strip off the color attributes correctly; but it also obliterates all of the other character format info (font, etc.), which is not acceptable.
So, ideally I'd like to find an API that lets me explicitly remove a given text attribute from a QTextDocument. Alternatively, I guess I need to loop through all the spans of the QTextDocument one by one, get the char format of the current span, remove the color attributes from the format, and set the modified format back onto the span. That would be fine; but I have no idea how to loop over spans in that way. Thanks for any help.
Instead of creating a new instance of QTextCharFormat, update the current format and reapply it on the QTextEdit;
default = QTextCharFormat()
charFormat = self.textCursor().charFormat()
charFormat.setBackground(default.background())
charFormat.setForeground(default.foreground())
self.textCursor().mergeCharFormat(charFormat)
A sub-optimal solution that I have found as a workaround is to actually edit the HTML data string before I create the QTextDocument, using a regex:
topicFileData.replace(QRegularExpression("(;? ?color: ?#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])"), "");
This works for my situation, because all of the colors in my HTML file are set with color: #XXXXXX style attributes that can be stripped out of the HTML itself. This is fragile, however; colors specified in other ways would not be stripped, and if the body text of the HTML document happened to contain text that matched the regex, the regex would modify it and thus corrupt the content of the document. So I don't recommend this solution, and I won't be accepting it. If somebody can offer a better solution that would be preferable.

What is the function called 'numberOfLines'?

I modified numberOfLines in this code.
But I didn't figure out yet what hability it has.
What is this?
<Text numberOfLines={10}>{this.state.bodyText}</Text>
numberOfLines is used to limit visible text on screen.
From docs: (https://facebook.github.io/react-native/docs/text#numberoflines)
Used to truncate the text with an ellipsis after computing the text layout, including line wrapping, such that the total number of lines does not exceed this number.
This prop is commonly used with ellipsizeMode.

How to fill available tableview width with columns?

When tableview is created, the default behaviour of columns is to leave a lot of empty space. Is there a way to automatically fill the space?
One solution is described here:
JavaFX 2 Automatic Column Width
but this seems a little cumbersome.
TornadoFX comes with an advanced column resize policy called SmartResize. You assign it to a TableView like this:
columnResizePolicy = SmartResize.POLICY
By default it tries to do something useful depending on the data, and it will assign any left over width to the last column.
You can configure resizing options per column by calling the appropriate configurator function. For example, to tell the policy to give remaining width to a given column:
column("Name", Person::nameProperty).remainingWidth()
You can configure multiple columns to receive remaning width, so that they will share the remaining width between them.
contentWidth() will make sure the column width fits the content, with optional additional padding: contentWidth(padding = 50.0).
Most resize options also take an optional useAsMin parameter which will enforce the given setting as a minimum width for the column. useAsMax does the same for max width. You will get a fixed size by setting both useAsMin and useAsMax or specifying the fixedWidth(width) option.
You can distribute space using the weigthedWidth(weightNum) function, or even the pctWidth(pctNum) function. All these modes can be combined
Please see the TornadoFX Guide chapter about the resize policy for more information:

How do I use multiple different UIFonts in a UILabel?

I have an UILabel in my UIView. The text of my label is dynamic: it's a web service call which returns to me the text that I will put in my label. Here's an example of the content of the label:
"this is an example of my text/nthis is the second line".
I would like to put the first line in a specific font (Helvetica-Bold 12px for example) and the second line in another font (Helvetica 15px for example). How i can do this?
Thanks for your answers.
Honestly I'd recommend using two separate UILabel instances, take your text and get an array via [string componentsSeparatedByString:#"\n"], then place object at index 0 in the first one, and if you have a second object, put it in the second label.
You could go for a static UIWebView and simply wrap your text into HTML+CSS. This will be much easier than doing all the layout in code.
Maybe what you are looking for is NSAttributedString.
Here is a example: iphone/ipad: How exactly use NSAttributedString?

Printing multiple UIElements in Silverlight 4

I have a page that has two UIElements that need to be printed, one is a StackPanel and the other is a custom graph control for displaying test scores. The graph control could be any length based on the number of tests to display, so sometimes I will be able to fit both on one page and other times will need separate pages.
Printing them on separate pages works fine as I just set the UIElement to the pagevisual, the problem I am having is that I can't figure out how to combine them for printing on a single page. I tried creating a StackPanel in the codebehind and adding the elements to it, but since an element can only have one parent I have to create temporary objects to hold each one while I remove from the original parent and then give the temp to the new StackPanel. The problem is that after I do that all the bound data goes missing
Any ideas would be awesome! Thanks.
Instead of adding actual elements to the StackPanel for printing, you can create snapshots of those elements and add only images to the StackPanel. You can use the following method to created an Image from a UIElement:
public static Image CreateElementImage(UIElement element)
{
var bitmap = new WriteableBitmap((int)element.RenderSize.Width, (int)element.RenderSize.Height);
Array.Clear(bitmap.Pixels, 0, bitmap.Pixels.Length);
bitmap.Render(element, element.RenderTransform);
bitmap.Invalidate();
var result = new Image {Source = bitmap};
return result;
}
Or just put the image in a Canvas and then compare Canvas's height and image height to calculate number of pages.