diff --git a/src/main/scala/org/gerweck/scalafx/util/layout/Anchored.scala b/src/main/scala/org/gerweck/scalafx/util/layout/Anchored.scala new file mode 100644 index 0000000..dbe5413 --- /dev/null +++ b/src/main/scala/org/gerweck/scalafx/util/layout/Anchored.scala @@ -0,0 +1,24 @@ +package org.gerweck.scalafx.util.layout + +import scalafx.geometry.Insets +import scalafx.scene.control.MenuBar +import scalafx.scene.layout._ + +/** A wrapper that binds its child pane to all four corners so it will always + * grow as the stage is resized. + * + * This can be useful as the very top element of a [[scalafx.stage.Stage]] + * + * @author Sarah Gerweck + */ +object Anchored { + def apply(margins: Insets = Insets.Empty, menus: Option[MenuBar] = None)(body: => Pane) = { + new AnchorPane { ap => + hgrow = Priority.Always + vgrow = Priority.Always + private[this] lazy val innerPane = body + children = menus.toSeq :+ innerPane + AnchorPane.setAnchors(innerPane, margins.top, margins.right, margins.bottom, margins.left) + } + } +}