Unity's text mesh pro input field caret is too wide and pushes text outside of textarea - unity3d

I'm working on a mind map editor in which the user can draw boxes and write text in them. However, the TMPro input fields I'm using in those boxes have extra-wide caret when I type in them, and changing the fonts didn't solve the problem. Here are some images of the issue:
The caret is so wide that it can push the text inside out of the box:
I tried to lower the caret width in my script, but it's an int and has already been set to 1. Can you give me some possible reasons as to why this is happening?

I solved that problem by multiplying width+height of my inputfield by 100 and dividing its scale by 100.
Don't forget to increase the font size significantly.

Related

Unity GUI Label text justification issue

I'm running into an issue with GUI.Label in Unity3D. If I display some text on the screen and display that EXACT same string 1 pixel down and 1 to the right, it works correctly 99.9% of the time:
var old=GUI.color;
var shadow=rec;
shadow.x++; shadow.y++;
GUI.color=Color.black;
GUI.Label(shadow, txt, style);
GUI.color=old;
GUI.Label(rec, txt, style);
I've had this same code for years but I just recently discovered that a particular string will wrap text in the wrong place on the shadow text, even though they both have the same width in their rect's and same style. What's even more strange is it won't do this every frame. The text appears when I hover over something with my mouse and moving the mouse slightly will cause the shadow string to go back & forth, wrapping two different ways causing the shadow text to not coincide with the normal colored text.
Not an edge-of-screen issue either. I'm using 2020.2.1f1.
Thanks in advance!

What's the proper way to align a strechable Text and an image to two ends in Unity UI?

I have an UI element that has a Text and an Image as its children. It has a HorizontalLayoutGroup component that enables Control Child Size and Child Force Expand.
I want the Image has a fixed size, and Text has strechable size controlled by the HorizontalLayoutGroup. So when the Image is set to inactive, the Text fills the whole space and when the Image is active, the Text shrinks a little bit in order to give space to the Image. Right now this part works good.
My second goal is to align them to both ends: the Text in the left and the Image on the right with space in between. But changing Child Alignment can't achieve this.
I tried the following solution:
Add LayoutElement both to Image and Text. On Text, enable Flexible Width and set a a value, on Image, enable Min Width and set to a value. Manually adjust the two values until it seems right.
This solution seems to work, but I don't know why. Is anyone familiar with this?What's the recommended way to do it? Thanks!
I worked it out. On the LayoutElement, treat Preferred Width or Preferred Height as Max Width or Max Height. Enable them, set the value the same with min value. One the other objects that you want to stretch, enable Flexible values. Then all worked as we want.

Trying to reduce the size of boxes on screen

I am trying to setup a style based on bootstrap3.
Basically I want to try and reduce the size of the input elements which I have done, getting a decent proportion of 'box' vs 'text'.
However if I use the same font-size in a select box with the same size then I get a situation where the text is masked along the bottom edge...
I think there is a tiny bit more margin at the top of the select box, but for the life of me I cant find where that is set in BootStrap to change it (if at all).
I think all I need to do is move the text in the 'select' element up by a couple of pixels and it will align with those bits of text in standard text boxes....
Can anyone point me in the right direct please?
Found the associated CSS in the bootstrap, with a bit of trial and error....
Mainly in the 'form-control' section.
but now also using Bootstrap 4, with a couple of additional styles.

Text component displaying lines in reverse order

Alright, I do not know how to fix this and only ran into this problem after trying to put in some longer text on a UI Text component. I have tried both pasting a value into its Text attribute through the Unity editor, and setting its value programmatically like this:
t.GetComponent<Text> ().text = "This is where meat, fish, and [...] (long text)"
Because Horizontal wrap is on, the text wraps when it reaches the edge of the available space.
However, the text displays backwards. Meaning, the start of the paragraph is at the bottom, and bottom at the top. Taking off wrap fixes this, but then the font size has to be really small (or it won't all be visible), and it can't form a normal paragraph because it has to... you know... wrap.
Is this a bug in Unity?
This is what happens - as you can see, it is displayed backwards:
The negative Line Spacing value is what is causing the issue here:
When the value of this field is less than 0, the lines will actually be arranged backwards, leading to the behaviour you're currently encountering. Just change the value to a positive number to have the text display correctly.

iWatch: WKInterfaceLabel is it possible to stop text from being cut off with "..." at the end of a label?

The text in my WKInterfaceLabel is way too long and causes the text to be cut off with dots at the end. I know for UILabel for iOS you can easily resolve this issue by enabling clip mode. I don't believe there is any way for me to resolve this for watchkit. This is going to force me to use an Image if I can't prevent the text from being cut off. Any tips or suggestions is appreciated.
You have a couple options depending on how you want the view to respond. In your interface story board select your label and open the attributes inspector.
Your first option is to change the font to a smaller size. This is more for a static label that you want to style and leave set.
Your second option is to adjust the min scale value, changing this will automatically shrink the text to fit the window up to the value provided. For example if your font size is 12pt and you set the scale to .5, the font will shrink up to 6pt before appending the ellipsis (...).
Your third option is to set the number of lines to 0 (or a higher number). This will move the text down onto the next line.
Set the number of lines to 0 and ensure the label and any containing groups are set to fit content.
if you want your font size adjust according to label size follow this method
in WKInterfaceTable attribute inspector set min scale to 0
like in screen shoot
Result before Min scale = 0
Result after Min scale = 0
Note: your no of lines also set to 1