# web/pane (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/web/pane/

Screen split pane. (PaneTheme, PaneStyle, Pane of the original web/pane.js)
- The original builds the window layout of tools (such as the particle editor) with the DOM. Panes split horizontally or vertically, fixed, ratio and flex sizes, minimum and maximum, resizers that change size by dragging,
  hiding, clearing dragged sizes, layout callbacks, and PaneStyle presets (panel, toolbar, button, input, textarea, text) that build elements with the same theme colors.
- The web builds them with DOM elements as in the original. (pane/dompane.rs)
- Desktop has no DOM, so engine nodes do the same work. Containers are nodes and contents are their child nodes. Resizers are draggable nodes drawn with theme colors. (pane/nodepane.rs)
- Size calculation (calculate_pane_layout) and drag calculation (calculate_resized_size) use the same functions on both platforms. (the original updateLayout, onMouseMove)
- Differences from the original:
  - PaneTheme is associated constants that flatten the original groups (color, size, font) with name prefixes. (PaneTheme.color.background → PaneTheme::COLOR_BACKGROUND,
    PaneTheme.size.resizer → PaneTheme::SIZE_RESIZER, PaneTheme.font.sizeSmall → PaneTheme::FONT_SIZE_SMALL)
    Abbreviated names were spelled out. (color.inputBg → COLOR_INPUT_BACKGROUND, font.mono → FONT_MONOSPACE) SIZE_RESIZER is a pixel count (f64).
  - Pane options are PaneOptions. Sizes are PaneSize. (Flex, Fixed(pixels), Ratio(0~1 ratio))
    The original reads a single number: 0 or "flex" as flex, 1 or less as a ratio, above 1 as pixels. ("50%" is Ratio(0.5)) So get_initial_size returns a PaneSize.
  - PaneStyle::create options are PaneStyleOptions. Empty strings are not applied, like empty values in the original. The original options.type is element_type. (type is a Rust reserved word)

## PaneResizeCallback (type)

Callback called when the pane sizes are laid out again. (original setCallback)

```rust
pub type PaneResizeCallback = Box<dyn FnMut()>
```

## PaneTheme (struct)

Theme constants. (original PaneTheme)

Example: Building a border style string from a theme color (the bottom border of the original toolbar preset)

```rust
use vanilla::{Color, PaneTheme};

let border_bottom = format!("1px solid {}", PaneTheme::COLOR_BORDER);
assert_eq!(border_bottom, "1px solid #444");
assert_eq!(Color::from(PaneTheme::COLOR_PANEL), Color::from("#252526"));
assert_eq!(PaneTheme::SIZE_RESIZER, 5.0);
assert_eq!(PaneTheme::FONT_SIZE, "13px");
```

- `pub const COLOR_BACKGROUND: &'static str = "#1e1e1e"` (static, since 0.4.0): Background color. (original color.background, background of the pane container and the textarea preset)
  - returns &'static str
- `pub const COLOR_PANEL: &'static str = "#252526"` (static, since 0.4.0): Background color of the panel preset. (original color.panel)
  - returns &'static str
- `pub const COLOR_TOOLBAR: &'static str = "#2d2d30"` (static, since 0.4.0): Background color of the toolbar preset. (original color.toolbar)
  - returns &'static str
- `pub const COLOR_BORDER: &'static str = "#444"` (static, since 0.4.0): Border color. (original color.border, bottom border of the toolbar preset)
  - returns &'static str
- `pub const COLOR_TEXT: &'static str = "#ccc"` (static, since 0.4.0): Text color. (original color.text)
  - returns &'static str
- `pub const COLOR_TEXT_DIM: &'static str = "#aaaaaa"` (static, since 0.4.0): Dim text color. (original color.textDim)
  - returns &'static str
- `pub const COLOR_ACCENT: &'static str = "#0e639c"` (static, since 0.4.0): Accent color. (original color.accent, background of accent buttons)
  - returns &'static str
