Is there a SwiftUI equivalent for lineBreakMode for Text views? - swiftui

I have a Text view, and I would like to configure it to wrap the first character that doesn't fit. In UIKit, this would be the equivalent of setting label.lineBreakMode = .byCharWrapping. Has this been implemented for SwiftUI Text yet? I haven't been able to find anything in the documentation for Text.
The reason that I want to do this is that I'm displaying a long code to the user, so wrapping by character rather than by word is desirable.

Not sure if this helps, but I am using the following which leads to long words getting wrapped by characters:
Text("Supercallifragilisticexpialidocious")
.font(.system(size: 100))
.minimumScaleFactor(0.01)
.lineLimit(3)
.multilineTextAlignment(.leading)
Unfortunately for my use case, I do not want the Text to wrap by characters. If I set lineLimit(1) that works fine and the font size is reduced to keep the Text on 1 line. But if Text is multiple words such as Text("Practically perfect in every way") then I want the string wrapped by word. I can't seem to get both Word wrapping for multiple words and font scaling for long words.

Related

SwiftUI: How to suppress line breaks for a part of texts?

I would like to prevent line breaks in a parts of SwiftUI Text - for example, when I have label like Car speed is 10 m/s., I would like to force SwiftUI to keep the m/s (or preferrably 10 m/s) together (but still allow it to do linebreaks elsewhere in text).
With default settings, the label might break like this 10 m<br>/s, which I'd like to prevent.
If the character in question would have been dash, I could use a non-breaking dash, but no such luck here.

QListWidget very long text

I'm asking this question because i dont know how to google it, i dont find the right keywords.
I have a QListWidget with strings inside. The strings are very long and if i disable horizontal scrolling, which is what i want, then the text ends with ... because it is too long.
I would like to have the text to display the end of the text and the beginning like:
This is very long text to This is ... text instead of This is very long ...
Is there any simple way to achieve this without having to manipulate the string? I need the full string afterwards and i dont want to store extra data. Any help is appreciated.
There is indeed a very easy solution: Lock for TextElideMode and Qt::ElideMiddle (setTextElideMode ( Qt::TextElideMode mode )).

long text printed on screen creating a horizontal line and going of of bounds while printing

I am working on textarea where the user can enter text to create the letter. now if they keep typing continuously, it creates a lengthy string and once they save it in database, the same letter is available for print. Now while printing, it shows a very long horizontal bar. While printing, text is being cut off
I tried using the WRAP function of Function, but that creates extra Tags where they are not needed, Although in letter, there are couple of instances where they are needed. using the Following Code replaces all &NBSP;.
#Wrap(qryGetLetterDetails.letter,'([[:print:]])( )([[:print:]])','\1 \3','all'),75)#
My Next Approach was using the Custom Lib Function WRAP available on CFLIB.org
Again with this Tag, it generated the source HTML on screen while wrapping the Letter. It did not worked as expected.
I tried searching CSS ways to force to break word but in vain. I am using IE7+ versions only, No other Browser Support is provided.
can you try with
#ReplaceList(qryGetLetterDetails.letter, "#chr(10)#,#chr(13)#", "<br />")#

How do tabs work for text boxes?

I'm making a game gui api and I'm wondering how to implement tabs. I'm using freetype for text. When I try to render '\t' It looks like a square. I'm wondering how tabs are implemented because they are not a fixed width.
Thanks
For a fixed-width font you could compute how many spaces to the next tab stop, but the general solution is to stop rendering when you hit a tab, move to the next tabstop, and then render the text that comes after the tab character starting from there. Where the tabstops are is up to you, but a good default is probably something like every 8 ems.
The simplest strategy is to swap a tab out for a some number of spaces. I.e. when the user pushes tab, pretend they pushed tab four times instead. (Or just print out four spaces, whatever works for you)

Use cases for regular expression find/replace

