vanilladocs
vanillapunch.com
API / ui/uiscrollbar

ui/uiscrollbar

스크롤바.

Scroll bar.

UIScrollBarextends WorldNode

짝Counterpart: vanilla-engine UIScrollBar

스크롤바.

  • 대상 UIScrollView 의 스크롤 상태를 트랙(배경) + 썸(드래그 핸들)으로 표시한다.
  • 사용자가 썸 또는 트랙을 드래그하면 대상 UIScrollView 의 scrollOffset 을 직접 갱신.
  • 매 tick 에 대상의 offset / contentSize / 가시 영역을 읽어 썸 위치/크기를 갱신.

배치 주의:

  • 본 노드는 반드시 UIScrollView 가 attach 된 노드의 자식으로 두지 말 것. (TouchRecognizer 가 ancestor scrollview 를 찾아 드래그를 그쪽에 인계해 버린다.) 대신 sibling 으로 두어 raycast 결과가 ScrollBar 자신이 되도록 한다.

Scroll bar.

  • Displays the scroll state of the target UIScrollView as a track (background) + thumb (drag handle).
  • When the user drags the thumb or track, directly updates the target UIScrollView's scrollOffset.
  • Every tick, reads the target's offset / contentSize / visible area and updates the thumb position/size.

Placement note:

  • Never place this node as a child of the node with UIScrollView attached. (TouchRecognizer finds the ancestor scrollview and hands the drag over to it.) Instead place it as a sibling so the raycast result is the ScrollBar itself.
예제Example스크롤 뷰 옆에 세로 스크롤바 세우기Put a vertical scroll bar next to a scroll view
import { Engine, EngineConfiguration, UIScene, UIScrollView, UIScrollBar, ScrollBarAxis, WorldNode, Paint, Color, Pivot, Vector2 } from "./build/vanilla.js";

class ScrollBarScene extends UIScene {
	create() {
		super.create();
		const root = this.getRoot();
		const viewportNode = new WorldNode();
		viewportNode.setPivot(Pivot.topLeft.clone());
		viewportNode.setAnchor(Pivot.topLeft.clone());
		viewportNode.setContentSize(Vector2.create(300, 240));
		viewportNode.setLocalPosition(Vector2.create(160, 60));
		const scrollView = viewportNode.addComponent(UIScrollView);
		scrollView.setHorizontal(false);
		const rowCount = 24;
		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(300, rowHeight - 4));
			rowNode.setLocalPosition(Vector2.create(0, rowIndex * rowHeight));
			const rowPaint = rowNode.addComponent(Paint);
			rowPaint.setColor(new Color(0.2, 0.3 + (rowIndex % 2) * 0.1, 0.5, 1));
			content.addChild(rowNode);
		}
		scrollView.setScrollContentSize(Vector2.create(300, rowCount * rowHeight));
		root.addChild(viewportNode);

		const scrollBar = new UIScrollBar();
		scrollBar.setScrollView(scrollView);
		scrollBar.setAxis(ScrollBarAxis.vertical);
		scrollBar.setContentSize(Vector2.create(10, 240));
		scrollBar.setLocalPosition(Vector2.create(466, 60));
		scrollBar.setTrackColor(new Color(1, 1, 1, 0.1));
		scrollBar.setThumbColor(new Color(1, 1, 1, 0.7));
		scrollBar.setMinThumbSize(32);
		root.addChild(scrollBar);
	}
}

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const scene = new ScrollBarScene();
scene.setLoadingMinDurationMs(0);
engine.run(scene);
생성자constructorconstructor()#0.2.1 부터since 0.2.1소스source

생성.

Constructor.

짝Counterpart: vanilla-engine UIScrollBar.new

메서드methodsetScrollView(scrollView)#0.2.1 부터since 0.2.1소스source

대상 UIScrollView 설정.

Sets the target UIScrollView.

