vanilladocs
vanillapunch.com
API / web/pane/dompane

web/pane/dompane

DOM 화면 분할 패널. (원본 web/pane.js 의 PaneStyle, Pane 을 DOM 그대로 옮긴 웹 판, 공통 형과 셈은 web/pane.rs)

let main_pane = Pane::new(PaneOptions { direction: PaneDirection::Horizontal, ..Default::default() });
let left_pane = Pane::new(PaneOptions { size: PaneSize::Fixed(240.0), min_size: 170.0, ..Default::default() });
let view_pane = Pane::new(PaneOptions { min_size: 200.0, ..Default::default() });
main_pane.add_pane(&left_pane);
main_pane.add_pane(&view_pane);
left_pane.get_container().append_child(&PaneStyle::create("div", "panel", &PaneStyleOptions::default()));
main_pane.attach_to(&body);
  • 원본과 다른 점:
  • PaneStyle::apply 의 스타일은 (CSS 속성 이름, 값) 목록이다. 이름은 원본 객체 키(backgroundColor)가 아니라 CSS 이름(background-color)이다. (러스트에는 Object.assign 이 없어서 style.setProperty 로 넣는다) 태그 이름이 틀리면 원본처럼 그 자리에서 멈춘다. (원본은 예외, 러스트 판은 panic)
  • Pane 은 상태를 Rc<RefCell> 로 나눠 드는 손잡이다. clone 은 같은 패널을 가리킨다. 자식은 부모를 Weak 로 가리킨다. attach_to 가 단 창 resize 리스너가 뿌리 패널을 끝까지 붙든다. (원본과 같다) attach_to 하지 않은 패널은 손잡이를 모두 놓으면 풀리고, 리사이저를 끌어도 아무것도 하지 않는다.
  • 리사이저 두께는 원본처럼 data-thickness 속성에 적되, 계산은 러스트 쪽에 든 값으로 한다.
  • 리스너는 wasm-bindgen Closure 다. 요소에 다는 것은 into_js_value 로 JS 가비지 컬렉터에 넘기고, 요소는 사건의 currentTarget 으로 읽는다. (요소를 잡아 두면 러스트 쪽이 요소를 붙들어 DOM 에서 빼도 풀리지 않는다)
  • set_callback 은 None 으로 비울 수 있다. 콜백 안에서 패널을 다시 불러도 된다. (부르는 동안 빼 두었다가 돌려놓는다)

DOM screen split pane. (the web version porting PaneStyle and Pane of the original web/pane.js to the DOM as is, common types and calculations in web/pane.rs)

let main_pane = Pane::new(PaneOptions { direction: PaneDirection::Horizontal, ..Default::default() });
let left_pane = Pane::new(PaneOptions { size: PaneSize::Fixed(240.0), min_size: 170.0, ..Default::default() });
let view_pane = Pane::new(PaneOptions { min_size: 200.0, ..Default::default() });
main_pane.add_pane(&left_pane);
main_pane.add_pane(&view_pane);
left_pane.get_container().append_child(&PaneStyle::create("div", "panel", &PaneStyleOptions::default()));
main_pane.attach_to(&body);
  • Differences from the original:
  • PaneStyle::apply styles are a list of (CSS property name, value). Names are CSS names (background-color), not the original object keys (backgroundColor). (Rust has no Object.assign, so they are set with style.setProperty) If the tag name is invalid, it stops on the spot as in the original. (an exception in the original, a panic in the Rust version)
  • Pane is a handle that shares its state as Rc<RefCell>. clone points to the same pane. Children point to their parent with Weak. The window resize listener added by attach_to holds the root pane until the end. (same as the original) Panes that were not attach_to'd are freed when all handles are dropped, and dragging their resizers does nothing.
  • The resizer thickness is written to the data-thickness attribute as in the original, but calculations use the value held on the Rust side.
  • Listeners are wasm-bindgen Closures. Those attached to elements are handed to the JS garbage collector with into_js_value, and the element is read from the event's currentTarget. (holding the element would make the Rust side keep it alive, so it would not be freed even when removed from the DOM)
  • set_callback can be cleared with None. Calling into the pane again inside the callback is fine. (it is taken out while being called and put back afterward)