I recently discussed editors with a co-worker. He uses one of the less popular editors and I use another (I won't say which ones since it's not relevant and I want to avoid an editor flame war). I was saying that I didn't like his editor as much because it doesn't let you do find/replace with regular expressions.
He said he's never wanted to do that, which was surprising since it's something I find myself doing all the time. However, off the top of my head I wasn't able to come up with more than one or two examples. Can anyone here offer some examples of times when they've found regex find/replace useful in their editor? Here's what I've been able to come up with since then as examples of things that I've actually had to do:
Strip the beginning of a line off of every line in a file that looks like:
Line 25634 :
Line 632157 :
Taking a few dozen files with a standard header which is slightly different for each file and stripping the first 19 lines from all of them all at once.
Piping the result of a MySQL select statement into a text file, then removing all of the formatting junk and reformatting it as a Python dictionary for use in a simple script.
In a CSV file with no escaped commas, replace the first character of the 8th column of each row with a capital A.
Given a bunch of GDB stack traces with lines like
#3 0x080a6d61 in _mvl_set_req_done (req=0x82624a4, result=27158) at ../../mvl/src/mvl_serv.c:850
strip out everything from each line except the function names.
Does anyone else have any real-life examples? The next time this comes up, I'd like to be more prepared to list good examples of why this feature is useful.
Just last week, I used regex find/replace to convert a CSV file to an XML file.
Simple enough to do really, just chop up each field (luckily it didn't have any escaped commas) and push it back out with the appropriate tags in place of the commas.
Regex make it easy to replace whole words using word boundaries.
(\b\w+\b)
So you can replace unwanted words in your file without disturbing words like Scunthorpe
Yesterday I took a create table statement I made for an Oracle table and converted the fields to setString() method calls using JDBC and PreparedStatements. The table's field names were mapped to my class properties, so regex search and replace was the perfect fit.
Create Table text:
...
field_1 VARCHAR2(100) NULL,
field_2 VARCHAR2(10) NULL,
field_3 NUMBER(8) NULL,
field_4 VARCHAR2(100) NULL,
....
My Regex Search:
/([a-z_])+ .*?,?/
My Replacement:
pstmt.setString(1, \1);
The result:
...
pstmt.setString(1, field_1);
pstmt.setString(1, field_2);
pstmt.setString(1, field_3);
pstmt.setString(1, field_4);
....
I then went through and manually set the position int for each call and changed the method to setInt() (and others) where necessary, but that worked handy for me. I actually used it three or four times for similar field to method call conversions.
I like to use regexps to reformat lists of items like this:
int item1
double item2
to
public void item1(int item1){
}
public void item2(double item2){
}
This can be a big time saver.
I use it all the time when someone sends me a list of patient visit numbers in a column (say 100-200) and I need them in a '0000000444','000000004445' format. works wonders for me!
I also use it to pull out email addresses in an email. I send out group emails often and all the bounced returns come back in one email. So, I regex to pull them all out and then drop them into a string var to remove from the database.
I even wrote a little dialog prog to apply regex to my clipboard. It grabs the contents applies the regex and then loads it back into the clipboard.
One thing I use it for in web development all the time is stripping some text of its HTML tags. This might need to be done to sanitize user input for security, or for displaying a preview of a news article. For example, if you have an article with lots of HTML tags for formatting, you can't just do LEFT(article_text,100) + '...' (plus a "read more" link) and render that on a page at the risk of breaking the page by splitting apart an HTML tag.
Also, I've had to strip img tags in database records that link to images that no longer exist. And let's not forget web form validation. If you want to make a user has entered a correct email address (syntactically speaking) into a web form this is about the only way of checking it thoroughly.
I've just pasted a long character sequence into a string literal, and now I want to break it up into a concatenation of shorter string literals so it doesn't wrap. I also want it to be readable, so I want to break only after spaces. I select the whole string (minus the quotation marks) and do an in-selection-only replace-all with this regex:
/.{20,60} /
...and this replacement:
/$0"ΒΆ + "/
...where the pilcrow is an actual newline, and the number of spaces varies from one incident to the next. Result:
String s = "I recently discussed editors with a co-worker. He uses one "
+ "of the less popular editors and I use another (I won't say "
+ "which ones since it's not relevant and I want to avoid an "
+ "editor flame war). I was saying that I didn't like his "
+ "editor as much because it doesn't let you do find/replace "
+ "with regular expressions.";
The first thing I do with any editor is try to figure out it's Regex oddities. I use it all the time. Nothing really crazy, but it's handy when you've got to copy/paste stuff between different types of text - SQL <-> PHP is the one I do most often - and you don't want to fart around making the same change 500 times.
Regex is very handy any time I am trying to replace a value that spans multiple lines. Or when I want to replace a value with something that contains a line break.
I also like that you can match things in a regular expression and not replace the full match using the $# syntax to output the portion of the match you want to maintain.
I agree with you on points 3, 4, and 5 but not necessarily points 1 and 2.
In some cases 1 and 2 are easier to achieve using a anonymous keyboard macro.
By this I mean doing the following:
Position the cursor on the first line
Start a keyboard macro recording
Modify the first line
Position the cursor on the next line
Stop record.
Now all that is needed to modify the next line is to repeat the macro.
I could live with out support for regex but could not live without anonymous keyboard macros.