x4js gallery

HSplitBox

Panels side by side that the user resizes by dragging the line between them; VSplitBox stacks them. The sizers they put between their panels can also be placed by hand.

import { HSplitBox, VSplitBox, HSizer, CSizer } from "x4js"

Side by side

A sizer is put between the panels: it resizes the panel that is not flex, the flex one takes the rest.

export function sideBySide( ) {
	return new HSplitBox( { cls: "panes", height: 200, content: [
		new VBox( { width: 200, content: new SimpleText( { text: "200px at first: drag the line on my right." } ) } ),
		new VBox( { flex: 1, content: new SimpleText( { text: "flex: the rest of the width." } ) } ),
	] } );
}
.panes {
	border: 1px solid var( --border );
	overflow: hidden;		// nothing of a panel drawn out of the box

	// a panel made narrower than its text: the text is cut at its edge, not drawn over its neighbour
	> .x4vbox, .x4vsplitbox > .x4vbox {
		padding: 8px;
		background: var( --background-ternary );
		overflow: hidden;
	}

	.x4csizer {
		background: var( --border );
	}
}

VSplitBox

The same, stacked: the sizer changes the height of the panel that is not flex.

export function stacked( ) {
	return new VSplitBox( { cls: "panes", height: 260, content: [
		new VBox( { flex: 1, content: new SimpleText( { text: "flex: the rest of the height." } ) } ),
		new VBox( { height: 90, content: new SimpleText( { text: "90px at first: drag the line above me." } ) } ),
	] } );
}

Nested

A VSplitBox in a HSplitBox: the layout of an editor, a tree on the left, a log at the bottom.

export function nested( ) {
	return new HSplitBox( { cls: "panes", height: 260, content: [
		new VBox( { width: 160, content: new SimpleText( { text: "Files" } ) } ),
		new VSplitBox( { flex: 1, content: [
			new VBox( { flex: 1, content: new SimpleText( { text: "Editor" } ) } ),
			new VBox( { height: 70, content: new SimpleText( { text: "Log" } ) } ),
		] } ),
		new VBox( { width: 140, content: new SimpleText( { text: "Outline" } ) } ),
	] } );
}

HSizer by hand

In any HBox, a sizer you put between two children: HSizer( "before" ) resizes the one before it, HSizer( "after" ) the one after it; the flex one takes the rest. A SplitBox puts them for you.

export function bySizer( ) {
	return new HBox( { cls: "panes", height: 120, content: [
		new VBox( { width: 180, content: new SimpleText( { text: "HSizer( \"before\" ), on my right, resizes me." } ) } ),
		new HSizer( "before" ),
		new VBox( { flex: 1, content: new SimpleText( { text: "flex: the rest." } ) } ),
		new HSizer( "after" ),
		new VBox( { width: 180, content: new SimpleText( { text: "HSizer( \"after\" ), on my left, resizes me." } ) } ),
	] } );
}

Edges

A CSizer on the edge of a box resizes the box; its resize event gives the new size.

export function edges( ) {
	const size = new Label( { text: "Drag the right edge or the corner." } );
	const right = new CSizer( "right" );
	const corner = new CSizer( "bottom-right" );

	right.on( "resize", ( ev ) => size.setText( `${ev.width} x ${ev.height}` ) );
	corner.on( "resize", ( ev ) => size.setText( `${ev.width} x ${ev.height}` ) );

	return new VBox( { height: 220, content: [
		new VBox( { cls: "resizable", width: 240, height: 120, content: [ size, right, corner ] } ),
	] } );
}
.resizable {
	padding: 8px;
	border: 1px solid var( --border );
	background: var( --background-ternary );

	> .x4csizer:hover {
		background: var( --accent-background );
	}
}

For an assistant: llms.txt, llms-full.txt.