How to position text horizontally in vertical tabs? - kivy

I have vertical tabs but want to 'rotate' the tab labels so that these read horizontally. How could this be done?
The kivy file contains:
TabbedPanel:
id: tab_panel
tab_pos: 'left_top'
do_default_tab: False
TabbedPanelItem:
text: '1'
TabbedPanelItem:
text: '2'
TabbedPanelItem:
text: '3'

Edit: Actually, it IS possible!
TabbedPanelItem:
text: '2'
canvas.before:
PushMatrix
Rotate:
angle: -90
axis: 0,0,1
origin: self.center
canvas.after:
PopMatrix
With current api impossible. And it'll be really ugly if you manage to do it, because it'll stretch the tab-header and make it a square or even another, 90° rotated rectangle, which will screw your Layout as much as possible - the original tab will look like a casual Button and whole TabbedPanel as a beginner's try to make html page if you don't want to limit yourself to 3-4 characters with current font size. Just saying.
You may try to edit the source and one of the ways how to do it directly is making a custom ToggleButton from which TabbedPanelHeader inherits and rotate it with Push/PopMatrix().
The other (and more reasonable) way would be to make tabs look like this:
t|
a| content
b|
_|
i.e. text going up -> down, though I don't know how to do it except rotating the whole thing and work with characters like this: t\na\nb

Related

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.

Make an image in Kivy exactly the same size as the widget bounding box

I'm having trouble in Kivy setting an image size. I want to keep the aspect ratio fixed but I also want to position things precisely over the top of the image.
To do this, I make a RelativeLayout that has the same size and position as the image. However, when I check the size of the layout, it is always slightly larger than the displayed image. Making precise alignment very difficult. The wiki mentions something like this:
By default, the image is centered and fits inside the widget bounding box. If you don’t want that, you can set allow_stretch to True and keep_ratio to False.
They also include code if you want to make the image slightly larger than the containing widget:
<-FullImage>:
canvas:
Color:
rgb: (1, 1, 1)
Rectangle:
texture: self.texture
size: self.width + 20, self.height + 20
pos: self.x - 10, self.y - 10
But nothing about making them exactly the same size!? Surely I should be able to dictate the containing widgets size so the aspect ratio etc. is exactly as required.
I have tried many things but whatever I try, I cannot get the outside edges of the displayed image and a layout to coincide.
Does anyone have any experience with this?
Apologies, I have discovered the problem, the images had a transparent border that I wasn't aware of (the images were passed on to me from elsewhere) I have removed this and it has solved the problem.

Changing text adjustment in UIView using swift

I've been trying to create my app and something is bugging me very much,
I have images of what I am trying to achieve:
1)
2 )
number 1 shows what I am trying to do, the letters are "squeezed" together making the text appear tighter with a short width even though the letter sizing is big.
number 2 shows my attempt to achieve this, I tried multiple different ways to get that same look but failed for hours, does anyone have any suggestions or know how to make the text look like that in the first picture?
I appreciate any help, thank you!
The only way how to do it AFAIK is to use transform on UILabel, like this:
let widthTransform = 0.8 // Shrink label to 80% of its width
label.layer.transform = CATransform3DMakeScale(widthTransform, 1.0, 1.0);
Hope it helps!
Note* that transform work for about 30% of decrease (even less imo), then it just starts to look very bad. You can also change text spacing, but if you calculate it dynamically, you could end up with negative one and that looks terrible. The easiest way really is then just change of the design :)
Options:
You can decrease character spacing like in this answer
and increase font size.
Having fun with transformation on layer is really awful idea, as later you won't be able to get the height of text etc -> just everything will be working wrong.
You can also just use different font.

Image position between inputs xcode 6

Good afternoon,
I'm trying to put an image in the middle of two inputs, that means that I would like to have the same margin to the first input as the second input. I'm going to explain better with an example:
[input a]---- 20px-----[image]---- 20px-----[input b]
I want to have the image always at the middle between them, because when I rotate the screen I have to make it large.
I have to use constraints? Which one? Is it possible?
Thanks in advance.
There are a number of ways to approach this. (There are a number of ways to approach everything, lol).
I'm only going to show AutoLayout solutions because it will make things easer when things are moving. Also, your description is pretty much already using AutoLayout Visual Format Language.
The first would be to place inputA, inputB and image into a third view which I'll call interfaceView.
Now you can lay it out like this...
|[inputA] // i.e. up against the left edge
[inputB]| // i.e. up against the right edge
[image] is different. You then align the centre of image with the centerX of interfaceView
The second option is to use "spacer" views.
Create two more views called spacer1 and spacer2 and layout the screen like this...
[inputA][spacer1][image][spacer2(==spacer1)][inputB]
Make spacer 1 and 2 hidden. They are just there for layout purposes. Now, because I have given them equal widths they will align the image view exactly in the middle of A and B.

CSS sprite position problem

I trying to create a fixed border to the site that dynamically change size with the browser window from this sprite (it isn't perfect I know.): http://fc07.deviantart.net/fs70/f/2011/269/7/0/bordersprite_by_nakos-d4ayzne.png
DEMO on jSFiddle
My problem as you can see is the vertical wall part. As the #falJ and #falB are height:100% they include the bottom wall's end too with the space between the two wall sprites. Is there a way to force backround-position to only use vertical wall part without bottom wall's end?
Thanks in advance.
Solution: http://jsfiddle.net/vonkly/Ld43B/
It's not the prettiest thing in the world, but it achieves what you want. Check out the source code & direct link for the background images to see what you'll need to do. It's currently set at 299px wide; I imagine you'll be using something wider.
I'd also suggest adding some padding around your content (either with a p tag, span, another div, etc.) - the way it is currently set up isn't what I'd recommend for readability.
EDIT
The only way I can imagine achieving a fluid width + height box with the borders that you have in the way that you want is to use a second image for the west and east containing divs. This should work with your current method.

Resources