# web/pane (vanilla-engine 0.4.0)

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

화면 분할 패널. (원본 web/pane.js 의 PaneTheme, PaneStyle, Pane)
- 원본은 도구(파티클 에디터 같은)의 창 구성을 DOM 으로 짓는다. 가로나 세로로 나눈 패널, 고정, 비율, flex 크기, 최소와 최대, 끌어서 크기를 바꾸는 리사이저,
  숨기기, 끌어서 바꾼 크기 지우기, 배치 콜백, 그리고 같은 테마 색의 요소를 짓는 PaneStyle 프리셋(panel, toolbar, button, input, textarea, text)이다.
- 웹은 원본처럼 DOM 요소로 짓는다. (pane/dompane.rs)
- 데스크탑은 DOM 이 없어 엔진 노드로 같은 일을 한다. 컨테이너는 노드이고 내용은 그 자식 노드다. 리사이저는 끌 수 있는 노드이고 테마 색으로 그린다. (pane/nodepane.rs)
- 크기 셈(calculate_pane_layout)과 끌기 셈(calculate_resized_size)은 두 플랫폼이 같은 함수를 쓴다. (원본 updateLayout, onMouseMove)
- 원본과 다른 점:
  - PaneTheme 은 원본의 묶음(color, size, font)을 이름 앞머리로 편 연관 상수다. (PaneTheme.color.background → PaneTheme::COLOR_BACKGROUND,
    PaneTheme.size.resizer → PaneTheme::SIZE_RESIZER, PaneTheme.font.sizeSmall → PaneTheme::FONT_SIZE_SMALL)
    줄인 이름은 풀었다. (color.inputBg → COLOR_INPUT_BACKGROUND, font.mono → FONT_MONOSPACE) SIZE_RESIZER 는 픽셀 수(f64)다.
  - Pane 의 옵션은 PaneOptions 다. 크기는 PaneSize 다. (Flex, Fixed(픽셀), Ratio(0~1 비율))
    원본은 숫자 하나로 0 이나 "flex" 는 flex, 1 이하는 비율, 1 을 넘으면 픽셀로 읽는다. ("50%" 는 Ratio(0.5)) 그래서 get_initial_size 는 PaneSize 를 돌려준다.
  - PaneStyle::create 의 옵션은 PaneStyleOptions 다. 빈 글은 원본의 빈 값처럼 넣지 않는다. 원본 options.type 은 element_type 이다. (type 은 러스트 예약어)

## PaneResizeCallback (type)

패널 크기가 다시 놓일 때 부르는 콜백. (원본 setCallback)

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

## PaneTheme (struct)

테마 상수. (원본 PaneTheme)

예제: 테마 색으로 테두리 스타일 글 짓기 (원본 toolbar 프리셋의 아래 테두리)

```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): 바탕 색. (원본 color.background, 패널 컨테이너와 textarea 프리셋의 바탕)
  - returns &'static str
- `pub const COLOR_PANEL: &'static str = "#252526"` (static, since 0.4.0): panel 프리셋의 바탕 색. (원본 color.panel)
  - returns &'static str
- `pub const COLOR_TOOLBAR: &'static str = "#2d2d30"` (static, since 0.4.0): toolbar 프리셋의 바탕 색. (원본 color.toolbar)
  - returns &'static str
- `pub const COLOR_BORDER: &'static str = "#444"` (static, since 0.4.0): 테두리 색. (원본 color.border, toolbar 프리셋의 아래 테두리)
  - returns &'static str
- `pub const COLOR_TEXT: &'static str = "#ccc"` (static, since 0.4.0): 글 색. (원본 color.text)
  - returns &'static str
- `pub const COLOR_TEXT_DIM: &'static str = "#aaaaaa"` (static, since 0.4.0): 흐린 글 색. (원본 color.textDim)
  - returns &'static str
- `pub const COLOR_ACCENT: &'static str = "#0e639c"` (static, since 0.4.0): 강조 색. (원본 color.accent, accent 단추의 바탕)
  - returns &'static str
- `pub const COLOR_ACCENT_HOVER: &'static str = "#1177bb"` (static, since 0.4.0): 강조 색에 올려 두었을 때의 색. (원본 color.accentHover)
  - returns &'static str
- `pub const COLOR_WARNING: &'static str = "#d97706"` (static, since 0.4.0): 주황색.
  - returns &'static str
- `pub const COLOR_WARNING_HOVER: &'static str = "#f59e0b"` (static, since 0.4.0): 경고 색에 올려 두었을 때의 색. (원본 color.warningHover)
  - returns &'static str
- `pub const COLOR_ERROR: &'static str = "#f44336"` (static, since 0.4.0): 오류 색. (원본 color.error)
  - returns &'static str
- `pub const COLOR_SUCCESS: &'static str = "#4CAF50"` (static, since 0.4.0): 성공 색. (원본 color.success)
  - returns &'static str
