Aligning text to always be on the outside of line - alignment

I know how to align text diagonally, but I'm having trouble aligning the text to be always on the outside, as the diagram shows:
http://i38.tinypic.com/rs4zlj.png
The lines will always be positioned as a triangle.
What I get instead is, depending on the angle, text is inside or out (and upside down). Is there any math that can help me out here? I have the angle of every line, if that is helpful at all.

Related

Text isn't positioned precisely enough

If Konva.Text align is set to right or verticalAlign to middle or bottom it's not being positioned well enough and always have some offset from right or/and bottom. Are there any ways to fix that?

How to align two UILabels on the Y axis of the center of the first line of text

please see the image below for two examples of what is to be achived
the alignment should be on the Center Y of the first lines of each UILabels and should work regardless of font size or font. currently we have implemented this with different constraints to the top of the super view for different font and font size combinations.
the constraint to align the center of the two UILabels does not work since the text of the second UILabel is not fixed and can have several lines.
also the text is dynamic, so it is not known where the text will wrap to create the first line, thus it cannot be shown in an one line UILabel with the rest of the text in another one below.
currently this is implemented using UIKit, but if there is an easy solution in SwiftUI we can put these two labels in a SwiftUI component. so a SwiftUI solution would also be welcomed.
Your comments said "it should be on the glyphs" ... but, without additional information, my guess is that "real world" usage would not really need that level of precision.
For example:
While the glyphs are not perfectly center-Y aligned, it seems unlikely you'd run into a case where the first line of the "rightLabel" is " ' " ' " or . , . , ..
This layout can be easily done with only a few constraints - no need to do any calculations:
The "Positioning" label would, of course, be set .hidden = true so it would never be seen.
If you really, really want glyph-precision, you'll need to calculate
the Glyph bounding box for the left-label
the Glyph bounding box for first line of the right-label
calculate the "character box" offsets to align the Glyph Y-centers
and then position the two labels accordingly, or use Core Text to draw the text (instead of using UILabel).
Probably more work than necessary -- unless your actual use-case demands it.
That's an interesting problem! You can try using the centerYAnchor for the label on the left, and the firstBaselineAnchor for the label on the right... that will align the center Y with the text baseline, which isn't quite what you want.
To find the correct offset to apply, you can use the information from UIFont about the size of the characters. I'd probably start with capHeight * 0.5 and see if that looks or feels right. Something like:
leftLabel.centerYAnchor.constraint(equalTo: rightLabel.firstBaseLineAnchor, constant: rightFont.capHeight * 0.5)
This is a more difficult problem in SwiftUI, I think, because resolved font metrics aren't directly available to you.

Roblox Lua Script, How to make a frame decrease its size from left to right?

I'm trying to make a health bar that decreases from left to right instead of from right to left
and it has to be this way because of how the interface looks, I've tried different calculations but all of them were close but too far and I'm running out of ideas on how to make it
Take a look into anchor point.
What anchor point does is set the origin of the UI. So for your use case, you'll probably want to set the anchor point to [1,0]. Which means the UI will scale to the left
(White Box) Anchor point 0,0
(White Box) Anchor point 1,0
With an anchor point of 1,0, it will scale to the left

Alignment of UILabel and word wrapping with right-to-left language

I have a view that has an image, and to the left it is a long block of text that may take up multiple lines. In English, the first line might be full, and on the second line it may only take up half of the left side of the screen. When using Arabic, should the text be aligned towards the right side, where the first line is full, but the second line takes up half of the line and is aligned with the right?
I am using Auto Layout. Is there something, like the hugging settings, that I want to adjust?

Problem with a vertical UISlider with custom images

So i have a custom UISlider. It's vertical (i did it with the +270° technic). I have 3 images, respectively for the minimum value, maximum value and for the thumb. Everything seems good but i have problems with the extrema values, as you can observe on the screen capture (even though it's a little dark).
The slider on the left is perfect ! Both end of the sliders show the images perfectly and the cursor (thumb) is perfectly cutting the slider in 2.
The other two sliders on the right shows a similar issue. We can see that, when in extrema value, the cursor is not well located (there shouldn't be any part of the image below or above the middle of the cursor !) Oo
More to that, let's look at the right slider (with minimum value). We can see that image has been cut on the bottom ! Indeed it should be close. It's the same thing for the maximum value, the image looks like it's been cut.
I looked at the bounds of the slider view by touching it at both ends and looking at its coordinates. The slider was defined with a height of 300 but i can perform touches at coordinate 307, or -6 !!! I don't really understand why..
For more information, coordinates form 300 to 310 represents the maximum value i defined and negative coordinates (from 0 to -10) represents the minimum value.
-> So We can notice there's a difference of 10 at both ends.
Please help ! :s

Resources