PaneStylestruct

짝Counterpart: vanilla.js PaneStyle소스source

스타일 및 요소 생성 유틸리티. (원본 PaneStyle)

Style and element creation utility. (original PaneStyle)

예제Example도구 막대에 단추 두 개를 놓아 body 에 붙이기 (브라우저가 있어야 해서 컴파일만)Placing two buttons on a toolbar and attaching it to body (compile only, needs a browser)
use vanilla::{PaneStyle, PaneStyleOptions};

let body = web_sys::window().unwrap().document().unwrap().body().unwrap();
let toolbar = PaneStyle::create("div", "toolbar", &PaneStyleOptions { style: &[("height", "40px")], ..Default::default() });
let play_button = PaneStyle::create("button", "button", &PaneStyleOptions { text: "Play", accent: true, ..Default::default() });
let reset_button = PaneStyle::create("button", "button", &PaneStyleOptions { text: "Reset", warning: true, ..Default::default() });
toolbar.append_child(&play_button).unwrap();
toolbar.append_child(&reset_button).unwrap();
PaneStyle::apply(&toolbar, &[("justify-content", "flex-start")]);
body.append_child(&toolbar).unwrap();
정적staticpub fn apply(element: &HtmlElement, styles: &[(&str, &str)])#0.4.0 부터since 0.4.0소스source

요소에 여러 스타일을 한꺼번에 넣는다. ((CSS 속성 이름, 값) 목록)

Puts several styles into an element at once. ((CSS property name, value) list)

element&HtmlElement
스타일을 넣을 요소.Element to apply the styles to.
styles&[(&str, &str)]
(CSS 속성 이름, 값) 목록. (이름은 background-color 같은 CSS 이름)List of (CSS property name, value). (names are CSS names like background-color)

짝Counterpart: vanilla.js PaneStyle.apply

정적staticpub fn create(tag_name: &str, preset: &str, options: &PaneStyleOptions) -> HtmlElement#0.4.0 부터since 0.4.0소스source

스타일 프리셋을 넣은 요소를 만든다. (preset: "panel" | "toolbar" | "button" | "input" | "textarea" | "text", 그 밖은 공통 스타일만)

Creates an element with a style preset applied. (preset: "panel" | "toolbar" | "button" | "input" | "textarea" | "text", only the common style otherwise)

tag_name&str
만들 요소의 태그 이름. (만들 수 없거나 HTML 요소가 아니면 panic)Tag name of the element to create. (panic if it cannot be created or is not an HTML element)
preset&str
스타일 프리셋. ("panel" | "toolbar" | "button" | "input" | "textarea" | "text")Style preset. ("panel" | "toolbar" | "button" | "input" | "textarea" | "text")
options&PaneStyleOptions
id, 글, 덧붙이는 스타일, type, 안내 글, 단추 색.id, text, additional styles, type, placeholder, button color.

반환ReturnsHtmlElement 만든 요소. (아직 문서에 붙지 않았다)The created element. (not attached to the document yet)

짝Counterpart: vanilla.js PaneStyle.create

Panestruct traits Clone

짝Counterpart: vanilla.js Pane소스source

화면 분할 패널. (원본 Pane, clone 은 같은 패널을 가리킨다)

Screen split pane. (original Pane, clones point to the same pane)

예제Example왼쪽 목록과 오른쪽 화면으로 나누어 body 에 붙이기 (브라우저가 있어야 해서 컴파일만)Splitting into a list on the left and a view on the right and attaching to body (compile only, needs a browser)
use vanilla::{Pane, PaneOptions, PaneSize, PaneStyle, PaneStyleOptions};