- `pub const COLOR_INPUT_BACKGROUND: &'static str = "#3c3c3c"` (static, since 0.4.0): 입력 칸의 바탕 색. (원본 color.inputBg, input 프리셋)
  - returns &'static str
- `pub const COLOR_RESIZER: &'static str = "#333"` (static, since 0.4.0): 리사이저 색. (원본 color.resizer, 단추의 기본 바탕과 입력 칸의 테두리에도 쓴다)
  - returns &'static str
- `pub const COLOR_RESIZER_HOVER: &'static str = "#007acc"` (static, since 0.4.0): 리사이저에 올려 두거나 끄는 동안의 색. (원본 color.resizerHover)
  - returns &'static str
- `pub const SIZE_RESIZER: f64 = 5.0` (static, since 0.4.0): 리사이저 두께. (픽셀)
  - returns f64
- `pub const FONT_FAMILY: &'static str = "sans-serif"` (static, since 0.4.0): 글꼴. (원본 font.family)
  - returns &'static str
- `pub const FONT_MONOSPACE: &'static str = "\"Consolas\", monospace"` (static, since 0.4.0): 고정폭 글꼴. (원본 font.mono, textarea 프리셋)
  - returns &'static str
- `pub const FONT_SIZE: &'static str = "13px"` (static, since 0.4.0): 글 크기. (원본 font.size)
  - returns &'static str
- `pub const FONT_SIZE_SMALL: &'static str = "12px"` (static, since 0.4.0): 작은 글 크기. (원본 font.sizeSmall)
  - returns &'static str

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

PaneStyle::create 옵션. (원본 options: { id, text, style, type, placeholder, accent, warning })

예제: 강조 단추의 옵션 (적지 않은 칸은 빈 글과 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): 요소 id. (빈 글이면 넣지 않는다, 데스크탑은 노드 이름이고 비면 태그 이름)
  - returns &'a str
- `pub text: &'a str` (field, since 0.4.0): 글. (원본 innerText, 빈 글이면 넣지 않는다)
  - returns &'a str
- `pub style: &'a [(&'a str, &'a str)]` (field, since 0.4.0): 덧붙이는 스타일. ((CSS 속성 이름, 값) 목록, 프리셋 스타일 뒤에 넣는다)
  - returns &'a [(&'a str, &'a str)]
- `pub element_type: &'a str` (field, since 0.4.0): 요소의 type. (원본 options.type, 빈 글이면 넣지 않는다, 데스크탑은 쓰지 않는다)
  - returns &'a str
- `pub placeholder: &'a str` (field, since 0.4.0): 안내 글. (웹은 요소의 placeholder 이고 빈 글이면 넣지 않는다, 데스크탑은 input 과 textarea 의 입력 필드에 넣는다)
  - returns &'a str
- `pub accent: bool` (field, since 0.4.0): button 프리셋의 바탕을 COLOR_ACCENT 로.
  - returns bool
- `pub warning: bool` (field, since 0.4.0): button 프리셋의 바탕을 COLOR_WARNING 으로. (accent 보다 앞선다)
  - returns bool

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

리사이저로 끌 수 있는 가장자리. (원본 resizableEdges)

예제: 왼쪽 가장자리만 막기

```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): 위 가장자리. (세로로 나눈 부모에서 앞 형제와의 리사이저)
  - returns bool
- `pub bottom: bool` (field, since 0.4.0): 아래 가장자리. (세로로 나눈 부모에서 뒤 형제와의 리사이저)
  - returns bool
- `pub left: bool` (field, since 0.4.0): 왼쪽 가장자리. (가로로 나눈 부모에서 앞 형제와의 리사이저)
  - returns bool
- `pub right: bool` (field, since 0.4.0): 오른쪽 가장자리. (가로로 나눈 부모에서 뒤 형제와의 리사이저)
  - returns bool

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

Pane 생성 옵션. (원본 options: { direction, size, minSize, maxSize, isResizable, resizableEdges })

예제: 고정 크기 목록 패널과 끌 수 없는 비율 패널의 옵션

```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): 자식을 놓는 방향. (기본 Horizontal)
  - returns PaneDirection
- `pub size: PaneSize` (field, since 0.4.0): 처음 크기. (부모의 나누는 방향 쪽 길이, 기본 Flex)
  - returns PaneSize
- `pub min_size: f64` (field, since 0.4.0): 가장 작은 크기. (픽셀, 기본 50)
  - returns f64
- `pub max_size: f64` (field, since 0.4.0): 가장 큰 크기. (픽셀, 기본 f64::MAX)
  - returns f64
- `pub is_resizable: bool` (field, since 0.4.0): 리사이저로 끌 수 있는지. (기본 true, 부모와 맞닿은 두 형제가 모두 true 여야 그 사이 리사이저가 끌린다)
  - returns bool