- `pub const COLOR_ACCENT_HOVER: &'static str = "#1177bb"` (static, since 0.4.0): Color when hovering over the accent color. (original color.accentHover)
  - returns &'static str
- `pub const COLOR_WARNING: &'static str = "#d97706"` (static, since 0.4.0): Orange.
  - returns &'static str
- `pub const COLOR_WARNING_HOVER: &'static str = "#f59e0b"` (static, since 0.4.0): Color when hovering over the warning color. (original color.warningHover)
  - returns &'static str
- `pub const COLOR_ERROR: &'static str = "#f44336"` (static, since 0.4.0): Error color. (original color.error)
  - returns &'static str
- `pub const COLOR_SUCCESS: &'static str = "#4CAF50"` (static, since 0.4.0): Success color. (original color.success)
  - returns &'static str
- `pub const COLOR_INPUT_BACKGROUND: &'static str = "#3c3c3c"` (static, since 0.4.0): Background color of input boxes. (original color.inputBg, input preset)
  - returns &'static str
- `pub const COLOR_RESIZER: &'static str = "#333"` (static, since 0.4.0): Resizer color. (original color.resizer, also used for the default button background and input box borders)
  - returns &'static str
- `pub const COLOR_RESIZER_HOVER: &'static str = "#007acc"` (static, since 0.4.0): Color while hovering over or dragging a resizer. (original color.resizerHover)
  - returns &'static str
- `pub const SIZE_RESIZER: f64 = 5.0` (static, since 0.4.0): Resizer thickness. (pixels)
  - returns f64
- `pub const FONT_FAMILY: &'static str = "sans-serif"` (static, since 0.4.0): Font family. (original font.family)
  - returns &'static str
- `pub const FONT_MONOSPACE: &'static str = "\"Consolas\", monospace"` (static, since 0.4.0): Monospace font. (original font.mono, textarea preset)
  - returns &'static str
- `pub const FONT_SIZE: &'static str = "13px"` (static, since 0.4.0): Font size. (original font.size)
  - returns &'static str
- `pub const FONT_SIZE_SMALL: &'static str = "12px"` (static, since 0.4.0): Small font size. (original font.sizeSmall)
  - returns &'static str

## PaneStyleOptions (struct) (Clone, Copy, Debug, Default)

PaneStyle::create options. (original options: { id, text, style, type, placeholder, accent, warning })

Example: Options for an accent button (unspecified fields are empty strings and false)

```rust
use vanilla::PaneStyleOptions;

let options = PaneStyleOptions { id: "saveButton", text: "Save", accent: true, style: &[("margin", "4px")], ..Default::default() };
assert_eq!(options.style, &[("margin", "4px")]);
assert_eq!(options.element_type, "");
assert_eq!(options.placeholder, "");
assert!(!options.warning);
```

- `pub id: &'a str` (field, since 0.4.0): Element id. (not set if empty, on desktop it is the node name, the tag name if empty)
  - returns &'a str
- `pub text: &'a str` (field, since 0.4.0): Text. (original innerText, not set if empty)
  - returns &'a str
- `pub style: &'a [(&'a str, &'a str)]` (field, since 0.4.0): Additional styles. (list of (CSS property name, value), applied after the preset styles)
  - returns &'a [(&'a str, &'a str)]
- `pub element_type: &'a str` (field, since 0.4.0): Element type. (original options.type, not set if empty, not used on desktop)
  - returns &'a str
- `pub placeholder: &'a str` (field, since 0.4.0): Placeholder text. (the element's placeholder on the web, not set if empty, on desktop it goes into the input field of input and textarea)
  - returns &'a str
- `pub accent: bool` (field, since 0.4.0): Sets the button preset background to COLOR_ACCENT.
  - returns bool
- `pub warning: bool` (field, since 0.4.0): Sets the button preset background to COLOR_WARNING. (takes precedence over accent)
  - returns bool

## PaneResizableEdges (struct) (Clone, Copy, Debug, PartialEq, Eq, Default)

Edges that can be dragged with a resizer. (original resizableEdges)

Example: Blocking only the left edge

```rust
use vanilla::{PaneOptions, PaneResizableEdges};

let options = PaneOptions { resizable_edges: PaneResizableEdges { left: false, ..Default::default() }, ..Default::default() };
assert!(options.resizable_edges.top && options.resizable_edges.bottom && options.resizable_edges.right);
assert!(!options.resizable_edges.left);
```

- `pub top: bool` (field, since 0.4.0): Top edge. (the resizer with the previous sibling in a vertically split parent)
  - returns bool
- `pub bottom: bool` (field, since 0.4.0): Bottom edge. (the resizer with the next sibling in a vertically split parent)
  - returns bool
- `pub left: bool` (field, since 0.4.0): Left edge. (the resizer with the previous sibling in a horizontally split parent)
  - returns bool
- `pub right: bool` (field, since 0.4.0): Right edge. (the resizer with the next sibling in a horizontally split parent)
  - returns bool

## PaneOptions (struct) (Clone, Copy, Debug, Default)

Pane creation options. (original options: { direction, size, minSize, maxSize, isResizable, resizableEdges })

Example: Options for a fixed size list pane and a non-draggable ratio pane

```rust
use vanilla::{PaneDirection, PaneOptions, PaneSize};

let list_options = PaneOptions { size: PaneSize::Fixed(240.0), min_size: 170.0, ..Default::default() };
let tool_options = PaneOptions { direction: PaneDirection::Vertical, size: PaneSize::Ratio(0.25), is_resizable: false, ..Default::default() };
assert_eq!(list_options.direction, PaneDirection::Horizontal);
assert_eq!(list_options.max_size, f64::MAX);
assert!(list_options.is_resizable);
assert_eq!(tool_options.min_size, 50.0);
```

- `pub direction: PaneDirection` (field, since 0.4.0): Direction to lay out children. (default Horizontal)
  - returns PaneDirection
- `pub size: PaneSize` (field, since 0.4.0): Initial size. (length along the parent's split direction, default Flex)
  - returns PaneSize
- `pub min_size: f64` (field, since 0.4.0): Minimum size. (pixels, default 50)
  - returns f64
- `pub max_size: f64` (field, since 0.4.0): Maximum size. (pixels, default f64::MAX)
  - returns f64
- `pub is_resizable: bool` (field, since 0.4.0): Whether it can be dragged with a resizer. (default true, the resizer between two adjacent siblings can be dragged only if the parent and both siblings are true)
  - returns bool
- `pub resizable_edges: PaneResizableEdges` (field, since 0.4.0): Edges that can be dragged with a resizer. (default all four)
  - returns PaneResizableEdges

## ClassicScrollbarMetrics (struct) (Clone, Copy, Debug, PartialEq)

Metrics of a space-taking scroll bar (classic scroll bar). (same as Chrome, DIP)

Example: Computing the thumb position with the same metrics as Chrome on Windows (bar 200, visible length 200, content 800)

```rust
use vanilla::web::pane::{self, ClassicScrollbarMetrics};

let metrics = ClassicScrollbarMetrics { thickness: 15.0, button_length: 18.0, thumb_thickness: 9.0, thumb_cross_offset: 3.0, thumb_minimum_length: 17.0, thumb_length_inset: 0.0 };
assert_eq!(pane::calculate_classic_thumb_span(&metrics, 200.0, 200.0, 800.0, 0.0), Some((18.0, 41.0)));
assert_eq!(pane::calculate_classic_thumb_span(&metrics, 200.0, 200.0, 800.0, 600.0), Some((141.0, 41.0)));
assert_eq!(pane::calculate_classic_thumb_span(&metrics, 200.0, 200.0, 200.0, 0.0), None);
```

- `pub thickness: f64` (field, since 0.4.0): Bar thickness. (this much is taken from the content box)
  - returns f64
- `pub button_length: f64` (field, since 0.4.0): Length of the buttons at both ends. (the thumb moves between them, 0 if none)
  - returns f64
- `pub thumb_thickness: f64` (field, since 0.4.0): Thumb thickness. (across the bar)
  - returns f64
- `pub thumb_cross_offset: f64` (field, since 0.4.0): From the inside of the bar to the thumb. (across the bar)
  - returns f64
- `pub thumb_minimum_length: f64` (field, since 0.4.0): Shortest thumb length in the track the thumb moves in.
  - returns f64
- `pub thumb_length_inset: f64` (field, since 0.4.0): How far the drawn thumb stays from the ends of the track.
  - returns f64

## Functions and constants

- `pub fn read_classic_scrollbar_metrics(is_thin: bool) -> Option<ClassicScrollbarMetrics>` (method, since 0.4.0): Classic scroll bar metrics used by Chrome on this platform. (None for overlay scroll bars)
  - Windows, Linux: Chrome uses the Fluent scroll bar as a space-taking scroll bar. (IsFluentScrollbarEnabled in native_theme_features.cc is true on IS_WIN, IS_LINUX,
    and the overlay scroll bar feature kOverlayScrollbar is off on both operating systems) Thickness 15, buttons 18, thumb 9 and minimum length 17 (native_theme_fluent.h, .cc).
    scrollbar-width: thin is 2/3 times, like Chrome ScrollbarThemeAura.
  - Mac: Chrome reads the system setting (Show scroll bars) with NSScroller.preferredScrollerStyle (os_settings_provider_mac.mm), and overlay scroll bars take no space.
    If classic, the legacy values of scrollbar_theme_mac.cc apply (thickness 15, 11 if thin, minimum thumb track 20, 16), and the thumb is drawn shrunk by 3 all around (1 more for the border on the bar side) like native_theme_mac.mm.
  - Web: reads the bar thickness laid out by the browser (offsetWidth - clientWidth of an element with overflow: scroll). 0 means an overlay scroll bar.
  - `is_thin` bool: Whether CSS scrollbar-width is thin.
  - returns Option<ClassicScrollbarMetrics>: Metrics of the classic scroll bar. (None for overlay scroll bars)
- `pub fn calculate_classic_thumb_span(metrics: &ClassicScrollbarMetrics, track_length: f64, viewport_length: f64, extent_length: f64, offset: f64) -> Option<(f64, f64)>` (method, since 0.4.0): Thumb position of the classic scroll bar. ((thumb start, thumb length), positions along the bar length, the bar start is 0. None if not overflowing or there is no thumb track)
  - Like Chrome ScrollbarTheme, the thumb track is between the buttons at both ends, and the thumb length is track x visible ratio (down to the minimum length).
  - `metrics` &ClassicScrollbarMetrics: Bar metrics. (read_classic_scrollbar_metrics)
  - `track_length` f64: Bar length.
  - `viewport_length` f64: Length of the visible content.
  - `extent_length` f64: Length of the whole content.
  - `offset` f64: Scrolled amount.
  - returns Option<(f64, f64)>: (thumb start, thumb length). None if the content does not overflow by more than 0.5, the thumb track is shorter than the minimum thumb length, or the visible length is 0 or less.

## PaneDirection (enum) (Clone, Copy, Debug, Default, PartialEq, Eq)

Split direction. (original "horizontal" | "vertical")

- `Horizontal`: Places children from left to right.
- `Vertical`: Places children from top to bottom.

## PaneSize (enum) (Clone, Copy, Debug, Default, PartialEq)

Initial size. (length along the parent's split direction)

- `Flex`: The space left over by fixed size siblings is split equally among flex siblings. (original 0, "flex")
- `Fixed` = `Fixed(f64)`: Pixels. (original numbers greater than 1)
- `Ratio` = `Ratio(f64)`: Ratio multiplied by the parent length minus the resizers. (original numbers at most 1, "50%")
