Layout class that draws a box around controls that it positions and sizes automatically.
// BorderBoxLayout is a BoxLayout that draws a labelled frame around its
// contents -- the group box from settings dialogs. The only difference
// is the constructor:
//
// new BorderBoxLayout(orientation, text)
//
// Leave the text off for an unlabelled frame; leave both off and the
// orientation defaults to Layout.Horizontal.
class MyForm extends Form {
server = null;
use_ssl = null;
advanced = null;
main = null;
shown = true;
constructor() {
super("BorderBoxLayout Example", 100, 100, 380, 280);
this.server = new TextBox("localhost", 0, 0, 100, 22);
this.use_ssl = new CheckBox("Use SSL", 0, 0, 150, 20);
this.use_ssl.setValue(true);
// a row inside a group is an ordinary nested BoxLayout
const row = new BoxLayout(Layout.Horizontal);
row.add(new Label("Server:", 0, 0, 50, 18), 0, Layout.Center, 0);
row.add(this.server, 1, Layout.Center, 0);
const connection = new BorderBoxLayout(Layout.Vertical, "Connection");
connection.add(row, 0, Layout.Expand | Layout.All, 6);
this.advanced = new BorderBoxLayout(Layout.Vertical, "Advanced");
this.advanced.add(this.use_ssl, 0, Layout.Left | Layout.All, 6);
const button = new Button("Hide Advanced", 0, 0, 120, 24);
button.click.connect(this, this.onToggle);
this.main = new BoxLayout(Layout.Vertical);
this.main.add(connection, 0, Layout.Expand | Layout.All, 8);
this.main.add(this.advanced, 0, Layout.Expand | Layout.All, 8);
this.main.addStretchSpacer();
this.main.add(button, 0, Layout.Center | Layout.All, 8);
this.setLayout(this.main);
}
onToggle(sender, event_args) {
this.shown = !this.shown;
// show() is inherited from Layout, so frame, caption and
// contents all disappear together
this.main.show(this.advanced, this.shown);
this.main.layout();
sender.setLabel(this.shown ? "Hide Advanced" : "Show Advanced");
}
}
const form = new MyForm();
form.show();
Application.run();