ui/uiscrollview
스크롤바 기본 두께 / 마진 (UIKit indicator 스타일).
Default scrollbar thickness / margin (UIKit indicator style).
UIScrollViewextends UIView
스크롤뷰 컴포넌트.
- 소유 노드의 getContentSize()를 가시 영역으로 사용한다.
- 내부에 별도의 콘텐츠 노드를 생성하며, 드래그로 스크롤링할 수 있다.
- require() 로 Mask 를 의존 선언하므로 부착되는 노드(WorldNode 계열)에 자동으로 Mask 가 추가되어 자식 클리핑이 동작한다.
- 중첩 ScrollView를 지원한다. (TouchRaycaster와 연동)
Scroll view component.
- Uses the owner node's getContentSize() as the visible area.
- Creates a separate content node inside, which can be scrolled by dragging.
- Declares Mask as a dependency with require(), so on the attached node (WorldNode family) Mask is added automatically and child clipping works.
- Supports nested ScrollView. (works with TouchRaycaster)
import { Engine, EngineConfiguration, UIScene, UIScrollView, UILabel, WorldNode, Paint, Color, Pivot, Vector2 } from "./build/vanilla.js";
class ScrollScene extends UIScene {
create() {
super.create();
const viewportNode = new WorldNode();
viewportNode.setPivot(Pivot.topLeft.clone());
viewportNode.setAnchor(Pivot.topLeft.clone());
viewportNode.setContentSize(Vector2.create(320, 240));
viewportNode.setLocalPosition(Vector2.create(160, 60));
const scrollView = viewportNode.addComponent(UIScrollView);
scrollView.setBackgroundColor(new Color(0.1, 0.12, 0.16, 1));
scrollView.setHorizontal(false);
scrollView.setScrollMode("elastic");
scrollView.setShowsVerticalScrollBar(true);
const rowCount = 20;
const rowHeight = 40;
const content = scrollView.getContent();
for (let rowIndex = 0; rowIndex < rowCount; ++rowIndex) {
const rowNode = new WorldNode();
rowNode.setPivot(Pivot.topLeft.clone());
rowNode.setAnchor(Pivot.topLeft.clone());
rowNode.setContentSize(Vector2.create(280, rowHeight - 4));
rowNode.setLocalPosition(Vector2.create(8, rowIndex * rowHeight + 2));
const rowPaint = rowNode.addComponent(Paint);
rowPaint.setColor(new Color(1, 1, 1, 0.06));
const rowLabel = rowNode.addComponent(UILabel);
rowLabel.setText("Row " + rowIndex);
content.addChild(rowNode);
}
scrollView.setScrollContentSize(Vector2.create(320, rowCount * rowHeight));
scrollView.setScrollOffset(Vector2.create(0, -120));
const root = this.getRoot();
root.addChild(viewportNode);
}
}
const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const scene = new ScrollScene();
scene.setLoadingMinDurationMs(0);
engine.run(scene);의존 컴포넌트, 자식 클리핑을 위해 Mask 가 필요.
Dependent component; Mask is needed for child clipping.
반환ReturnsFunction[] 같은 노드에 함께 붙일 컴포넌트 목록. ([Mask])Components to attach to the same node. ([Mask])
노드에 붙음. (WorldNode 계열의 isInteractable 을 자동 활성화)
Attached to a node. (automatically enables isInteractable of the WorldNode family)
- nodeComponentNode
- 붙을 노드. (내용 크기가 보이는 영역이 된다)The node to attach to. (its content size becomes the visible area)
터치 누름. (TouchRaycaster → WorldNode → ScrollView)
Touch press. (TouchRaycaster → WorldNode → ScrollView)
- viewInputPositionVector2
- 입력 위치. (뷰 좌표)Input position. (view coordinates)
터치 이동. (TouchRaycaster → WorldNode → ScrollView)
Touch move. (TouchRaycaster → WorldNode → ScrollView)
- viewInputPositionVector2
- 입력 위치. (뷰 좌표, 끄는 중일 때만 담아 두고 tick 에서 반영한다)Input position. (view coordinates, stored only while dragging and applied in tick)
터치 뗌. (TouchRaycaster → WorldNode → ScrollView)
Touch release. (TouchRaycaster → WorldNode → ScrollView)
- viewInputPositionVector2
- 입력 위치. (뷰 좌표, 쓰지 않는다)Input position. (view coordinates, unused)
터치 취소. (TouchRaycaster → WorldNode → ScrollView)
Touch cancel. (TouchRaycaster → WorldNode → ScrollView)
- viewInputPositionVector2
- 입력 위치. (뷰 좌표, 쓰지 않는다)Input position. (view coordinates, unused)
갱신.
Update.
- timeDeltanumber
- 지난 프레임부터의 시간. (초)Time since the last frame. (Seconds)
스크롤 오프셋 적용. (클램핑 포함)
Applies the scroll offset. (including clamping)
- offsetVector2
- 스크롤 오프셋. (콘텐츠 노드의 자리, 0 이 맨 위 왼쪽이고 내릴수록 음수, 끌 수 있는 축만 범위로 자르고 다른 축은 0)Scroll offset. (position of the content node, 0 is the top left and it goes negative as you scroll down, only draggable axes are clamped to the range and other axes are 0)
짝Counterpart: vanilla-engine UIScrollView.apply_scroll_offset
스크롤 오프셋 설정.
Sets the scroll offset.
- offsetVector2
- 스크롤 오프셋. (0 이 맨 위 왼쪽이고 내릴수록 음수, 범위로 자른다)Scroll offset. (0 is the top left and it goes negative as you scroll down, clamped to the range)
짝Counterpart: vanilla-engine UIScrollView.set_scroll_offset
import { UIScrollView, WorldNode, Vector2 } from "./build/vanilla.js";
const viewportNode = new WorldNode();
viewportNode.setContentSize(Vector2.create(200, 100));
const scrollView = viewportNode.addComponent(UIScrollView);
scrollView.setScrollContentSize(Vector2.create(200, 500));
scrollView.setScrollOffset(Vector2.create(0, -1000));
const clampedOffset = scrollView.getScrollOffset();
console.log(clampedOffset.y);
scrollView.wheel(Vector2.create(0, -150));
const wheeledOffset = scrollView.getScrollOffset();
console.log(wheeledOffset.y);스크롤 오프셋 반환.
Returns the scroll offset.
반환ReturnsVector2 스크롤 오프셋. (복사하지 않은 원본, 0 이 맨 위 왼쪽이고 내릴수록 음수)Scroll offset. (the original, not a copy, 0 is the top left and it goes negative as you scroll down)
짝Counterpart: vanilla-engine UIScrollView.get_scroll_offset
가로 스크롤 활성 설정. (false = 가로 스크롤 비활성)
Sets horizontal scroll enabled. (false = horizontal scroll disabled)
- horizontalboolean
- 참이면 가로로 끌 수 있다.If true, it can be dragged horizontally.
짝Counterpart: vanilla-engine UIScrollView.set_horizontal
가로 스크롤 활성 반환.
Returns horizontal scroll enabled.
반환Returnsboolean 가로로 끌 수 있으면 참.True if it can be dragged horizontally.
짝Counterpart: vanilla-engine UIScrollView.is_horizontal
세로 스크롤 활성 설정. (false = 세로 스크롤 비활성)
Sets vertical scroll enabled. (false = vertical scroll disabled)
- verticalboolean
- 참이면 세로로 끌 수 있다.If true, it can be dragged vertically.
짝Counterpart: vanilla-engine UIScrollView.set_vertical
세로 스크롤 활성 반환.
Returns vertical scroll enabled.
반환Returnsboolean 세로로 끌 수 있으면 참.True if it can be dragged vertically.
짝Counterpart: vanilla-engine UIScrollView.is_vertical
스크롤하지 않는 축으로 끄는 손가락을 누른 노드에 남길지 설정. (기본 false)
- false 면 지금까지처럼 어느 쪽이든 드래그 임계를 넘으면 스크롤 뷰가 가져간다.
- true 면 세로만 스크롤하는 뷰에서 가로로 더 많이 끈 손가락(가로만이면 세로로)은 가져가지 않고, 누른 노드(슬라이더 등)가 곧바로 누름을 받아 끝까지 끈다. 두 축 모두 스크롤하면 늘 가져간다.
Sets whether to leave a finger dragging along the non-scrolling axis to the pressed node. (default false)
- If false, as before, the scroll view takes it once the drag threshold is exceeded in any direction.
- If true, in a vertical-only scroll view a finger dragged more horizontally (vertically, for horizontal-only) is not taken, and the pressed node (slider, etc.) receives the press right away and drags to the end. If both axes scroll, it is always taken.
- passesboolean
- 참이면 스크롤하지 않는 축의 드래그를 누른 노드에 남긴다.If true, drags along the axis that does not scroll are left to the pressed node.
짝Counterpart: vanilla-engine UIScrollView.set_passes_cross_axis_drag
import { UIScrollView, WorldNode, Vector2 } from "./build/vanilla.js";
const viewportNode = new WorldNode();
viewportNode.setContentSize(Vector2.create(200, 100));
const scrollView = viewportNode.addComponent(UIScrollView);
scrollView.setHorizontal(false);
scrollView.setPassesCrossAxisDrag(true);
const isSidewaysTaken = scrollView.isScrollDrag(30, 5);
const isDownwardTaken = scrollView.isScrollDrag(5, 30);
console.log(isSidewaysTaken, isDownwardTaken);스크롤하지 않는 축으로 끄는 손가락을 누른 노드에 남기는지 반환.
Returns whether a finger dragging along the non-scrolling axis is left to the pressed node.
반환Returnsboolean 스크롤하지 않는 축의 드래그를 남기면 참.True if drags along the axis that does not scroll are left to the pressed node.
짝Counterpart: vanilla-engine UIScrollView.is_passing_cross_axis_drag
끈 방향이 이 뷰가 가져갈 드래그인지. (스크롤하지 않는 축의 드래그를 남기는 옵션을 켰을 때만 가려낸다)
Whether the drag direction is a drag this view should take. (only distinguishes when the option to leave drags on the non-scrolling axis is on)
- deltaXnumber
- 누른 자리에서 끈 가로 거리. (픽셀, 부호는 보지 않는다)Horizontal distance dragged from the pressed point. (pixels, the sign is ignored)
- deltaYnumber
- 누른 자리에서 끈 세로 거리. (픽셀, 부호는 보지 않는다)Vertical distance dragged from the pressed point. (pixels, the sign is ignored)
반환Returnsboolean 이 뷰가 가져가면 참. (옵션이 꺼졌거나 두 축 모두 스크롤하면 늘 참, 끌 수 있는 축이 없으면 거짓)True if this view takes it. (always true if the option is off or both axes scroll, false if no axis can be dragged)
짝Counterpart: vanilla-engine UIScrollView.is_scroll_drag
드래그 반영량 배율 설정. (1.0 = 기본, 2.0 = 두 배 빠르게)
Sets the drag amount multiplier. (1.0 = default, 2.0 = twice as fast)
- dragSensitivitynumber
- 드래그 반영량 배율. (끈 거리에 곱한다)Drag sensitivity multiplier. (multiplied by the dragged distance)
짝Counterpart: vanilla-engine UIScrollView.set_drag_sensitivity
드래그 반영량 배율 반환.
Returns the drag amount multiplier.
반환Returnsnumber 드래그 반영량 배율. (기본 1)Drag sensitivity multiplier. (default 1)
짝Counterpart: vanilla-engine UIScrollView.get_drag_sensitivity
스크롤 모드 설정.
Sets the scroll mode.
- scrollModestring
- "clamp" 면 경계에서 멈추고, "elastic" 이면 경계를 넘을 때 저항이 생기고 놓으면 튕겨 돌아온다."clamp" stops at the bounds, "elastic" resists past the bounds and springs back on release.
짝Counterpart: vanilla-engine UIScrollView.set_scroll_mode
스크롤 모드 반환.
Returns the scroll mode.
반환Returnsstring "clamp" 나 "elastic". (기본 "clamp")"clamp" or "elastic". (default "clamp")
짝Counterpart: vanilla-engine UIScrollView.get_scroll_mode
스크롤 콘텐츠 크기 설정. (가시 영역보다 크게 설정해야 스크롤 가능)
Sets the scroll content size. (must be set larger than the visible area to scroll)
- scrollContentSizeVector2
- 스크롤할 콘텐츠 크기. (픽셀, 복제해 콘텐츠 노드의 내용 크기에도 넣는다)Size of the content to scroll. (pixels, cloned and also set as the content node's content size)
짝Counterpart: vanilla-engine UIScrollView.set_scroll_content_size
스크롤 콘텐츠 크기 반환.
Returns the scroll content size.
반환ReturnsVector2 스크롤할 콘텐츠 크기. (픽셀)Size of the content to scroll. (pixels)
짝Counterpart: vanilla-engine UIScrollView.get_scroll_content_size
드래그 중 여부 반환.
Returns whether dragging.
반환Returnsboolean 누르고 있으면 참.True while pressed.
짝Counterpart: vanilla-engine UIScrollView.is_dragging
현재 스크롤 속도 반환.
Returns the current scroll velocity.
반환ReturnsVector2 스크롤 속도. (초당 픽셀, elastic 모드에서만 셈한다)Scroll velocity. (pixels per second, computed only in elastic mode)
짝Counterpart: vanilla-engine UIScrollView.get_scroll_velocity
세로 스크롤바 노출 여부 설정. true 면 자동 생성하여 호스트 노드의 자식으로 추가.
Sets whether to show the vertical scrollbar. If true, creates it automatically and adds it as a child of the host node.
- showsboolean
- 참이면 보인다. (노드에 붙기 전이면 스크롤바를 만들지 못한다)If true, it is shown. (the scroll bar cannot be created before attaching to a node)
짝Counterpart: vanilla-engine UIScrollView.set_shows_vertical_scroll_bar
가로 스크롤바 노출 여부 설정.
Sets whether to show the horizontal scrollbar.
- showsboolean
- 참이면 보인다. (처음 켤 때 만들어 노드의 자식으로 붙인다, 노드에 붙기 전이면 만들지 못한다)If true, it is shown. (created and added as a child of the node when first turned on, cannot be created before attaching to a node)
짝Counterpart: vanilla-engine UIScrollView.set_shows_horizontal_scroll_bar
세로 / 가로 스크롤바 인스턴스 반환. (커스터마이즈 용)
Returns the vertical / horizontal scrollbar instance. (for customization)
반환ReturnsUIScrollBar | null 세로 스크롤바. (한 번도 켜지 않았으면 null)Vertical scroll bar. (null if never turned on)
짝Counterpart: vanilla-engine UIScrollView.get_vertical_scroll_bar
가로 스크롤바 반환. (커스터마이즈 용)
Returns the horizontal scroll bar. (for customization)
반환ReturnsUIScrollBar | null 가로 스크롤바. (한 번도 켜지 않았으면 null)Horizontal scroll bar. (null if never turned on)
짝Counterpart: vanilla-engine UIScrollView.get_horizontal_scroll_bar
스크롤바가 차지하는(reserved) 영역의 두께. (스크롤바가 활성/표시 중일 때만)
Thickness of the area reserved by the scrollbar. (only while the scrollbar is active/shown)
반환Returnsnumber 세로 스크롤바가 차지하는 너비. (픽셀, 보일 때 24, 아니면 0)Width taken by the vertical scroll bar. (pixels, 24 when shown, otherwise 0)
짝Counterpart: vanilla-engine UIScrollView.get_vertical_scroll_bar_reserved_width
가로 스크롤바가 차지하는 영역의 두께. (스크롤바가 보일 때만)
Thickness of the area taken by the horizontal scroll bar. (only while the scroll bar is shown)
반환Returnsnumber 가로 스크롤바가 차지하는 높이. (픽셀, 보일 때 24, 아니면 0)Height taken by the horizontal scroll bar. (pixels, 24 when shown, otherwise 0)
짝Counterpart: vanilla-engine UIScrollView.get_horizontal_scroll_bar_reserved_height
스크롤바를 제외한 실제 콘텐트가 그려질 수 있는 가시 영역 크기.
- 가로 스크롤바가 있으면 그 만큼 세로가 줄고, 세로 스크롤바가 있으면 가로가 준다.
Visible area size where the actual content can be drawn, excluding scrollbars.
- If there is a horizontal scrollbar the height shrinks by that much, and if there is a vertical scrollbar the width shrinks.
반환ReturnsVector2 스크롤바 몫을 뺀 보이는 영역 크기. (픽셀, 노드에 붙기 전이면 0)Visible area size minus the scroll bars. (pixels, 0 before attaching to a node)
짝Counterpart: vanilla-engine UIScrollView.get_inner_content_size
매 tick 마다 스크롤바 위치 / 크기 갱신.
Updates the scrollbar position / size every tick.
휠 입력 처리. (TouchRaycaster → UIScrollView)
- delta: 마우스 휠 누적값 (DOM WheelEvent 의 deltaX/deltaY 와 동일 부호. 아래 = +y)
Handles wheel input. (TouchRaycaster → UIScrollView)
- delta: accumulated mouse wheel value (same sign as DOM WheelEvent's deltaX/deltaY. down = +y)
- deltaVector2
- 휠 누적값. (휠 스크롤 배율을 곱해 오프셋에서 뺀다, 없으면 아무것도 하지 않는다)Accumulated wheel delta. (multiplied by the wheel scroll scale and subtracted from the offset, does nothing if missing)
휠 스크롤 배율 설정.
Sets the wheel scroll multiplier.
- scalenumber
- 휠 누적값에 곱할 배율. (기본 1)Multiplier applied to the accumulated wheel delta. (default 1)
짝Counterpart: vanilla-engine UIScrollView.set_wheel_scroll_scale
ScrollModeenum
스크롤 모드.
- clamp: 경계를 초과하지 않는 기본 모드.
- elastic: 경계를 초과하면 저항이 생기고 놓으면 스프링처럼 튕겨 돌아오는 모드.
Scroll mode.
- clamp: the default mode that does not go past the bounds.
- elastic: resists past the bounds and springs back when released.
| 이름Name | 값Value | 설명Description |
|---|---|---|
clamp | clamp | 경계를 넘지 않게 자른다.Clamps at the bounds. |
elastic | elastic | 경계를 넘으면 저항이 생기고 놓으면 튕겨 돌아온다.Resists past the bounds and springs back on release. |