- `pub resizable_edges: PaneResizableEdges` (field, since 0.4.0): 리사이저로 끌 수 있는 가장자리. (기본 네 쪽 모두)
  - returns PaneResizableEdges

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

자리를 차지하는 스크롤 막대(클래식 막대)의 치수. (크롬과 같게, DIP)

예제: 윈도우 크롬과 같은 치수로 썸 자리 셈하기 (막대 200, 보이는 길이 200, 내용 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): 막대 두께. (내용 상자에서 이만큼 덜어 낸다)
  - returns f64
- `pub button_length: f64` (field, since 0.4.0): 양끝 단추 길이. (썸은 그 사이에서 움직인다, 없으면 0)
  - returns f64
- `pub thumb_thickness: f64` (field, since 0.4.0): 썸 두께. (막대의 가로지르는 쪽)
  - returns f64
- `pub thumb_cross_offset: f64` (field, since 0.4.0): 막대 안쪽에서 썸까지. (막대의 가로지르는 쪽)
  - returns f64
- `pub thumb_minimum_length: f64` (field, since 0.4.0): 썸이 움직이는 칸의 가장 짧은 썸 길이.
  - returns f64
- `pub thumb_length_inset: f64` (field, since 0.4.0): 그린 썸이 칸 끝에서 떨어지는 만큼.
  - returns f64

## Functions and constants

- `pub fn read_classic_scrollbar_metrics(is_thin: bool) -> Option<ClassicScrollbarMetrics>` (method, since 0.4.0): 이 플랫폼의 크롬이 쓰는 클래식 스크롤 막대 치수. (얹는 막대면 None)
  - 윈도우, 리눅스: 크롬은 Fluent 막대를 자리를 차지하는 막대로 쓴다. (native_theme_features.cc 의 IsFluentScrollbarEnabled 가 IS_WIN, IS_LINUX 에서 참,
    얹는 막대 기능 kOverlayScrollbar 는 두 운영체제에서 꺼져 있다) 두께 15, 단추 18, 썸 9 와 가장 짧은 길이 17 (native_theme_fluent.h, .cc).
    scrollbar-width: thin 은 크롬 ScrollbarThemeAura 처럼 2/3 배다.
  - 맥: 크롬은 시스템 설정(스크롤 막대 보기)을 NSScroller.preferredScrollerStyle 로 읽어(os_settings_provider_mac.mm) 얹는 막대면 자리를 차지하지 않는다.
    클래식이면 scrollbar_theme_mac.cc 의 legacy 값(두께 15, 얇으면 11, 가장 짧은 썸 칸 20, 16)이고 썸은 native_theme_mac.mm 처럼 둘레를 3 (막대 쪽은 테두리 1 더) 줄여 그린다.
  - 웹: 브라우저가 놓은 막대 두께(overflow: scroll 인 요소의 offsetWidth - clientWidth)를 읽는다. 0 이면 얹는 막대다.
  - `is_thin` bool: CSS scrollbar-width 가 thin 인지.
  - returns Option<ClassicScrollbarMetrics>: 클래식 막대의 치수. (얹는 막대면 None)
- `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): 클래식 막대의 썸 자리. ((썸 시작, 썸 길이), 막대 길이 방향의 자리, 막대 시작이 0. 넘치지 않거나 썸 칸이 없으면 None)
  - 크롬 ScrollbarTheme 처럼 썸 칸은 양끝 단추 사이이고, 썸 길이는 칸 x 보이는 비율(가장 짧은 길이까지)이다.
  - `metrics` &ClassicScrollbarMetrics: 막대 치수. (read_classic_scrollbar_metrics)
  - `track_length` f64: 막대 길이.
  - `viewport_length` f64: 보이는 내용의 길이.
  - `extent_length` f64: 내용 전체의 길이.
  - `offset` f64: 굴려 넘긴 만큼.
  - returns Option<(f64, f64)>: (썸 시작, 썸 길이). 내용이 0.5 를 넘게 넘치지 않거나, 썸 칸이 가장 짧은 썸 길이보다 짧거나, 보이는 길이가 0 이하면 None.

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

나누는 방향. (원본 "horizontal" | "vertical")

- `Horizontal`: 자식을 왼쪽에서 오른쪽으로 놓는다.
- `Vertical`: 자식을 위에서 아래로 놓는다.

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

처음 크기. (부모의 나누는 방향 쪽 길이)

- `Flex`: 고정 크기 형제들이 쓰고 남은 자리를 flex 형제끼리 똑같이 나눈다. (원본 0, "flex")
- `Fixed` = `Fixed(f64)`: 픽셀. (원본 1 을 넘는 숫자)
- `Ratio` = `Ratio(f64)`: 리사이저를 뺀 부모 길이에 곱하는 비율. (원본 1 이하 숫자, "50%")
