Skip to content

Commit cd0e294

Browse files
authored
Add a document detailing the layout system (#1232)
1 parent 8c17269 commit cd0e294

8 files changed

Lines changed: 198 additions & 112 deletions

File tree

docs/docs/config.mdx

Lines changed: 112 additions & 112 deletions
Large diffs are not rendered by default.
206 KB
Loading

docs/docs/img/drag-edge.png

717 KB
Loading

docs/docs/img/drag-swap.png

709 KB
Loading

docs/docs/img/node-resize.png

299 KB
Loading

docs/docs/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ References:
2626
- [Key Bindings](./keybindings)
2727
- [wsh command](./wsh)
2828
- [Connections](./connections)
29+
- [Tab Layout System](./layout)
2930
- [Custom Widgets](./customwidgets)
3031
- [Telemetry](./telemetry)
3132
- [FAQ](./faq)

docs/docs/layout.mdx

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
sidebar_position: 2
3+
id: "layout"
4+
title: "Tab Layout System"
5+
---
6+
7+
import { PlatformProvider, PlatformToggleButton } from "@site/src/components/platformcontext.tsx";
8+
import { Kbd } from "@site/src/components/kbd.tsx";
9+
10+
<PlatformProvider>
11+
<PlatformToggleButton/>
12+
13+
![screenshot showing a block being dragged over another block, with the placeholder depicting a out-of-line before outer drop](./img/drag-edge.png)
14+
15+
## Layout system under the hood
16+
17+
:::info
18+
19+
**Definitions**
20+
21+
- Layout tree: the in-memory representation of a tab layout, comprised of nodes
22+
- Node: An entry in the layout tree, either a single block (a leaf) or an ordered list of nodes. Defines a tiling direction (row or column) and a unitless size
23+
- Block: The contents of a leaf in the layout tree, defines what contents is displayed at the given layout location
24+
25+
:::
26+
27+
Our layout system emulates the [CSS Flexbox](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_flexible_box_layout/Basic_concepts_of_flexbox) system, comprising of a tree of columns and rows. Under the hood, the layout is represented as an n-tree, where each node in the tree is either a single block, or a list of nodes. Each level in the tree alternates the direction in which it tiles (level 1 tiles as a row, level 2 as a column, level 3 as a row, etc.).
28+
29+
## Layout actions
30+
31+
### Add a new block
32+
33+
You can add new blocks by selecting a widget from the right sidebar.
34+
35+
Starting at the topmost level of the tree, since the first level tiles as a row, new blocks will be added to the right side of existing blocks. Once there are 5 blocks across, new blocks will begin being added below existing blocks, starting from the right side and working to the left. As a new block gets added below an existing one, the node containing the existing block is converted from a single-block node to a list node and the existing block definition is moved one level deeper in the tree as the first element of the node list. New blocks will always be added to the last-available node in the deepest level, where available is defined as having less than five children. We don't set a limit on the number of blocks in a tab, but you may experience degraded performance past around 25 blocks.
36+
37+
While we define a 5-child limit for each node in the tree when automatically placing new blocks, there is no actual limit to the number of children a node can hold. After the block is placed, you are free to move it wherever in the layout
38+
39+
### Delete a block
40+
41+
You can delete blocks by clicking the <i className="fa-sharp fa-xmark-large"/> button in the top-right corner of the block, by right-clicking on the block header and selecting "Close Block" from the context menu, or by running the [`wsh deleteblock` command](./wsh#deleteblock). Alternatively, the currently focused block/widget can be closed by pressing <Kbd k="Cmd:w"/>
42+
43+
When you delete a block, the layout tree will be automatically adjusted to minimize the tree depth.
44+
45+
### Move a block
46+
47+
You can move blocks by clicking on the block header and dragging the block around the tab. You will see placeholders appear to show where the block will land when you drop it.
48+
49+
There are 7 different drop targets for any given block. A block is divided into quadrants along its diagonals. If the block is tiling as a row (left-to-right), dropping a block into the left or right quadrant will place the dropped block in the same level as the targeted block. This can be considered dropping the block inline. If you drop the block out of line (in quadrants corresponding to opposite tiling direction), the block will either be placed one level above or one level below the targeted block. Dropping the block towards the outside will place it in the same level as the target block's parent, while dropping it towards the center of the block will create a new level, where both the target block and the dropped block will be moved. The middle fifth of the block is reserved for the swap action. Dropping a block here will cause the target block and the dropped block to swap positions in the layout.
50+
51+
![screenshot showing a block being dragged over another block, with the placeholder depicting a swap movement](./img/drag-swap.png)
52+
53+
#### Possible block movements
54+
55+
:::note
56+
All block movements except for Swap will cause the rest of the layout to shift to accommodate the block's new displacement.
57+
:::
58+
59+
![annotated example showing the drop targets within a block](./img/block-drag-example.jpg)
60+
61+
1. Inline before: Drops the block under the same node as the target block, placing it before the target in the same tiling direction
62+
2. Inline after: Drops the block under the same node as the target block, placing it after the target in the same tiling direction
63+
3. Out-of-line before outer: Drops the block before the target block's parent node in the opposite tiling direction
64+
4. Out-of-line before inner: Segments the target block, creating a new node in the tree. Places the dropped block before the target block in the opposite tiling direction.
65+
5. Out-of-line after inner: Segments the target block, creating a new node in the tree. Places the dropped block after the target block in the opposite tiling direction.
66+
6. Out-of-line after outer: Drops the block after the target block's parent node in the opposite tiling direction
67+
7. Swap: Swaps the position of the dropped block and the targeted block in the layout, preserving the rest of the layout
68+
69+
### Resize a block
70+
71+
![screenshot showing the line that appears when the cursor hovers over the margin of a block, indicating which blocks will be resized by dragging the margin](./img/node-resize.png)
72+
73+
You do not directly resize a block. Rather, you resize the nodes containing the blocks. If you hover your mouse over the margin of a block, you will see the cursor change to <i className="fa-sharp fa-arrows-left-right"/> or <i className="fa-sharp fa-arrows-up-down"/> to indicate the direction the node can be resized. You will also see a line appear after 500ms to show you how many blocks will be resized by moving that margin. Clicking and dragging on this margin will cause the block(s) to get resized.
74+
75+
Node sizes are unitless values. The ratio of all node sizes at a given tree level determines the displacement of each node. If you move a block and its node is deleted, the other nodes at the given tree level will adjust their sizes to account for the new size ratio.
76+
77+
## Change the gap size between blocks
78+
79+
The gap between blocks defaults to 3px, but this value can be changed by modifying the `window:tilegapsize` configuration value. See [Configuration](./config) for more information on how to change configuration values.
80+
81+
</PlatformProvider>

docs/docs/widgets.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ Magnifying a widget will pop the widget out in front of everything else. You can
3535

3636
By dragging and dropping their headers, widgets can be moved to different locations in the layout. This effectively allows you to reorganize your screen however you see fit. When dragging, you will see a preview of the widget that is being dragged. When the widget is over a valid drop point, the area where it would be moved to will turn green. Releasing the click will place the widget there and reflow the other widgets around it. If you see a green box cover half of two different widgets, the drop will place the widget between the two. If you see the green box cover half of one widget at the edge of the screen, the widget will be placed between that widget and the edge of the screen. If you see the green box cover one widget entirely, the two widgets will swap locations.
3737

38+
See [Tab Layout System](./layout#move-a-block) for more information.
39+
3840
### How to Resize Widgets
3941

4042
Hovering the mouse between two widgets changes your cursor to <i className="fa-sharp fa-arrows-left-right"/> or <i className="fa-sharp fa-arrows-up-down"/>; and reveals a green line dividing the widgets. By dragging and dropping this green line, you are able to resize the widgets adjacent to it.
4143

44+
See [Tab Layout System](./layout#resize-a-block) for more information.
45+
4246
## Types of Widgets
4347

4448
### Term

0 commit comments

Comments
 (0)