scrollViewUIScrollView | null
상태를 보이고 끌기로 오프셋을 바꿀 스크롤 뷰. (null 이면 썸을 끄고 눌러도 아무것도 하지 않는다)The scroll view whose state is shown and whose offset is changed by dragging. (null turns the thumb off and presses do nothing)

짝Counterpart: vanilla-engine UIScrollBar.set_scroll_view

메서드methodgetScrollView()#0.2.1 부터since 0.2.1소스source

대상 UIScrollView 반환. (TouchRecognizer 가 자기 스크롤바의 ancestor scroll view 인계 동작을 차단하는데 사용한다.)

Returns the target UIScrollView. (Used by TouchRecognizer to block the ancestor scroll view handover behavior for its own scroll bar.)

반환ReturnsUIScrollView | null setScrollView 로 준 스크롤 뷰. (주지 않았으면 null)The scroll view given to setScrollView. (null if none was given)

짝Counterpart: vanilla-engine UIScrollBar.get_scroll_view

메서드methodsetAxis(axis)#0.2.1 부터since 0.2.1소스source

축 설정. (ScrollBarAxis.vertical / horizontal)

Sets the axis. (ScrollBarAxis.vertical / horizontal)

axisstring
스크롤바 축. (ScrollBarAxis 값, 기본 vertical)Scroll bar axis. (A ScrollBarAxis value, default vertical)

짝Counterpart: vanilla-engine UIScrollBar.set_axis

메서드methodgetAxis()#0.4.0 부터since 0.4.0소스source

축 반환.

Returns the axis.

반환Returnsstring 스크롤바 축. (ScrollBarAxis 값)Scroll bar axis. (A ScrollBarAxis value)

짝Counterpart: vanilla-engine UIScrollBar.get_axis

메서드methodgetThumbRect()#0.4.0 부터since 0.4.0소스source

지금 썸 사각형. (스크롤바 노드 영역 안, 썸이 꺼져 있으면 null)

The current thumb rectangle. (Within the scroll bar node area, null if the thumb is off)

반환ReturnsRect | null 썸 사각형. (스크롤바 노드 로컬 좌표, 썸이 꺼져 있으면 null)Thumb rectangle. (Local coordinates of the scroll bar node, null when the thumb is off)

짝Counterpart: vanilla-engine UIScrollBar.get_thumb_rect

예제Example오프셋에 따라 썸이 트랙을 따라 내려가기The thumb moves down the track with the offset
import { UIScrollView, UIScrollBar, 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, 400));
const scrollBar = new UIScrollBar();
scrollBar.setScrollView(scrollView);
scrollBar.setContentSize(Vector2.create(8, 100));
scrollBar.tick(0);
const topThumbRect = scrollBar.getThumbRect();
scrollView.setScrollOffset(Vector2.create(0, -300));
scrollBar.tick(0);
const bottomThumbRect = scrollBar.getThumbRect();
console.log(topThumbRect.size.y, bottomThumbRect.position.y);
메서드methodsetTrackColor(color)#0.2.1 부터since 0.2.1소스source

트랙 색 설정.

Sets the track color.

colorColor | string
트랙(바탕) 색. (트랙 Paint 에 그대로 건다, 기본 검정 알파 0.15)Track (background) color. (Set on the track Paint as is, default black with alpha 0.15)

짝Counterpart: vanilla-engine UIScrollBar.set_track_color

메서드methodsetThumbColor(color)#0.2.1 부터since 0.2.1소스source

썸 색 설정.

Sets the thumb color.

colorColor | string
썸(끄는 손잡이) 색. (썸 노드 Paint 에 그대로 건다, 기본 흰색 알파 0.6)Thumb (drag handle) color. (Set on the thumb node Paint as is, default white with alpha 0.6)

짝Counterpart: vanilla-engine UIScrollBar.set_thumb_color

메서드methodgetTrackColor()#0.4.0 부터since 0.4.0소스source

트랙 색 반환. (트랙 Paint 의 색)

