GWT - how to precisely set rendered width of TextArea in pixels? - gwt

I need to render a TextArea in an exact pixel width for the special purposes of my GUI.
When I set its width to "250px", it comes out as 256px.
Is there a way to override this behavior so I can render it as 250px exactly?

When you use setWidth(), you're effectively setting the element's content width.
To get the offset width use UIObject#getOffsetWidth(). This will return the width including padding and border (but not margins).
References on W3C
Computing widths and margins
The box model

Related

How to calculate fontsize of same height by component height?

There's a RectComponent, and a TextComponent inside. The text will change length sometimes.
So I need "text adaptation".
The fontsize :
The size of glyphs (in logical pixels) to use when painting the text.
I cannot find the conversion method between fontSize(logical pixels) and component size.
Is there some formula between "component size" and "font size"?
There is currently no way to automatically fit the text in the size of the RectangleComponent.
You can however use TextComponent.textRenderer.measureWidth and calculate whether the font size has to be smaller or larger than it currently is.
Remember that if you don't use a mono-spaced font, a string with the same amount of characters as another string might become different widths.
You can use FittedBox, check this answer out:
How to dynamically resize text in Flutter?
So, basically, FittedBox makes sure the content always stays within an area.

How to Calculate the Height and Width of Forms in Powerhsell?

Can someone help me in understanding how to calculate the Height and Width of a Powershell Forms. For Example I Created a blank Powershell form of Height 500 and Width 700 and now If want to place a Text box a little below from the top of the form what will be the height and width that I need to enter? and If I want to place a Button at middle of the Form? what will be the height and width that I need to enter? I am struggling with this calculation.
You should get the screen size and use the ratio to set position. The ratio is useful for different screen size.

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.

Matlab - change height of the text field on the whole figure

Is there a way to change the height of a text field on the whole figure without changing the x and y position?
To change we must use the position, which requires to change the coordinates. I would like to change only the height, without changing x and y.
Just store the current x and y, and use those in your set call like so:
old_pos = get(text_field_handle,'Position');
set(text_field_handle,'Position',[old_pos(1:2),new_width,new_height]);
Well, you can change the FontSize property, this won't change the coordinates, but will increase width as well as height. See Text Properties in the doc for more details.
I am assuming you are working with uicontrol('style','text').
From the uicontrol properties you have:
Position
position rectangle
*Size and location of uicontrol*. The rectangle defined by this property
specifies the size and location of the control within the parent figure
window, uipanel, or uibuttongroup. Specify Position as:
[left bottom width height]
where left and bottom define the distance from the lower-left corner of the
container to the lower-left corner of the rectangle. width and height are the
dimensions of the uicontrol rectangle.
You can then just change the width and height keeping the original left and bottom.
One can set the Margin property of a text object to increase the height of the object without changing the fontsize, but this influences both the height and the width of the text object. I am not sure what it means to make the height smaller than what Matlab thinks is the text height, so I will assume you are interested in increasing the size.
Increasing the height of the text object is relatively easy if you are willing to use the LaTeX interpreter. You just need to add an "empty" box of whatever height you want:
text(0.5, 0.25, 'Hello World\parbox{\textwidth}{\vspace{1in}}', 'Interpreter', 'LaTeX', 'BackgroundColor',[1, 0, 0]);
This won't increase the height by exactly 1 inch, instead it will be more like 1 inch minus a baseline skip. Determining the actual height increase in displayed units adds even more problems. You might be able to change the height with unicode characters, and hence skip the LaTeX interpreter, but I have no idea how.

Getting panel width and height in GWT

I want to draw a gradient to a canvas and add it to an AbsolutePanel, thus i need width and height of absolutePanel to define gradient vector. But event if I add AbsolutePanel to RootLayoutPanel (via the north-widget of a DockPanel, which width set to 100%) and call a method setGradient() after, i still get 0 for width and height. How can i get the dimensions of the panel?
Use getOffsetWidth() and getOffsetHeight() methods. The doc is here:
Gets the object's offset width in pixels. This is the total width of the object,
including decorations such as border, margin, and padding.
The methods are defined in UiObject, so common for all widgets.