Inner padding in jetpack compose - android-layout

Jetpack compose has a padding modifier that is actually analogous to the margin attribute in other UI toolkits (it adds space around the target). Is there a way to add inner padding to a component in compose without wrapping it with a Box/Surface?

Modifier.padding() in Jetpack Compose acts as padding or margin depending on order.
Modifier.padding(10.dp).size(200.dp) adds space before setting size you have a Composable with 200.dp size
Modifier.size(200.dp).padding(10.dp) adds padding which you have 180.dp width and height after setting 10.dp padding on each side.
You can try this with Modifier.background, Modifier.border, Modifier.clickble{} to see how order changes area with color, border or which user can click.
You can also refer codelab's documentation about Modifiers to see how to apply padding.

Related

How to get an SVG NOT to fill the available space?

Say I have a row of 3 icons, each 20px x 20px, then some links (however wide the link text is) then another couple of links. I'm using flexbox to space the elements and what I would like to happen is that the space between is evenly distributed between the elements. What actually happens is that the svg will increase its size to take up the entirity of the free space.
I have tried taking out the height and width attributes from the svg but the image disappears altogether. I haver also tried a wrapper div but the svg forces it to take up the remainder of the space.
In case anyone finds this post, svg does not have any intrinsic width or height so by removing the width and height attribute from the svg something higher up in the chain needs to have an explicit width or height, then the svg will fill that space.

Changing text canvas size

I realize I may not have my terminology down yet, I'm new to after effects, so I've attached a picture of what I am trying to achieve. I'd like to know how to resize the black canvas surrounding the "of magic" text layer can add more text.
Go to Composition > Composition Settings and change the size (in pixels) of that canvas under width and height.
Alternatively if this is a text block within an already larger canvas, click onto your text in the composition with the Type Tool cmd+t/ctrl+t and expand using the corner points to expand the visible type.

Scale down UITextView with Transform

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.

SVG Text-anchor top left

By default, the anchor for the text element in SVG is at the bottom left, but I want it to be at the top left, since I am also creating a rectangle to act as the background for the text, but it is displayed incorrectly since the text is higher than the rectangle (because rectangle anchor/offset is at the top left). Is there a way to fix this, so both text and rectangle can be drawn at same coordinates and be displayed in the same location.
The dominant-baseline property/attribute worked for me:
svg {
dominant-baseline: hanging;
}
The coordinates (x and y) you supply for text elements is used as the baseline of the text. This makes sense because if there is text with varying font sizes on the same line, you would want their baselines to line up.
There is no "automatic" way to do what you want. SVG elements are always absolutely positioned.
You will just have to move the text down a bit by making the y coordinate a bit larger.
Alternatively, you could add a dy attribute to shift the text down a bit. Or even use a transform attribute to do the same. But using either of those methods wouldn't really be simplifying the process for you.

How do I tell WPF to treat my control's Padding as part of the control?

If I add some padding between the border of a control and the content, clicking/mousing over the padding doesn't work. When I mouseover the border, my trigger is activated. Then I reach the padding, and the mouseover deactivates. Then I reach the content and it reactivates.
How can I make it so the padding is considered part of the control?
I decided to just use a transparent inner border instead of padding.

Resources