Stacked UI elements: how to have only the visible ones to respond to click - unity3d

I have 3 dropdown that are stacked on top of each other; I use canvas group to make the non relevant ones invisible; although the click is intercepted only on the topmost control.
How do you work around this? Should I keep track of the position in the hierarchy and swap it when I need to have a specific dropdown control so I can use it? Feels like a lot of work...hopefully is there an easier way?

The image component of UI elements has a Raycast Target property that you can set to false. This will make them unclickable.

Related

How do you sort UI elements in Canvas?

I don't get how you sort UI elements Z-index in Unity inside a Canvas, is it by hierarchy order ?
I'm trying to do a settings screen like in this video: https://www.youtube.com/watch?v=-qNo1jloR_k
It's quite simple, you click on the button and it set the whole panel as first sibling in the hierarchy.
But this is what I get:
https://gyazo.com/cec14f21df2ded191875e6a8cfd9f124
Also, my gameplay panel had a red background, my graphics panel a green one, and my sound panel a yellow one.
I could avoid this problem by changing alpha on panels, but would like to make it work with z sorting... that I can't seem to understand on Unity.
Using unity 2017.1.2 and .NET 4.6 .
The child that is lower in the hierarchy is rendered on top of other ones.
Let's say there are 2 panels. panel1(red) and panel2(green).If the hierarchy is like this:
-panel1
-panel2
Then panel2 will be rendered on top of panel1. So, you'll see green panel.
Hope this answers your question.
Another suggestion, it is better to deactivate the unused panels and activate only the used panels. Because, if the unused panel is active, when it's not shown, it'll still take the processing power which is a waste. For example, if you have animation in the main menu, but currently you are showing the settings panel, your approach will keep the animations running in the main menu.

How to implement a 'dynamic' drag and drop (like iOS/Android)?

I would like to implement a 'dynamic' drag and drop in a list. By 'dynamic' I mean that in the list in which the drag is happening, there's an empty space below the dragged element which 'follows it' as you drag through the list (to make it visually obvious where the dropped element will end up in the list). Like what you see in iOS/Android apps supporting D&D.
What I've tried is to use Component.dragEnter to insert an empty Component with the size of the dragged element below the dragged compoment. And as the drag moves through the list, remove the old Component and insert a new one in the new position (explanation of why I create a new Component in next paragraph). However, with the dynamic updates that CN1 does while dragging, and my own updates when moving the empty Component, I just cannot find a way to make it work so I get the right vusual behavior. One aspect making this more complex than you'd think at first is that CN1's built-in support for drag&drop makes the original dragged component invisible with setVisible(false) which means it leaves an empty space behind.
The reason I recreate a new empty Component is because the final drop() will happen on the empty Component, and my trick to make this work is to override drop() on the empty Component to call drop on the dropTarget that is (was) in the Component's position.
All in all, I've spend I don't know how many days trying to get this to work with no success so far. Let me know if anyone has a suggestion for a more straightforward approach?
Big thanks in advance!
The builtin support hides the original component but drags an image of it which you can customize by overriding getDragImage().
You can use custom code to highlight the drop location by using a drag over listener which you can accomplish by using addDragOverListener(ActionListener).

Application Menu on top of Leaflet map

In a map application based on Leaflet, I would like to have a large application menu, kind of a settings menu. I managed to put a nice button into the top right corner as a L.Control and it gets fired on a click.
The menu should position either to the left of the menu button or simply in the middle of the screen.
I am wondering whether it is best practice to use
a Popup,
a Layer,
another Control or
just position a at the right place on the page.
Trying the latter, I found that I have to set z-index to a very high value to see it, and it feels a bit odd not to use the Leafleat features.
What would be the "right" solution to use with Leaflet?
If you want a full screen map, you can use https://github.com/Turbo87/leaflet-sidebar
I use it here: http://franceimage.github.io/map
You can create a nice customized icons based toolbar using Leaflet easybutton plugin.
You will have all the leaflet based controls (Click, hover, position etc.) to set that up as per your requirements.
Here are the implementation examples:
http://danielmontague.com/projects/easyButton.js/v1/examples/
and github repo: https://github.com/CliffCloud/Leaflet.EasyButton

XCode 4 Interface Builder: A better way to work with lots of overlapping views

In IB I have quite a few views that are shown. Many of them are hidden when the app loads, but are shown later when buttons are pressed. This is all fine, but when building this layout in IB it is extremely difficult to layout anything because there are so many overlapping views, some of which are partially transparent (ones that are set to hidden) and other are completely overlapping and covering others. This makes layout very hard.
What is the best method when laying out lots of views like this? Is there another way to break things up? Or better yet, can I hide a a view completely (like in photoshop) so that I can edit the ones underneath, then turn that layer back on?
Another option when trying to select a view that is obscured by another is the shortcut:
'ctrl' + 'shift' and click
It displays a list of all the views under the cursor.
I'm not aware of any way to hide objects in the canvas, but a useful trick for complex layouts is to double-click an item in the document tree to the left - this selects the item and puts focus on the canvas, you can the use the cursor keys to nudge it about.
This doesnt solve the problem of not being able to see things because there are, for example, five or six labels occupying the same space, but if that is the situation it may be a better idea to have a single label and change its contents in code.
I ran into this issue for an app I'm building that has an arial-view image of a park with clickable hotspots. When a hotspot is clicked a popup UIview is displayed with information about that spot in the park. I use the same VC/XIB for three parks. This makes the XIB really busy and hard to work with (i.e the same issue that you have) The detail UIViews make it hard to work with the views underneath. My workaround was to pick each detailed UIView that was hiding the part of the XIB I wanted to work on, and add 1000 to the UIView origin.x in the size inspector. This moved those UIViews enough out of the way for me to do what I needed to with the XIB. Then when I was done, I moved them back by x 1000. (I just needed to move them out horizontally to do what I needed to)
I know its clunky but given that XCode does not have a convenient way to hide portions of an XIB - it was the quickest approach I could think of!
One approach to handling overlapping items in IB is:
Ensure the groups of items that you want to hide are grouped into Views.
Give these Views names: e.g. ViewOptionA, ViewOptionB and ViewOptionC.
Can do this by clicking on name of view in the tree while it is selected and then typing new name.
When you want to hide one of those groups of items:
a) Select the View by either:
i) Clicking on it in the tree at the left or
ii) Ctrl-Shift Clicking in the layout editor and then select the view from the list.
b) In the Attributes Inspector set Alpha to 0.
When you want to unhide one of those groups of items:
As for 2) but set Alpha back to 1
[You do need to remember to unhide all views before you publish!
If you are forgetful like me then perhaps you could subclass UIView and set Alpha to 1. I haven't tried this subclassing idea yet.]

iPhone panel control

In my iPad application there are many buttons (around 50), and I want to make a group box which contain buttons arranged by category.
I am looking for something like a C# or .NET GroupBox/Panel.
There is no Group Box / Panel Box in iPhone.
You need to manage by your self.
Use the UITableView to put all the button in on category.
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UITableView_Class/Reference/Reference.html
It may be worthwhile to look into UIPopoverController views. These are the little popup views that appear when you click stuff. YOu could easily break your menu system into smaller parts with these.
You may draw a group panel by making two views. make a view of frame say 20,20,280,199 and then another one with frame 21,21,278,197. now put the 2nd view on the last one and change the color of last to some dark than later one. enjoy :)
remember that the should be in same hierarchy. that no one should be parent or child of any of these.