Align a view to the right (appcelerator alloy) - appcelerator

I am trying to align the view to the right, I tried
right="0"
I tried getting the width on the controller and subtracting the view size and no succes
<View id="logoutAlignRightContainer" layout="horizontal" width="33%" heigh="40dp" right="0">
<View id="logoutAlignRight" left="" width="72dp" height="40dp" right="0">
<Label left="3" class="button" onClick="logoutEvent" width="Titanium.UI.SIZE">Log Out</Label>
</View>
I want to layout the $.logoutAlignRight to the right, but it stays at the left

You need to remove the layout=horizontal from logoutAlignRightContainer. By adding that you force the child view to layout starting from the left...

The answer for your question is Composite layout, please read the below basics:
There are three types of layout in Titanium (let's suppose there are 3 child views A, B, C):
composite (default) - It always keep all child views at its center position, and that's why you can always use any of the property like left, right, top, bottom.
So, A, B, and C will be at same center or on top of each other.
If you set only top and bottom, then it will only determine the height of view.
If you set only left and right, then it will only determine the width of view.
vertical - It aligns child views in a stack form, one below another. Still you can use left, right, top, bottom, but you will find setting left and right property easy, but top and bottom properties might not behave as you expect because top and bottom will behave in relation to the other child views.
So if you set left or right, view will be left/right aligned staying in accordance with the stack form.
If you set both left and right, then it will be the width of view.
If you set top, then it will be counted from the parent's top edge.
If you set bottom, then there will be bottom space of same value but the child view will still be there at the top or at the corresponding position in the stack.
horizontal - Aligns views from left to right.
If you set left, it will add space to the left edge of view.
If you set right, it will add space to the right edge of view still keeping the view aligned from left, so its useful when you want to set the width of view in horizontal layout.
You should try these layout basics so that you can save your valuable hours in further development and soon you will be able to design efficiently. Titanium Docs are of great help.

Related

How to ensure NSOutlineView inside a custom view renders full height (without scrolling)

I have a window with two custom views stacked on top of each other. I use auto layout constraints, as follows:
Top view leading, top, and trailing edges are tied to superview.
Bottom view leading, bottom, and trailing edges are tied to superview.
There is a fixed vertical space constraint between two views.
Bottom view has a fixed height constraint.
Top view has a it's compression resistance set to 751.
So far so good. The idea is that the bottom view height is fixed and as the window is resized, the top view height adjusts to compensate.
Both top and bottom views have other views/controllers loaded in, as appropriate. The bottom view ends up containing an outline view with a half-dozen entries. I would like that outline view not to scroll. In other words, I would like to automatically adjust my bottom view fixed height constraint to match the height of the outline view required for it not to scroll.
Ideally, I'd prefer to solve this with auto layout without having to write code. But, if that's stretching beyond what auto layout can do, code help would be appreciated as well.

Superview not resizing with subviews

I have a window into which I horizontally add two subviews. Into each subview, I place a variable number of subviews made up of a vertical slider, a text field rotated 90 degrees and placed to the left of the slider and another textfield, placed just under the slider. The slider subview's constraints are done in code, the parent views are both done in IB. When I add more slider views to the left window than the subview can handle in its default size, it resizes horizontally and forces the window's content view (and window) to also resize horizontally. Great, that's just what I want. But if I add more slider subviews than can fit in the right subview, they just get squeezed together and the subview does not expand as the left. I layout the slider views using code with this category converted to support NSViews, instead of UIVews:
UIView+AutoLayout1: https://github.com/jrturton/UIView-Autolayout
The constraints for the left and right subviews are more or less the same. I can't figure out why the right view does not resize as the left view does.
Here is a link to a sample project that demonstrates the problem:
SliderTest
Some someone help me out with this?
Also, a secondary question as I think my slider view could use a little work:
When a view is rotated using setFrame(Center)Rotation, do the top, right, bottom and top edges remain along the same edges or do they reflect the new orientation of the rotated view?
Thanks
I found the problem. The constraint between the left view and right edge of the window was fixed at 233 instead of >= 233. I had this at some point in the past, as I was adjusting the constraints to achieve the desired behavior and just overlooked this one through the troubleshooting process.

Trying to understand Auto Layout

I'm trying to understand how to use Auto Layout but I haven't been able to wrap my head around how to accomplish something like this using it. I have an iPad ViewController with two subview views. I'd like the layout to work like in this representation but I'm not clear on which values to set. particularly the relationship between the two subviews:
The left view should be pinned to the superview's top, left and bottom edges (with your padding) It's right edge should be pinned to the right view's left edge.
The right view should be pinned to the superview's top, right and bottom edges (with your padding). It should have a width constraint with a constant value, which you would set to the appropriate number on rotation.
In IB, you'd create an outlet to the width constraint. In code, just assign it to a property as you create it.

Center an object between two objects with auto layout

I am laying out a calculator using Interface Builder and I ran into some issues with the layout of buttons.
I have 3 columns of number buttons, similar to most calculators, and I had no problem placing the left and right columns as the auto-layout feature of Xcode snapped them in the correct distance away from the edge of the window on the left and the operator buttons on the right; however, there was no automatic help for centering the middle column of buttons between those two.
I can eyeball it pretty well but I really prefer to have everything perfectly aligned. Is there any way to center a button between two other UI objects like this? here is a picture of the layout:
You can place all the buttons in their own View. Place the view where you want the buttons. Then you could align the left buttons to the left of the view, align the right buttons to the right of the view, and finally center the middle buttons. Then adjust your view you made accordingly. I did something very similar. Hope this helps.

NSScrollView with sticky top, left and bottom 'headers'

I'm trying to create a timeline control in Cocoa. This is what I am trying to achieve. It's basically a standard timeline design.
However, I don't know which approach to take. The problem lies with the top ruler, the left track list and the bottom audio waveform display. These three parts need to always be visible and 'stick' to the edges. The ruler and audio waveform should only scroll horizontally, while the track list on the left should only scroll vertically.
For the top ruler, NSRulerView seems appropriate since it's just a ruler.
For the left view and the bottom view I don't know which route to take. I've played with using a wide vertical NSRulerView for the track list. This works but creates additional problems. For example: the top ruler appears above the track list.
I've composed four options so far:
Forget NSRulerView and draw everything custom in the document view. This seems feasible but sidesteps built in NSRulerView functions. Also, I need to find a way to shorten the scrollbars so they don't overlap the side and top views.
Use NSRulerViews for the top and left side. The bottom side will then probably be drawn manually in the document view.
Place the left view outside the scrollview and manually scroll it up and down by linking it to the main scroll view. Use NSRulerView for the top, manually draw audio waveform in document view.
An NSScrollView embedded in another NSScrollView. The outer handles horizontal scrolling, the inner scroll view handles vertical scrolling. Possible I think, but it seems hacky.
So my question boils down to: Which route to take?. Can anyone shed some light on this issue and point me in the right direction?
What I understand:
You want a view to the left of an NSScrollView which scrolls vertically with the NSScrollView while ignoring horizontal scrolling.
You want a view below an NSScrollView which scrolls horizontally with the NSScrollView while ignoring vertical scrolling.
You want rulers.
To achieve this task:
Use 3 separate scroll views which do not overlap and donot inherit one another.
Activate rulers in whichever view(s) you would like them to appear.
Synchronize the scroll views (so that when one scrolls, the other scrolls accordingly).
How to synchronize scroll views is in the help. See User Experience > Controls > Scroll View Programming Guide for Mac > Synchronizing Scroll Views. This is also indirectly linked in the header of the help guide for NSScrollView.
If you want the three scroll views to be contained within an NSSplitView for resizing simplicity, then a fourth view must be added to consume the unused corner (good place to put controls). Since an NSSplitView can only be split vertically or horizontally, you will have to create an NSSplitView containing 2 split views with each of those split views containing 2 views that you actually see (splitting in one direction and then the other). The resizing of the split views will have to be synchronized in a manner much like the scrolling is synchronized to retain a straight cross of all four views.

Resources