Returns the track color. (the color of the track Paint)

반환ReturnsColor 트랙 색. (트랙 Paint 가 쥔 색 그대로)Track color. (The color held by the track Paint, as is)

짝Counterpart: vanilla-engine UIScrollBar.get_track_color

메서드methodgetThumbColor()#0.4.0 부터since 0.4.0소스source

썸 색 반환. (썸 노드 Paint 의 색)

Returns the thumb color. (the color of the thumb node's Paint)

반환ReturnsColor 썸 색. (썸 노드 Paint 가 쥔 색 그대로)Thumb color. (The color held by the thumb node Paint, as is)

짝Counterpart: vanilla-engine UIScrollBar.get_thumb_color

메서드methodsetMinThumbSize(size)#0.2.1 부터since 0.2.1소스source

썸 최소 길이 설정.

Sets the minimum thumb length.

sizenumber
썸 길이의 하한. (픽셀, 기본 24, 콘텐트가 길어 썸이 이보다 짧아지면 이 길이로 둔다)Lower limit of the thumb length. (Pixels, default 24, when long content would make the thumb shorter it stays at this length)

짝Counterpart: vanilla-engine UIScrollBar.set_min_thumb_size

메서드methodsetAutoHide(autoHide)#0.2.1 부터since 0.2.1소스source

자동 숨김 설정. (콘텐트가 가시영역에 들어오면 트랙까지 숨김)

Sets auto hide. (Hides even the track when the content fits within the visible area)

autoHideboolean
참이면 스크롤할 것이 없을 때 트랙까지 숨긴다. (기본 참, 거짓이면 썸만 끈다, 노드는 켜 둔 채 숨겨 콘텐트가 길어지거나 끄면 다음 갱신에 다시 보인다)If true, hides the track as well when there is nothing to scroll. (default true; if false, only the thumb is turned off; the node stays active while hidden, so it shows again on the next update when the content grows or this is turned off)

짝Counterpart: vanilla-engine UIScrollBar.set_auto_hide

메서드methodisAutoHidden()#0.4.0 부터since 0.4.0소스source

자동 숨김으로 숨어 있는지 반환.

Return whether it is hidden by auto hide.

반환Returnsboolean 스크롤할 것이 없어 자동 숨김으로 트랙까지 숨어 있으면 참.True if the track is hidden by auto hide because there is nothing to scroll.

짝Counterpart: vanilla-engine UIScrollBar.is_auto_hidden

메서드methodisVisible()#0.4.0 부터since 0.4.0소스source

가시 상태 반환. (자동 숨김으로 숨어 있으면 거짓)

Return the visibility. (false while hidden by auto hide)

반환Returnsboolean 켜져 있고 로컬 투명도가 0 보다 크고 자동 숨김으로 숨지 않았으면 참.True if active, the local opacity is greater than 0, and it is not hidden by auto hide.

메서드methodcontains(viewPosition)#0.4.0 부터since 0.4.0소스source

자리가 노드 안인지. (자동 숨김으로 숨어 있으면 누름을 받지 않는다)

Whether a position is inside the node. (does not take presses while hidden by auto hide)

viewPositionVector2
볼 자리. (뷰 좌표)Position to test. (View coordinates)

반환Returnsboolean 노드 안이면 참. (자동 숨김으로 숨어 있으면 늘 거짓)True if inside the node. (always false while hidden by auto hide)

메서드methodtick(timeDelta)#0.2.1 부터since 0.2.1소스source

갱신.

Update.

timeDeltanumber
지난 프레임부터의 시간. (초, 노드 갱신에 넘기고 썸 자리를 다시 맞춘다)Time since the previous frame. (Seconds, passed on to the node update before the thumb position is fitted again)
메서드methodupdateThumb()#0.2.1 부터since 0.2.1소스source

트랙 길이 / 가시 영역 / 콘텐트 크기로부터 썸의 위치와 크기를 갱신.

Updates the thumb position and size from the track length / visible area / content size.

메서드methodapplyTrackHitPosition(viewInputPosition)#0.2.1 부터since 0.2.1소스source

트랙 좌표(view) 위치를 받아 콘텐트 오프셋을 갱신. 트랙 클릭 시 사용.

  • 썸 중앙이 클릭 위치에 오도록 진행도 계산.

Takes a position in track coordinates (view) and updates the content offset. Used on track click.

  • Computes the progress so the thumb center lands at the click position.
viewInputPositionVector2
누른 자리. (뷰 좌표, 스크롤바의 월드 위치를 빼서 트랙 위 자리로 본다)Pressed position. (View coordinates, the world position of the scroll bar is subtracted to get the position on the track)
메서드methodisInsideThumb(viewInputPosition)#0.2.1 부터since 0.2.1소스source

썸이 viewInputPosition 안에 있는지.

Whether viewInputPosition is on the thumb.

viewInputPositionVector2
볼 자리. (뷰 좌표)Position to test. (View coordinates)

반환Returnsboolean 썸 사각형 안이면 참. (가장자리도 든다)True if inside the thumb rectangle. (Edges included)

메서드methodtouchPress(viewInputPosition)#0.2.1 부터since 0.2.1소스source

터치 누름. (썸 hit 이면 그 자리에서 드래그 시작, 트랙 hit 이면 점프 후 드래그)

Touch press. (If the thumb is hit, starts dragging from there, if the track is hit, jumps then drags)

viewInputPositionVector2
누른 자리. (뷰 좌표)Press position. (view coordinates)
예제Example트랙 끝을 눌러 뛰고 썸을 끌어 올리기Jump by pressing the end of the track, then drag the thumb back up
import { UIScrollView, UIScrollBar, 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, 400));
const scrollBar = new UIScrollBar();
scrollBar.setScrollView(scrollView);
scrollBar.setContentSize(Vector2.create(8, 100));
scrollBar.tick(0);
scrollBar.touchPress(Vector2.create(4, 100));
const jumpedOffset = scrollView.getScrollOffset();
scrollBar.touchMove(Vector2.create(4, 62.5));
scrollBar.touchRelease(Vector2.create(4, 62.5));
const draggedOffset = scrollView.getScrollOffset();
console.log(jumpedOffset.y, draggedOffset.y);
메서드methodtouchMove(viewInputPosition)#0.2.1 부터since 0.2.1소스source

