I have an app that uses a container as drop target.
When a label is released over the container, I would like the label to be automatically centered inside the container.
From what I have tried, setting a TableLayout with constraints for the container does not work and BoxLayout needs constraints defined before adding the component.
Is there any method to center the content of a container directly?
You can remove and re-add the component in the table layout but that can be "flaky" as it might go to the next row/column unless those are explicitly stated.
Two good approaches to center a component:
Container centered = BorderLayout.centerAbsolute(myCmp);
Or
Container centered = FlowLayout.encloseCenterMiddle(myCmp);
Using
Container centered = FlowLayout.encloseCenterMiddle();
with no arguments works in case you use the container as a drop target and don't know from the start what component will be released over it (my case).
Container centered = BorderLayout.centerAbsolute(myCmp);
requires you to define a component (myCmp).
Related
There exists legacy application having 3 canvas. First canvas to display objects which is stored in container, second canvas when object is selected and third one when object is moved or added for editing. I want to use the text and image feature of fabricJS into my existing application. While creating fabricJS canvas, i provided editing canvas object then all the mouse events bind to the editing canvas stopped working. So does there exists way to use fabricJS into existing application only for using the text and image feature of fabricJS.
You should be able to dynamically assign a z-index value to a canvas layer to expose or hide the layer to mouse events.
For the layers that you want to hide mouse events from, set z-index value to -1. For the layer that you want to expose to mouse events, set z-index value to 1.
var textLayer = document.getElementById("text-layer");
textLayer.style["z-index"] = 1;
Building UI in Godot 3.2.1. Of course I use anchors so UI elements are arranged within the screen automatically according to specified layout. I have UI scale system - nothing fancy - simply change font size (DynamicFont.size). If font size is large enough then some UI nodes may be pushed out of the screen. However, nodes don't return to normal sizes/positions with font size decreasing. The way to fix a mess is to resize game window which is not always an option and doesn't seem like a correct way to handle the issue. So how can I force Godot to recalculate control nodes size/position?
Changing the parent control's minimum size to Vector2(0, 0) after changing the font size might do the trick:
$Control.rect_min_size = Vector2(0, 0)
If it's already set to Vector2(0, 0), you may have to change it twice using call_deferred() for it to work.
In your scene tree, find the top level container that contains all of the elements that you want to recalculate. This would be the lowest common ancestor in the scene tree, in computer science terminology. Now, hide the container, by setting it's 'visible' property to false. Then, add a deferred call to change it's 'visible' property back to true.
var your_container = $".".find_node("your-container")
your_container.visible = false
your_container.call_deferred("set_visible", true)
This seems to cause Godot to recalculate the layout of 'your_container'.
It looks like only CanvasItem derived classes have a 'visible' property, so you would not be able to simply set the 'visible' property on a CanvasLayer, for example.
Fortunately, Containers and Controls both derive from CannvasItem, so this methodology should work fine if your lowest common ancestor node is either a Container or a Control or other CanvasItem derived class instance.
I got this working by emitting a signal from a parent element, which appears to force a refresh:
canvas_item.emit_signal("item_rect_changed")
The problem child got refreshed, and unlike the visibility method, focus was retained.
I would like to align a component initially relative to the visible part of the containing parent (Container). The containing parent is planned to be a scrollable Tabs page but only that component should be visible initially on the page when selecting the tab.
In my example I want to position a Container (variable: root) at the bottom of the visible area of its parent. My current approach is to get the height of root and the height of root.getParent() and then set its top-margin as: root.getUnselectedStyle().setMarginTop(parentsHeight - rootsHeight);, but the result is not as expected. How can I manage this?
check the illustrations below:
intention
result
Note: when I add the root component programmatically then my approach works!
finally I could detect the cause of the problem. The descirbed approach is correct, but I also had to pay attention for a specific point! Beneath the taps bar I have an additional component by default which gets hidden when initializing the containig form. Thus parentsHeight is lower than expected because I missed to revalidate the containing layout.
I have been trying to find an example or some hints on how to create an app that I could drag, resize, rotate images onto a UIView and then save the individual pieces (including their size, rotation and placement) and the entire UIView into CoreData. Kind of like the omnigraffle app.
Any tutorials, examples or anything on any piece of the app would be greatly appreciated.
for dragging a view
http://www.cocoacontrols.com/platforms/ios/controls/tkdragview
for roting a view http://www.cocoacontrols.com/platforms/ios/controls/ktonefingerrotationgesturerecognizer
for resizing a view
http://www.cocoacontrols.com/platforms/ios/controls/spuserresizableview
What respects to core data, its actually pretty straightforward just, gather the classes in one view, see the properties you need to save, and the new one you will need for your app and thats it.
Like:
Object Canvas containing a many relationship to morphlingViews wich contain all the properties as center, color, width, height, angle, UIPath (if you plan to create custom shapes) layer position (so it gets drawn correctly) and if you plan to connect the views as omnigraffle add a many realtionship to self (in morphlingViews) so you can take the center of different morphlingViews and add a simple line between them. (and a string if you plan to add drawInRect method to allow users to write in the objects, then it will be a good idea to add the text properties as well).
You can also add Quartz Composer drawing styles properties to the object, as shadow, shadowColor, shadowOffset, or add patterColor to add resizable background.
I want to place the components A and B over component with List. I need that would text of list will be to visible. I can not find which layout can do it.
How this behavior is in lwuit? What solutions exist?
The question is somewhat unclear, jmunoz answer is correct if you want component's A and B to reside at the bottom of the screen and the list to scroll above. However from the drawing it seems you want an "always on top" effect which you can achieve either via a glass pane (for non-interactive components) or via the LayeredLayout class.
This is actually quite simple using the following:
myForm.setLayout(new LayeredLayout());
myForm.setScrollable(false);
// will occupy the entire area of the form but should be scrollable
myForm.addComponent(componentUnderneath);
Container south = new Container(new BorderLayout());
myForm.addComponent(south);
south.addComponent(BorderLayout.SOUTH, whateverYouWantToPlaceOnTopInTheSouth);
You must do the following:
The Form must not do scroll. Use Form.setScrollable(false). Set the layout of the ´Form´ to BORDER_LAYOUT, myForm.setLayout(new BorderLayout()) . Ok in BorderLayoutyou can put the components in the Form as you want.
Put the Listcomponent in the center of the BorderLayout with myForm.addComponent(BorderLayout.CENTER, List) and the other two elements in the south of the layout using
Container southContainer = new Container();
southContainer.addComponent(A);
southContainer.addComponent(B);
myForm.addComponent(BorderLayout.SOUTH, southContainer)
With this you can get a scrollable Listand two elements always visible.