GTK+ widget background image alignment - gtk

I set background image for a button by:
bg_pixmap[NORMAL] = "img.png"
but most of the times the image is offset with certain x, y when:
there is padding around
there is adjacent widgets at left/top
align the button 0.5, 0.5 of an alignment container of larger size
...
how can I specify the background image to alway start from 0, 0 of the button?
EDIT
it seems bg_pixmap is always tiling start from 0, 0 of the window ( but shown only in the button area )....
but when I use bg_pixmap on widgets not has state changes (only NORMAL image is shown), the image is aligned correctly... (e.g. drawing area, event box, etc...)

Looks that Gdk::Window::set_back_pixmap is the function you are looking for. Point is the parent_relative boolean that change the tiling starting point.
C. F.

WORKAROUND
I worked around this and make an "image button" works with rc style file:
add GtkButton inside an EventBox
EventBox -> Visible Window = Yes ( No won't make it work )

Related

How do I copy text inside of the tooltip that appears when hovering over elements?

I'm trying to set min and max dimensions for some elements on a webpage and for elements near the end of the screen, the tooltip is cut off. Usually I would just look at the computed height and width and guess what it could be rounded to, but the width and height are set to auto.
I can't change the size of the viewport, since the size of most of my elements is dependent on viewport width.
I could try to copy the text inside of the tooltip, but I don't know how to get it to stay frozen in place so that I can select the text.
I saw some answers saying to hold F8, but that only works if you have a tooltip applied to the element you're hovering over, it doesn't freeze the inspect tooltip.
An example of what I'm trying to describe.
Source: https://developer.chrome.com/blog/new-in-devtools-75/#A%20detailed%20tooltip.

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.

Unity3d. UI elements snapping/anchoring

I have canvas with vertical layout and 2 elements within (in fact it's element with only recttransform on it, let's call it container). So these 2 containers take a half of the screen by height and stretched by width, ok. How can I place an text element in above container and snap it to the bottom of this container? I tried press bottom button in recttransform widget (also with shift and alt) and it seems it doesn't affect my transform at all
P.s. May be I can use some free plugin instead of default unity components of UI layout?
There are different ways of placing your UI elements
Simply drag and drop it to the bottom where you want it
Use the anchor widget to set the anchoring to bottom with horizontal stretch and hold shift to also set pivot. Then set Pos Y to 0. Set Left and Right to 0.
Assuming you also want other elements in your containers, place a Vertical Layout Group on each container and make sure that your text element is the last child of the container in the hierarchy.
I would also advise you to seek out tutorials on Unity UI anchoring, positioning, scaling, and layout. You need a deeper understanding of how these things interact than you are likely to get from Stack Overflow. Otherwise you will suddenly find that your UI behaves in unexpected ways when rearranged or displayed on a different aspect ratio.
It's fairly easy with Unity UI system. You just need to get used to it. Here are simple steps to accomplish what you want:
Create Text element as a child of that container.
Select your newly created element and edit its RectTransform component values:
2.1. Set both Y axis anchors (min and max) to 0.
2.2. Set pivot value to 0 as well.
2.3. Set Pos Y value to 0 as well.
Now your Text element is anchored at the bottom of the container and its position (and height) is measured from the bottom of the Text element itself.

How to get exactly the same point on different screen sizes?

I want to call the action (go to another view) when user tap specific area of image (black dots): . Image fills whole view, content mode is 'Aspect Fit'. The problem is that when I setup it on one screen size (e.g. iPhone 8) on another the 'tap area' is shifted. I've tried to solve this with button and constraints or UITapGestureRecognizer with point conversion using screen resolution (nativeBounds), but nothing helps.
It is possible to use constraints to match the positions of the circles with UIButtons. The trick is to use the multiplier of the constraint to scale the buttons width/height and position to the screen size.
I'll describe how to do it for one button, and then you can repeat it for the others. I assume the image is 657 wide by 918 high. If I have the dimensions reversed, you'll need to substitute the actual values for the ones I have used.
Create a UIView to hold the image and buttons. Give this view an aspect ratio constraint with multiplier 657:918 which is width:height. Add the UIImageView to this view and constrain its 4 edges to the edges of the view with 0 offsets. Give this view constraints to the left and right edges of the main view and give it a vertical constraint to place it on the screen.
Get the width/height of the circle in the image and the horizontal and vertical positions of the right edge and bottom edge. For example, the topmost circle is 106 x 106 and ends at horizontal position 392 and the bottom is at 338.
Set the width of the button equal to the width of the containing view with multiplier 106:657 which is width of circle:width of the image.
Set the height of the button equal to the height of the containing view with multiplier 106:918 which is height of circle:height of the image.
Set the trailing edge of the button equal to the trailing edge of the containing view with multiplier 392:657 which is end of circle:width of image.
Set the bottom edge of the button equal to the bottom edge of the containing view with multiplier 338:918 which is bottom of circle:height of the image.
This will allow the button to stay aligned with the circle on all devices. Repeat steps 2 through 6 for the other circles.
Instead of using an image, you can try creating your own UIView subclass called BlackDotsView.
In the draw(_rect:) method, you can draw the lines. To determine where the lines start and end, you need to do some maths with the view's width and height. You calculate where all the lines end and create UIBezierPaths and then you stroke the paths.
In the initializer of BlackDotsView, you can add the dots as subviews. To make them circular, just set dotView.layer.cornerRadius to half the dot's width. Then, you can add UITapGestureRecognizers to the dot views.
You can follow the delegate pattern by creating a BlackDotsViewDelegate that has a method called dotTapped(index:). When a dot is tapped, you would call the delegate method and pass the index of the dot.

Hide UI/Image partially in Unity 5

Does Unity 5 support partial hiding of a UI/Image?
For example, the UI/Image I have in my scene has 100 width and 100 height.
At time = 0, the UI/Image is hidden. When time = 5, the UI/Image only shows the first 50 pixels. When time = 10, the UI/Image is fully drawn.
The answer to the question is in this link
Set the image type to Filled
Set the fill method to horizontal
Set the fill origin to left
From the script, update the fill amount from 0 to 1 over the timespan
On first thought, I can come up with two workarounds for this.
If the background of the image-in-question is a solid color, you can use another image with the same color as background that covers the actual image, so that it looks like the actual image is partially revealed. Then, just reduce the length of this covering image over time to achieve a revealing effect using Coroutines.
You make multiple image files with alpha channels and change the textures of the UI/Image over time. Each image will act like an iteration of revealing effect. Say you have 11 images, the 6th image will have first half revealed, and second half as alpha=0. In this case, if you want smoothness, you will need a higher number of images.