터치 이동.

Touch move.

viewInputPositionVector2
옮긴 자리. (뷰 좌표, 누른 자리부터 끈 길이를 트랙 대 콘텐트 비율로 오프셋에 옮긴다)Moved position. (View coordinates, the length dragged since the press is carried to the offset by the track to content ratio)
메서드methodtouchRelease(viewInputPosition)#0.2.1 부터since 0.2.1소스source

터치 뗌.

Touch release.

viewInputPositionVector2
뗀 자리. (뷰 좌표, 쓰지 않는다)Released position. (View coordinates, unused)
메서드methodtouchCancel(viewInputPosition)#0.2.1 부터since 0.2.1소스source

터치 취소.

Touch cancel.

viewInputPositionVector2
취소된 때의 자리. (뷰 좌표, 쓰지 않는다)Position at cancellation. (View coordinates, unused)

ScrollBarAxisenum

짝Counterpart: vanilla-engine ScrollBarAxis

스크롤바 축.

Scroll bar axis.

이름Name값Value설명Description
horizontalhorizontal가로 스크롤바. (트랙 너비를 따라 썸이 움직이고 가로 오프셋을 바꾼다)Horizontal scroll bar. (The thumb moves along the track width and changes the horizontal offset)
verticalvertical세로 스크롤바. (트랙 높이를 따라 썸이 움직이고 세로 오프셋을 바꾼다, 기본)Vertical scroll bar. (The thumb moves along the track height and changes the vertical offset, default)