Created
January 20, 2010 04:05
-
-
Save bluepapa32/281591 to your computer and use it in GitHub Desktop.
How to use Panel Layout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.geometry.*; | |
import javafx.scene.*; | |
import javafx.scene.control.*; | |
import javafx.scene.layout.*; | |
import javafx.stage.*; | |
var panel: Panel; | |
var paddingTop = 5.0; | |
var paddingRight = 5.0; | |
var paddingBottom = 5.0; | |
var paddingLeft = 5.0; | |
Stage { | |
scene: Scene { | |
width: 100 | |
height: 100 | |
content: panel = Panel { | |
width: bind panel.scene.width | |
height: bind panel.scene.height | |
content: [ | |
Button { | |
text: "Prev" | |
layoutInfo: LayoutInfo { vpos: VPos.BOTTOM, hpos: HPos.LEFT } | |
} | |
Button { | |
text: "Home" | |
layoutInfo: LayoutInfo { vpos: VPos.BOTTOM, hpos: HPos.CENTER } | |
} | |
Button { | |
text: "Next" | |
layoutInfo: LayoutInfo { vpos: VPos.BOTTOM, hpos: HPos.RIGHT } | |
} | |
] | |
minWidth: function() { | |
var width = 0.0; | |
for (node in panel.content) { | |
width += node.boundsInLocal.width | |
} | |
return width; | |
} | |
onLayout: function(): Void { | |
if (panel.width <= 0.0) { return; } | |
if (panel.height <= 0.0) { return; } | |
var minWidth = panel.getMinWidth(); | |
var maxWidth = panel.getMaxWidth(); | |
var width = if (maxWidth < panel.width) { | |
maxWidth; | |
} else if (panel.width < minWidth) { | |
minWidth; | |
} else { | |
panel.width; | |
} | |
var height = panel.height; | |
for (node in panel.content) { | |
// ALIGN | |
var hpos = Container.getNodeHPos(node, HPos.LEFT); | |
node.layoutX = | |
if (hpos == HPos.CENTER) { | |
(width - node.layoutBounds.width | |
+ paddingLeft - paddingRight) / 2; | |
} else if (hpos == HPos.RIGHT) { | |
width - node.layoutBounds.width - paddingRight; | |
} else { | |
paddingLeft; | |
} | |
// VALIGN | |
var vpos = Container.getNodeVPos(node, VPos.TOP); | |
node.layoutY = | |
if (vpos == VPos.CENTER) { | |
(height - node.layoutBounds.height | |
+ paddingTop - paddingBottom) / 2; | |
} else if (vpos == VPos.BOTTOM) { | |
height - node.layoutBounds.height - paddingBottom; | |
} else { | |
paddingTop; | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment