I want to use expression blend to snap an element to the halfway line of another object.
Expression Blend only seems to let you snap elements to each others edges.
I'd even like to snap the centre of an object to the centre of a grid also.
I don't think you can do exactly what you want, but Blend has additional snapping support:
1) You can turn on the "snap grid" and enable "snap to grid lines". These are in the lower left corner of the Artboard.
2) The settings for snapping are in Window > Options > Artboard
3) As for snapping to the center, unless these grid lines line up just so, you'l have to use the HorizontalAlignment and VerticalAlignment properties to center the object in the Grid. You can, however, align objects by their centers.
Select the two objects and use the right click > Align context menu to select the alignment type. Vertical Centers then Horizontal centers will center the two objects in relation to one another.
You can snap to gridlines in Blend -- there are options you can set from the Tools menu, and there's a toggle button at the bottom of the drawing area that says "Show snap grid". You'll also have to toggle the "Snap to grid lines" button.
As for snapping to the center of a grid, you shouldn't be doing that with snapping. Set the vertical and horizontal position to Center.
Related
When a joint (hinge joint or configurable joint) is used in Unity the anchor is represented by a brown arrow icon in the Unity Scene window.
It is way too small. I want to enlarge it to see it easier. Is this possible, how?
For positioning purposes, I've found a solution: Clicking on "Edit Joint Angular Limits" (Unity 2017.3+ I guess) displays a circle that represents the angular limit. This circle is centered on the anchor, naturally. So it helps locating and positioning the anchor.
I want to make a controller button prompt in my game where it says 'Press X to Join', but I want the X to be an actual graphic of the 'X' button, like how it is in many games. How would I go about doing that? Right now I'm just putting a big space in my prompt text and putting a UI Image of the button in it, but I want to know if there's a better way about it.
For the sake of scaling to different resolution sizes, you would wanna scale the anchors of the UI elements correctly and have an appropriate parent-child relation tree in Unity's hierarchy.
The red box is the hierarchy.
The 2 green boxes shows ways of scaling the anchors.
The orange box shows the end result of it.
Anchors in combination with their relative position, allows Unity's UI elements to scale up and down according to screen size.
So for example if you say that an anchor is at 0.25x, that would be that its anchored at 25% of for example the x axis. Same goes if you set it for the y axis, just the vertical instead of horizontal anchoring.
You can use the anchors to adjust a minimum and a maximum anchor which the elements may float within, they may have the same value as well, then it's a fixed anchor point.
To clarify, I suggest that you use a panel to hold 2 text elements and the image with the X, each text element being on the left and right side of the X instead of having spacing inside the UI text elements. To keep correct spacing you then must use anchor points. This way your spacing stays correct despite changing screen and resolution sizes.
Please note that the "left", "top", "right" and "bottom" values are then relative to the anchor points. So if you move "left" 5 pixels, those 5 pixels will be out from the relative anchor point.
Here's the values I used:
My left text is at 0.25x, right text is at 0.8x, image is at 0.5x.
The panel holding the 3 is at 0.2 minimum x to 0.8 max x, same goes for y axis.
The largest parent panel is stretched to max fit in the canvas.
I'm using auto layout in Xcode and I have some buttons I want to be near the center, but not on it. I know I can use alignment constraints to be exactly in the center, in this menu:
However, I want to not be exactly in the center, lets say 50 pixels up and to the right. How can I do this? I'm sure it's an easy thing to do, but I can't seem to find anything elsewhere on the web.
If you want the center of your button to be 50 points up and to the right of the parent view's center you can use a center x alignment constraint and a center y alignment constraint and set the center x alignment constraint's constant to 50 and the center y alignment constraint's constant to -50.
Create a view with size 50 * 50. Then place this view exactly at the center using auto layout.
Next you need to place your button using vertical space and horizontal space in order to be aligned to the upper right corner of the view.
Finally make the view transparent.
Can anyone explain what is the difference between Frame Rectangle and Alignment Rectangle in the size inspector?
Frames describe where to place views on the screen and how big those views will be. When laying out views, constraints use a related geometric element called an alignment rectangle.
The alignment rectangle is based on the presentation of the item’s content, Auto Layout uses the alignment rectangle instead of the item’s frame rectangle.
By working with alignment rectangles instead of frames, Auto Layout ensures that key information like a view’s edges and center are properly considered during layout.
Unlike frames, a view’s alignment rectangle should be limited to a core visual element. Its size should remain unaffected as new items are drawn onto the view.
Consider the left side of Figure -1. It shows a view drawn with a shadow and a badge. When laying out this view, you want Auto Layout to focus on aligning just the core element—the blue rectangle—and not the ornamentation.
Figure - 1 : A view’s alignment rectangle (center) refers strictly to the core visual element to be aligned, without embellishments.
The center image in Figure -1 highlights the view’s alignment rectangle. This rectangle excludes all ornamentation, such as the drop shadow and badge. It’s the part of the view you want Auto Layout to consider when it does its work.
The right-hand rectangle in Figure -1 encompasses all the view’s visual elements. It encompasses the shadow and badge. These ornaments could potentially throw off a view’s alignment features (like center, bottom, and right) if they were considered during layout.
Figure -2 Auto Layout only considers this view’s alignment rectangle when laying it out as centered in its superview. The shadow and badge don’t affect its placement.
Reference: link
From Apple's old Auto Layout Guide:
Layout Operates on Alignment Rectangles, Not on Frames
When considering layout, keep in mind that the frame of a control is
less important than its visual extent. As a result, ornaments such as
shadows and engraving lines should typically be ignored for the
purposes of layout. Interface Builder ignores them when positioning
views on the canvas—in the following example, the Aqua guide (the
dashed blue line) aligns with the visual extent of the button, not
with the button’s frame (the solid blue rectangle).
To allow layout based on the presentation of the content rather than
the frame, views provide an alignment rectangle, which is what the
layout actually operates on. To determine whether your override is
correct on OS X, you can set the NSViewShowAlignmentRects default to
YES to draw the alignment rects.
So, that pop-up menu in Xcode is providing you the ability to view and edit a view's size and position based on its alignment rect or its frame rectangle.
Is there a way (API) of getting the size (vertical and horizontal) in pixels of the resize corners?
I am referring to the area at each of the corners of a window where you can resize the window in both directions (Left-to-Right and Top-to-Bottom) at the same time using your mouse. You will know you are there with your mouse cursor when you hover over the corners of the window and the mouse cursor is a Diagonal Resizing cursor.
Thank you
Edit:
An example: Hover your mouse over the right edge of a sizable window. Start in the middle (vertically) of the window and move the mouse up along the edge until the horizontal sizing cursor changes to a diagonal sizing cursor. How do I determine by asking the OS how far that position when the cursor changes, is from the top of the window.
I would suggest to use the size of the scrollbars. Call GetSystemMetrics with SM_CYHSCROLL and SM_CXVSCROLL. May be also SM_CYSIZEFRAME and SM_CXSIZEFRAME sizes can be combined.
But I think a better value is to use the height of the status bar. However even Microsoft Windows seems to use some fixed value as can seen on the screenshot.
Comparing the results of GetClientRect and GetWindowRect will tell you how wide the non-client (border) area is along each edge of the window.
If you're concerned that it might not all be active for sizing (true especially along the top), or you want to distinguish the diagonal sizing areas from edge sizing areas, you can take the coordinates discovered in step 1 and pass them to SendMessage(WM_NCHITTEST) See its documentation for the various return codes. There's no problem sending this message repeatedly -- it's designed to be called for each mouse move event and therefore is very fast.