let body = web_sys::window().unwrap().document().unwrap().body().unwrap();
let main_pane = Pane::new(PaneOptions::default());
let left_pane = Pane::new(PaneOptions { size: PaneSize::Fixed(240.0), min_size: 170.0, ..Default::default() });
let view_pane = Pane::new(PaneOptions { min_size: 200.0, ..Default::default() });
main_pane.add_pane(&left_pane);
main_pane.add_pane(&view_pane);
let panel = PaneStyle::create("div", "panel", &PaneStyleOptions::default());
left_pane.get_container().append_child(&panel).unwrap();
main_pane.set_callback(Some(Box::new(|| {
	println!("layout changed");
})));
main_pane.attach_to(&body);
생성자constructorpub fn new(options: PaneOptions) -> Pane#0.4.0 부터since 0.4.0소스source

생성. (컨테이너 div 를 만들고, 문서에 다는 끌기 리스너를 지어 둔다)

Constructor. (creates the container div and builds the drag listeners to attach to the document)

optionsPaneOptions
패널 옵션.Pane options.

반환ReturnsPane 새 패널. (컨테이너 div 는 아직 문서에 붙지 않았다)New pane. (the container div is not attached to the document yet)

짝Counterpart: vanilla.js Pane.constructor

메서드methodpub fn add_pane(&self, pane: &Pane)#0.4.0 부터since 0.4.0소스source

자식 추가. (앞 자식이 있으면 그 사이에 리사이저를 둔다)

Adds a child. (places a resizer in between if there is a previous child)

pane&Pane
붙일 자식 패널.Child pane to attach.

짝Counterpart: vanilla.js Pane.addPane

메서드methodpub fn update_layout(&self, x: f64, y: f64, width: f64, height: f64)#0.4.0 부터since 0.4.0소스source

배치. (자기 자리를 놓고, 고정 크기 자식을 먼저 재고 남은 자리를 flex 자식끼리 나눈 뒤 자식과 리사이저를 차례로 놓는다)

Layout. (places itself, measures fixed size children first, splits the remaining space among flex children, then places the children and resizers in order)

xf64
컨테이너 왼쪽. (픽셀, 부모 요소 기준)Container left. (pixels, relative to the parent element)
yf64
컨테이너 위. (픽셀, 부모 요소 기준)Container top. (pixels, relative to the parent element)
widthf64
컨테이너 폭. (픽셀)Container width. (pixels)
heightf64
컨테이너 높이. (픽셀)Container height. (pixels)

짝Counterpart: vanilla.js Pane.updateLayout

메서드methodpub fn reset_layout(&self)#0.4.0 부터since 0.4.0소스source

배치 초기화. (끌어서 바꾼 크기를 지운다, 자식까지)

Resets the layout. (clears sizes changed by dragging, including children)

짝Counterpart: vanilla.js Pane.resetLayout

메서드methodpub fn refresh(&self)#0.4.0 부터since 0.4.0소스source

부모 요소 크기에 맞춰 다시 놓는다. (부모 크기가 0 이면 창 크기, 부모가 없으면 아무것도 하지 않는다)

Lays out again to fit the parent element size. (the window size if the parent size is 0, does nothing if there is no parent)

짝Counterpart: vanilla.js Pane.refresh

메서드methodpub fn attach_to(&self, parent_element: &Element)#0.4.0 부터since 0.4.0소스source

요소에 단다. (창 크기가 바뀔 때와 다음 프레임에 다시 놓는다. 창 리스너가 이 패널을 끝까지 붙든다)

Attaches to an element. (lays out again when the window size changes and on the next frame. The window listener holds this pane until the end)

parent_element&Element
붙일 부모 요소. (보통 body)Parent element to attach to. (usually body)

짝Counterpart: vanilla.js Pane.attachTo

메서드methodpub fn set_visible(&self, is_visible: bool)#0.4.0 부터since 0.4.0소스source

보이기 / 숨기기. (숨긴 패널은 자리를 차지하지 않고, 맞닿은 리사이저도 숨는다)

Shows / hides. (a hidden pane takes no space, and the adjoining resizers are hidden too)

is_visiblebool
보일지.Whether to show it.

짝Counterpart: vanilla.js Pane.setVisible

메서드methodpub fn is_visible(&self) -> bool#0.4.0 부터since 0.4.0소스source

보이는지.

Whether visible.

반환Returnsbool 보이면 true.True if visible.

짝Counterpart: vanilla.js Pane.isVisible

메서드methodpub fn is_flex(&self) -> bool#0.4.0 부터since 0.4.0소스source

flex 인지. (처음 크기가 Flex)

Whether flex. (initial size is Flex)

반환Returnsbool 처음 크기가 Flex 면 true.True if the initial size is Flex.

짝Counterpart: vanilla.js Pane.isFlex

메서드methodpub fn get_initial_size(&self) -> PaneSize#0.4.0 부터since 0.4.0소스source

처음 크기.

Initial size.

반환ReturnsPaneSize 만들 때 받은 처음 크기. (PaneOptions::size)Initial size given at creation. (PaneOptions::size)

짝Counterpart: vanilla.js Pane.getInitialSize

메서드methodpub fn get_fixed_size(&self) -> f64#0.4.0 부터since 0.4.0소스source

고정 크기. (픽셀, 0 이면 처음 크기로 잰다)

Fixed size. (pixels, measured from the initial size if 0)

반환Returnsf64 고정 크기. (픽셀, 끌어서 정했거나 처음 크기가 Fixed 면 그 값, reset_layout 뒤나 그 밖은 0)Fixed size. (pixels, the value if set by dragging or the initial size is Fixed, 0 after reset_layout or otherwise)

짝Counterpart: vanilla.js Pane.getFixedSize

메서드methodpub fn set_fixed_size(&self, fixed_size: f64)#0.4.0 부터since 0.4.0소스source

고정 크기 설정. (다음 배치부터 쓴다. flex 패널에는 쓰이지 않는다)

Sets the fixed size. (used from the next layout. Not used for flex panes)

fixed_sizef64
새 고정 크기. (픽셀, 0 이면 처음 크기로 잰다)New fixed size. (pixels, measured from the initial size if 0)

짝Counterpart: vanilla.js Pane.setFixedSize

메서드methodpub fn get_min_size(&self) -> f64#0.4.0 부터since 0.4.0소스source

최소 크기.

Minimum size.

반환Returnsf64 가장 작은 크기. (픽셀)Minimum size. (pixels)

짝Counterpart: vanilla.js Pane.getMinSize

메서드methodpub fn get_max_size(&self) -> f64#0.4.0 부터since 0.4.0소스source

최대 크기.

Maximum size.

반환Returnsf64 가장 큰 크기. (픽셀)Largest size. (pixels)

짝Counterpart: vanilla.js Pane.getMaxSize

메서드methodpub fn get_container(&self) -> HtmlElement#0.4.0 부터since 0.4.0소스source

컨테이너 요소. (내용을 여기에 붙인다)

Container element. (content is attached here)

반환ReturnsHtmlElement 컨테이너 div 요소.Container div element.

짝Counterpart: vanilla.js Pane.getContainer

메서드methodpub fn set_callback(&self, resize_callback: Option<PaneResizeCallback>)#0.4.0 부터since 0.4.0소스source

배치 콜백 설정. (update_layout 이 끝날 때마다 부른다. None 이면 비운다)

Sets the layout callback. (called every time update_layout finishes. None clears it)

resize_callbackOption<PaneResizeCallback>
update_layout 이 끝날 때마다 부를 함수. (None 이면 비운다)Function called whenever update_layout finishes. (None clears it)

짝Counterpart: vanilla.js Pane.setCallback

메서드methodpub fn is_resizable(&self) -> bool#0.4.0 부터since 0.4.0소스source

리사이저로 끌 수 있는지.

Whether it can be dragged with a resizer.

반환Returnsbool 리사이저로 끌 수 있으면 true.True if it can be dragged with a resizer.

짝Counterpart: vanilla.js Pane.isResizable

메서드methodpub fn get_resizable_edges(&self) -> PaneResizableEdges#0.4.0 부터since 0.4.0소스source

끌 수 있는 가장자리.

Edges that can be dragged.

반환ReturnsPaneResizableEdges 끌 수 있는 가장자리.Edges that can be dragged.

짝Counterpart: vanilla.js Pane.getResizableEdges