ui/uiscrollbar
스크롤바. (원본 ui/uiscrollbar.js 의 UIScrollBar, ScrollBarAxis)
- 대상 스크롤 뷰의 스크롤 상태를 트랙(바탕) + 썸(끄는 손잡이)으로 보인다. 썸이나 트랙을 끌면 대상의 오프셋을 바로 바꾼다.
- 매 tick 대상의 오프셋 / 콘텐트 크기 / 보이는 영역을 읽어 썸 위치와 크기를 맞춘다.
- 원본과 다른 것:
- 원본 UIScrollBar 는 WorldNode 를 상속한 노드이고, 트랙 Paint 와 썸 노드(Paint)를 자기 아래에 만든다. 러스트 판은 노드에 붙는 컴포넌트이고, 트랙과 썸을 직접 그린다. (썸 노드 없이 썸 사각형과 켜짐만 든다) 썸 상태는 원본 썸 노드처럼 처음은 켜진 0 크기이고, 끌 때 사각형을 그대로 둔다. (get_thumb_rect 도 원본 getThumbRect 처럼 처음은 0 크기 사각형)
- 대상은 스크롤 뷰 컴포넌트 대신 UIScrollView 가 붙은 노드의 핸들이다. (set_scroll_view / get_scroll_view)
- 트랙 누름 자리와 썸 안 판정은 노드 행렬의 역으로 바꾼 로컬 좌표로 한다. (원본은 월드 위치를 뺀다. 회전 / 크기가 없으면 같다)
- UI 문서(UIDocument)는 register_node_type 으로 등록하면 원본 노드 꼴로 쓰고 읽는다. (노드 type "UIScrollBar", 트랙 Paint, 썸 노드, uidocument.rs 의 UIDocumentNode)
- 보통은 UIScrollView::set_shows_vertical_scroll_bar 가 만든다. 직접 만들 때는 node_tree.add_component 로 붙인다. (피봇 / 앵커 왼쪽 위, interactable)
Scroll bar. (UIScrollBar, ScrollBarAxis of the original ui/uiscrollbar.js)
- Shows the target scroll view's scroll state as a track (background) + thumb (drag handle). Dragging the thumb or track changes the target's offset right away.
- Every tick, reads the target's offset / content size / visible area and fits the thumb position and size.
- Differences from the original:
- The original UIScrollBar is a node that inherits WorldNode, and creates the track Paint and the thumb node (Paint) under itself. The Rust version is a component attached to a node, and draws the track and thumb directly. (holds only the thumb rectangle and its on state, without a thumb node) Like the original thumb node, the thumb state starts on with zero size, and the rectangle stays as is while dragging. (get_thumb_rect also starts as a zero-size rectangle like the original getThumbRect)
- The target is the handle of a node with a UIScrollView attached instead of the scroll view component. (set_scroll_view / get_scroll_view)
- The track press position and the inside-thumb test use local coordinates converted with the inverse of the node matrix. (the original subtracts the world position. the same without rotation / scale)
- The UI document (UIDocument) writes and reads it in the original node form when registered with register_node_type. (node type "UIScrollBar", track Paint, thumb node, UIDocumentNode in uidocument.rs)
- Usually created by UIScrollView::set_shows_vertical_scroll_bar. To create one directly, attach it with node_tree.add_component. (pivot / anchor at top left, interactable)
UIScrollBarstruct traits Default, Component, UIDocumentNode
스크롤바.
- 대상 스크롤 뷰 노드의 오프셋, 콘텐트 크기, 보이는 영역을 매 tick 읽어 썸을 맞춘다. 썸이나 트랙을 끌면 대상 오프셋을 바로 바꾼다.
Scroll bar.
- Reads the target scroll view node's offset, content size, and visible area every tick and fits the thumb. Dragging the thumb or track changes the target offset right away.
use vanilla::{Engine, EngineConfiguration, NodeTree, Pivot, Rect, UIScrollBar, UIScrollView, Vector2};
let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let scroll_id = node_tree.create_child(root_id, "scroll");
node_tree[scroll_id].set_pivot(Pivot::TOP_LEFT);
node_tree[scroll_id].set_content_size(Vector2::create(200.0, 112.0));
let scroll_view = node_tree.add_component(scroll_id, UIScrollView::new()).expect("scroll view");
scroll_view.set_scroll_content_size(Vector2::create(200.0, 448.0));
let scroll_bar_id = UIScrollView::set_shows_vertical_scroll_bar_in_tree(&mut node_tree, scroll_id, true).expect("scroll bar");
node_tree.tick(&engine, 0.016);
let scroll_bar = node_tree[scroll_bar_id].get_component::<UIScrollBar>().expect("scroll bar");
assert_eq!(scroll_bar.get_thumb_rect(), Some(Rect::create(0.0, 0.0, 12.0, 25.0)));생성. (세로, 트랙 옅은 검정, 썸 반투명 흰색, 썸 최소 길이 24, 자동 숨김)
- 트리에 붙이려면 node_tree.add_component 를 쓴다. (붙을 때 피봇, 앵커를 왼쪽 위로 두고 interactable 을 켠다)
Constructor. (vertical, faint black track, translucent white thumb, minimum thumb length 24, auto hide)
- To attach to a tree, use node_tree.add_component. (on attach, sets the pivot and anchor to the top left and turns interactable on)
반환ReturnsUIScrollBar 대상이 없는 새 스크롤바.New scroll bar with no target.
짝Counterpart: vanilla.js UIScrollBar.constructor
use vanilla::{Engine, EngineConfiguration, NodeTree, Pivot, Rect, ScrollBarAxis, UIScrollBar, UIScrollView, Vector2};
let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let scroll_id = node_tree.create_child(root_id, "scroll");
node_tree[scroll_id].set_pivot(Pivot::TOP_LEFT);
node_tree[scroll_id].set_content_size(Vector2::create(200.0, 100.0));
let scroll_view = node_tree.add_component(scroll_id, UIScrollView::new()).expect("scroll view");
scroll_view.set_scroll_content_size(Vector2::create(800.0, 100.0));
let scroll_bar_id = node_tree.create_child(scroll_id, "bar");
let mut scroll_bar = UIScrollBar::new();
scroll_bar.set_axis(ScrollBarAxis::Horizontal);
scroll_bar.set_scroll_view(Some(scroll_id));
node_tree.add_component(scroll_bar_id, scroll_bar);
node_tree[scroll_bar_id].set_rect(0.0, 92.0, 200.0, 8.0);
node_tree.tick(&engine, 0.016);
let scroll_bar = node_tree[scroll_bar_id].get_component::<UIScrollBar>().expect("scroll bar");
assert_eq!(scroll_bar.get_thumb_rect(), Some(Rect::create(0.0, 0.0, 50.0, 8.0)));대상 스크롤 뷰 설정. (UIScrollView 가 붙은 노드)
Sets the target scroll view. (a node with a UIScrollView attached)
- scroll_view_node_idOption<NodeId>
- UIScrollView 가 붙은 노드. None 이면 대상이 없어 썸을 끄고 터치를 받지 않는다.Node with a UIScrollView attached. None means there is no target, so the thumb is turned off and touches are not taken.
짝Counterpart: vanilla.js UIScrollBar.setScrollView
대상 스크롤 뷰 반환. (TouchRecognizer 가 자기 스크롤 뷰로 드래그를 넘기지 않으려고 읽는다)
Returns the target scroll view. (read by TouchRecognizer so as not to hand drags over to its own scroll view)
반환ReturnsOption<NodeId> 대상 스크롤 뷰 노드. 정하지 않았으면 None.Target scroll view node. None if not set.
짝Counterpart: vanilla.js UIScrollBar.getScrollView
축 설정.
Sets the axis.
- axisScrollBarAxis
- 썸이 움직일 축. (기본 세로)Axis the thumb moves along. (default vertical)
짝Counterpart: vanilla.js UIScrollBar.setAxis
축 반환.
Returns the axis.
반환ReturnsScrollBarAxis 지금 축.Current axis.
짝Counterpart: vanilla.js UIScrollBar.getAxis
트랙 색 설정.
Sets the track color.
- colorimpl Into<Color>
- 트랙(바탕) 색. (기본 (0, 0, 0, 0.15))Track (background) color. (default (0, 0, 0, 0.15))
짝Counterpart: vanilla.js UIScrollBar.setTrackColor
썸 색 설정.
Sets the thumb color.
- colorimpl Into<Color>
- 썸 색. (기본 (1, 1, 1, 0.6))Thumb color. (default (1, 1, 1, 0.6))
짝Counterpart: vanilla.js UIScrollBar.setThumbColor
트랙 색 반환. (원본은 트랙 Paint 컴포넌트의 색이다. 러스트 판은 직접 그려 색을 든다)
Returns the track color. (in the original, the color of the track Paint component. the Rust version draws it directly and holds the color)
반환ReturnsColor 트랙 색.Track color.
짝Counterpart: vanilla.js UIScrollBar.getTrackColor
썸 색 반환. (원본은 썸 노드 Paint 컴포넌트의 색이다)
Returns the thumb color. (in the original, the color of the thumb node's Paint component)
반환ReturnsColor 썸 색.Thumb color.
짝Counterpart: vanilla.js UIScrollBar.getThumbColor
썸 최소 길이 설정.
Sets the minimum thumb length.
- min_thumb_sizef64
- 썸이 축 방향으로 가질 가장 짧은 길이. (픽셀, 기본 24) 보이는 비율로 셈한 길이가 이보다 짧으면 이 길이를 쓴다.Shortest length the thumb can have along the axis. (pixels, default 24) If the length calculated from the visible ratio is shorter, this length is used.
짝Counterpart: vanilla.js UIScrollBar.setMinThumbSize
자동 숨김 설정. (콘텐트가 보이는 영역에 들어오면 트랙까지 숨긴다)
- 노드는 켜 둔 채 보이지 않게만 해, 콘텐트가 길어지거나 자동 숨김을 끄면 다음 tick 에 다시 보인다.
Sets auto hide. (hides even the track when the content fits in the visible area)
- The node stays active and is only made invisible, so it shows again on the next tick when the content grows or auto hide is turned off.
- auto_hidebool
- true 면 스크롤할 것이 없을 때 스크롤바 노드를 끈다. (기본 true) false 면 썸만 끄고 트랙은 그린다.If true, turns off the scroll bar node when there is nothing to scroll. (default true) If false, turns off only the thumb and draws the track.
짝Counterpart: vanilla.js UIScrollBar.setAutoHide
지금 썸 사각형. (스크롤바 노드 영역 안, 썸이 꺼져 있으면 None)
Current thumb rectangle. (within the scroll bar node area, None if the thumb is off)
반환ReturnsOption<Rect> 썸 사각형. (스크롤바 노드의 로컬 좌표, 픽셀) 대상이 없거나 스크롤할 것이 없어 썸이 꺼졌으면 None. 첫 tick 전에는 켜진 0 크기 사각형이다.Thumb rectangle. (local coordinates of the scroll bar node, pixels) None if the thumb is off because there is no target or nothing to scroll. Before the first tick it is an on, zero-size rectangle.
짝Counterpart: vanilla.js UIScrollBar.getThumbRect
use vanilla::{Engine, EngineConfiguration, NodeTree, Rect, UIScrollBar};
let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let scroll_bar_id = node_tree.create_child(root_id, "bar");
node_tree.add_component(scroll_bar_id, UIScrollBar::new());
let scroll_bar = node_tree[scroll_bar_id].get_component::<UIScrollBar>().expect("scroll bar");
assert_eq!(scroll_bar.get_thumb_rect(), Some(Rect::create(0.0, 0.0, 0.0, 0.0)));
node_tree.tick(&engine, 0.016);
let scroll_bar = node_tree[scroll_bar_id].get_component::<UIScrollBar>().expect("scroll bar");
assert_eq!(scroll_bar.get_thumb_rect(), None);ScrollBarAxisenum traits Clone, Copy, Debug, PartialEq, Eq
스크롤바 축.
Scroll bar axis.
| 이름Name | 설명Description |
|---|---|
Horizontal | 가로. (썸이 왼쪽 오른쪽으로 움직이고 오프셋 x 를 바꾼다)Horizontal. (the thumb moves left and right and changes offset x) |
Vertical | 세로. (썸이 위아래로 움직이고 오프셋 y 를 바꾼다)Vertical. (the thumb moves up and down and changes offset y) |