I’m taking a break from Carpe Diem development to explore using jME on another, non-game, project of mine. After tooling around with Lemur for a bit I recreated two of my favorite JavaFX layouts for it. Since these simple layouts can be nested to meet a variety of needs I figured I’d post’em for all the Lemur fans out there.
The VBoxLayout and HBoxLayout mimic JavaFX’s VBox and HBox respectively. Items are laid out vertically, VBoxLayout, or horizontally, HBoxLayout, with optional space between each element. Individual elements can be instructed to fill any remaining width, VBox, or height, HBox, or remain their original size. Individual elements that do not fill remaining space can be aligned left, center or right for VBox and top, center or bottom for HBox.
You can also set the fill mode to define how elements are sized to fill, or not fill, remaining space vertically, VBox, or horizontally, HBox, using the same FillMode enum used by SpringGridLayout. None does not resize the elements, unless they need to shrink because the V/HBox is not big enough, Even distributes the remaininig space evenly, ForcedEven forces all elements to be the same height(VBox) or width(HBox), proportional distributes remaining space according to each elements proportional size, First grows the first element only and last grows only the last element.
HBoxLayout: HBoxLayout.java - Google Drive
VBoxLayout: VBoxLayout.java - Google Drive
A quick example:
//Create the top level container using VBoxLayout so our children
//are arranged vertically. The last child will stretch to fill the
//extra space, there’s no spacing between children.
Container screen = new Container(new VBoxLayout(0, FillMode.Last)); screen.setLocalTranslation(0, 450, 0); screen.setPreferredSize(new Vector3f(800, 450, 1)); guiNode.attachChild(screen); //The top Container to hold some menu buttons or something. //Arranged horizontally with 5 pixels between each element. Container top = new Container(new HBoxLayout(5)); top.addChild(new Button("File")); top.addChild(new Button("Edit")); top.addChild(new Button("View")); top.addChild(new Button("Tools")); top.addChild(new Button("Help")); //The bottom right side container to hold who knows what. //Arranged vertically with 5 pixels between each element. Container right = new Container(new VBoxLayout(5)); right.addChild(new Label("Label")); right.addChild(new Button("Click Me")); //Add our top container to the root container and make sure //it fills the remaining available width by supplying true. screen.addChild(top, true); //Add our bottom right container, make sure it is right //aligned and does not fill any remaining width. screen.addChild(right, VBoxLayout.HAlign.Right, false);