Perfect square buttons in Unity3d - unity3d

I'm trying to create a flexible menu for my mobile project but i'm having trouble with new UI system. I could do this with code but i want to know if it's possible without coding.
Here is what i'm trying to do:
http://i.imgur.com/33yMRgV.jpg
Basically, i want to have a menu area with height of %10 of total screen height. So for example, if it's a HD device, i want height of the red area in the image to be 192 pixel (1920/10). I can do that easily but i also want to have 192x192 buttons aligned on top right corner. I can set the height to parent so it becomes 192 too but i can't set the width to height. I can use ratio fitter to make them squares but i can't place them side by side.
So basically i just want to set width of an element to it's height and puting them side by side without coding. Is it possible?
Thanks

Have a panel inside Canvas, and add horizontal layout group and then add your buttons inside this panel.
Note : You will need to increase the width of the panel more than the canvas in order to have buttons horizontally.

Related

Responsive in Unity 2D

I want my Unity 2d game responsive in all android mobile device. So i anchor 4 canvas to 4 edge (top left, top right, bottom left, bottom right).
But when i change a device, the size of each component is not change. Now i want the size of each component change depend on each resolution of device. What should i do or what tutorial i can follow.
Problem will come when i get small screensize, it like this
Canvas Scaler
You can solve it using Canvas Scaler.
You can find various options in the list in UI Scale Mode.
When selecting the option to fit the commonly used screen size,
If you want to align UI elements to the height, set Match, an element of Screen Math Mode, to Height, and if you want both height and width to match, place it in the center.

Fixed height with scaled width for UI panel [Unity]

I have to make 2 panels on the bottom of the UI. The bottom left panel needs to stay at a fixed square size regardless of the game window size. The bottom right panel needs to keep a fixed height but expand the width to fill all the space in between the bottom left panel and right of the game window.
This green panel should remain a constant sized square, while the blue panel needs to expand its width but not its height when the game window is resized.
I've tried separating them into two different canvas', and using a horizontal layout group, but I can't get what I'm looking for. The closest I've gotten is with a single canvas that doesn't scale (constant pixel size), and a horizontal layout group that has the blue panel at a maximum width for my display resolution. This leads to the blue panel just going off screen when the game window is downsized, but I need it to fit exactly to the window.
Green:
Blue:
Canvas (notice Match set to 1):
I hope it gives the result you were looking for
Adding to #slowikowskiarkadiusz answer, I was able to get my intended result by following all of these steps, except I used Constant Pixel Size for the canvas scaler. The anchor points of the blue panel allow it to still expand width, but constant pixel size kept the height constant.

How can I lay out the following screen in flutter

I am new to Flutter and trying to convert my iOS app to Flutter. However, I am having difficulty laying out the screen. Below is what the iOS screen looks like. I keep on getting red screens with layout errors saying it cannot layout the screen. When I add a column and add to that an image and a horizontally scrolling grid in Flutter I get the layout errors. How can I layout this screen?
I think it should have a column as the main widget. Then, a large image should be displayed, which displays centered width-wise on the screen. It should be constrained height-wise and wide enough not to distort the image. The photos come in a variety of heights and widths.
Then there should be a large text field centered width-wise in the central column. Then a breed text box is centered width-wise in the central column and followed by a line of stats—lastly, a city, state, and miles.
Then a centered list of icons with a single line of text-centered underneath each icon. Finally, the whole icon bar should be centered width-wise in the column.
Next, there should be a line of small photos of the cat, which is left aligned to the column and fills to the right going off-screen and scrollable horizontally. It should be a grid with a staggered layout width-wise. Each image should be a fixed height and a ratio of width to fixed height to fit the image without distorting it. The images should have rounded corners. The width and height of the source image are known ahead of time and need to be adjusted to fit the new fixed height.
Lastly, there should be a web browser that fills the width of the column with a height large enough to hold the content of the HTML without scrolling the web browser so the whole screen looks like it is one screen.
The whole screen should be able to scroll vertically but not horizontally to see the main column's total content.
Below is what the screen should look like:

Horizontal scrollview with images constant height in Unity3D UI - How?

I want to implement scrollview in Unity3D 5 UI with horizontal images downloaded from web, they have different random aspect ratios, but I want them to be constant height. And width to be according their aspect ratio, like this:
I tried to use Horizontal Layout Group, but images get too little, so it can all fit in group, when I want them to be constant height and stretch parent's width. So, like, parent's widht is primary and it affects children, but I want children to affect total parent's width (expand it when adding new children images).
Any ideas how to achieve this? Thanks.
You need to use ScrollView with horizontal scrolling enabled and vertical scrolling disabled. Setup your hierarchy as in the image below:
On the GameObject named Content attach Horizontal Layout Group and Content Size Fitter with the following settings:
Then on all your images attach a Layout Element component and during runtime calculate the width using the aspect ratio of the image and height to the Content gameobject and assign this width to Preferred Width property of Layout Element Component: In the following image 300 is the calculated width for the image:
As a result any images you add as child to the Content gameobject will increase their parent's width and also you will be able to scroll horizontally to view all the image.
p.s. I wrote this answer in a hurry. Hopefully it will make sense to you if not let me know and I will improve my answer.

How to set which view expands in a UIStackView?

I was just experimenting with UIStackView. In this quiz app i have different sized imaged, so i want the image to fill the space between the top button and the question text at the top. The buttons have constraints on them so they should be any size under 50px. As of now the top button is the one getting auto increased size, but that seems kinda random.
According to what I understand you have all the items inside a vertical UIstack. The images have different sizes so the available space for the buttons will changes based on the size of the image. I suggest that you add constraints to all buttons to be equal in height. This way they will re-size based on the available space but they will all have the same height.