Scale down UITextView with Transform - uitextview

I am trying to scale down a UITextView with a custom font in a storyboard with constraints. I can easily animated the bounds and also the font-size. However, since it is a custom font the font-changing becomes quite choppy at larger sizes. I figured this could be done with by changing the transform of the UITextView. However, this does not seem to be working. The text view is self sizing in height, but uses a fixed with constant for width (which animated along with the font size/transform). This go gain control over where the text view line breaks.
I've tried all suggested solutions below without success. Either the view keeps it bounds but lowers in resolution. Or the bounds decrease, but faster than the appeared font size resulting in clipping.
Scaling UITextView using contentScaleFactor property
I've also tried to place the text view in a placeholderview where I also animated the height/width constraint multiplier to make sure it decreases in size.

Solved it by placing my UITextView in a placeholder UIView and setting align center X/Y + Equal width/height constraints to it.
I also animated to multiplier of the width/height contraints between these views to the inverse of the current transform scale. This to compensate for the scaling of the transform.
textViewWidthConstraint = textViewWidthConstraint.withMultiplier(1/scale)
textViewHeightConstraint = textViewHeightConstraint.withMultiplier(1/scale)
placeholderView.transform = CGAffineTransform(scaleX: scale, y: scale)
where function withMultiplier is a rename of the solution presented in https://stackoverflow.com/a/33003217/511299 for editing constraint multipliers.

Related

How to clip vega-lite text inside a rect?

In a webpage created with node/webpack, vega-lite, and vegaEmbed, I have a layer with rect marks with short annotations inside them using text marks. I'd like to clip the text to its surrounding rect but haven't figured out a way to do this and hope someone can point me in the right direction.
I realize text has a limit property in pixel units. If I could determine the pixel units of my rect marks (I don't know how to do this), using limit seems like a reasonable approach.
Also, if I knew the pixel extents of my rectangle, I can then write code to align the text within the rect which would be desirable. Currently I just use the same x as the rect, with a dx offset.
I've read about background for text which is a similar problem, but not the same.

Codename one - scrollable layout restrictions

I have done my own version of the PropertyCross Demo (provided in their demo section).
The problem I currently face is the size of the "Recent Search" area. While I have a non-scrollable container, I can easily define the preferred height. As the Box Layout adheres to the preferred size, all is well, with the little issue of not being able to scroll it and see more than one result:
recentSearchContainer = new Container(new BoxLayout(BoxLayout.Y_AXIS)); recentSearchContainer.setPreferredH((int)(this.getContentP‌​ane().getHeight() * 0.1f));
Once I set the container to scrollable, the preferred height gets overwritten and takes up as much space as it needs, taking too much space from the BorderLayout Center piece above it.
How to manipulate the preferred size of scrollable components?
You don't manipulate the preferred size. Scrollables take up more space so if you need them to take up a specific amount of space you need to use the right type of layout which in this case might not be border layout...
Border layout gives NORTH/SOUTH elements their preferred height which might not be what you want. You might want a grid layout which will divide the height 50/50. You might want a table layout where you can define the height in percentages etc.
For those who are interested, here is the solution:
Setup a table layout with a single column and as many rows as you need (similar to box layout y axis or border layout which only north, center and south).
Set the table layout to non-scrollable so it defaults to 100% of your screen.
add the components with height % of the screen they should take up.
those components can be scrollable and will still stick to the height constraint!
// inside a form object, setup the layout
TableLayout tl = new TableLayout(3, 1);
tl.setGrowHorizontally(true);
setScrollable(false);
setLayout(tl);
...
// and add stuff to it
add(tl.createConstraint().heightPercentage(15), labelDesc);
add(tl.createConstraint().heightPercentage(50), compGroup);
add(tl.createConstraint().heightPercentage(35), recentSearchContainer);
Works like a charm!

How to get correct text width for oblique font in DirectWrite?

I create a IDWriteTextLayout object by the following code,
hr = g_pDWriteFactory->CreateTextLayout(text, textLength, *g_pTextFormat, 200000000, 200000000, g_pTextLayout);
then get the text width by text metric,
DWRITE_TEXT_METRICS dtm;
pTextLayout->GetMetrics(&dtm);
float minHeight = dtm.height;
float minWidth = dtm.widthIncludingTrailingWhitespace;
what confuse me is that whether the style of the font is DWRITE_FONT_STYLE_OBLIQUE or DWRITE_FONT_STYLE_NORMAL, the width of the same string is the same value. Why? I expect that when the font style is DWRITE_FONT_STYLE_OBLIQUE, the width should be bigger. how can i get the correct width for oblique text?
Thanks.
Layout metrics are based on font design metrics, either hinted or not, and not on actual ink box for each glyph. If you want metrics that closer match resulting rendered bitmap size, you can adjust returned layout metrics with data GetOverhangMetrics() returns. But at the end the only way to know exact pixel size of resulting layout is to render it.
So answering your question, returned layout metrics for oblique font are already correct, they just mean slightly different thing than you expect them to.

Swift and autolayout: proportional font size in a label

I have a storyboard with (among other things) a label. Its height is proportional to the screen height. But the text size in the label is always the same. I'd like to also have a proportional font size.
Does anyone know how to do this?
Thank you for your help.
Edit: Maybe I should specify that my label has both width and height proportional to the screen size (the bigger the screen is, the bigger the label is).
I did it programmatically but I'd like to know if it's possible to do it from the storyboard.
click the label and choose the size properties inspector on the right hand side and edit the font size. You can then choose a size of your choosing

Decreasing Polyline Stroke Width

I am trying to mimic the behavior of markers on white boards and was wondering if it I can do it with svg polylines. I know the stroke width can be set but can be it changed to vary depending on the velocity of the mouse which I can figure out or is it just a constant value for the stroke?
Or if you wanted to use SVG, instead of using a <polyline>, use a series of connected <line>s
You can't have multiple stroke widths in a single polyline element. I think canvas is probably a better fit for this task.

Resources