ui/uislider
슬라이더 컨트롤.
Slider control.
UISliderextends UIControl
슬라이더 컨트롤.
- 사용자 입력(드래그/탭)으로 값을 조정한다. → UIControl 을 상속.
- 표시 부분(트랙/채움)은 UIProgressView 와 외관이 비슷하지만, 컨트롤 트리에 속해야 하므로 UIProgressView 를 상속하지 않고 직접 그린다.
- thumb 까지 추가로 그린다.
Slider control.
- Adjusts the value by user input (drag/tap). → inherits UIControl.
- The display part (track/fill) looks similar to UIProgressView, but since it must belong to the control tree it does not inherit UIProgressView and draws itself.
- Also draws the thumb.
import { Engine, EngineConfiguration, UIScene, UISlider, WorldNode, Pivot, Vector2 } from "./build/vanilla.js";
class MainScene extends UIScene {
constructor() {
super();
this.setLoadingMinDurationMs(0);
}
initialize(engine) {
super.initialize(engine);
const sliderNode = new WorldNode();
sliderNode.setPivot(Pivot.topLeft);
sliderNode.setAnchor(Pivot.topLeft);
sliderNode.setLocalPosition(Vector2.create(40, 60));
sliderNode.setContentSize(Vector2.create(240, 24));
const slider = sliderNode.addComponent(UISlider);
slider.setRange(0, 100);
slider.setValue(50);
slider.setTrackThickness(6);
slider.setCornerRadius(3);
slider.setThumbRadius(12);
slider.setValueChangedEvent((changedSlider) => {
console.log("volume", changedSlider.getValue());
});
const root = this.getRoot();
root.addChild(sliderNode);
console.log(slider.getValue(), slider.getRatio());
}
}
const engineConfiguration = new EngineConfiguration();
engineConfiguration.canvasId = "mainCanvas";
engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
engineConfiguration.autoResizeOnWindowResize = true;
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());노드에 붙음. (WorldNode 의 isInteractable 을 자동 활성화)
Attached to a node. (automatically enables the WorldNode's isInteractable)
- nodeComponentNode
- 붙을 노드.Node to attach to.
출력. (트랙 + 채움 + thumb)
Render. (track + fill + thumb)
- graphicGraphic
- 그래픽.Graphics.
그리는 사각형을 rect 에 적기. (오버라이드: 트랙과 채움은 내용 영역 안, 손잡이 원은 값이 움직이는 줄 전체에 반지름만큼 넘친다)
- 값에 따라 움직이는 손잡이가 어디에 있든 품도록 값과 상관없는 사각형을 알린다. (값을 바꿔도 경계를 다시 셈하지 않는다)
- 손잡이 노드를 정했으면 원을 그리지 않으므로 내용 영역만. 가장자리 매끄럽게 하기만큼 한 단위씩 넓혀 본다.
Writes the drawn rectangle to rect. (Override: the track and fill stay inside the content area, the thumb circle spills by its radius along the whole range it moves over)
- Reports a value-independent rectangle that covers the thumb wherever the value moves it. (Changing the value does not recalculate bounds)
- With a thumb node set, no circle is drawn, so only the content area. Grown by one unit for anti-aliasing.
- rectRect
- 그리는 사각형을 적을 곳. (노드 내용 영역의 왼쪽 위가 원점)Where to write the drawn rectangle. (origin at the top-left of the node's content area)
반환Returnsboolean 노드에 붙어 있으면 참.True if attached to a node.
import { WorldNode, UISlider, Rect, Vector2 } from "./build/vanilla.js";
const sliderNode = new WorldNode();
sliderNode.setContentSize(Vector2.create(200, 8));
const slider = sliderNode.addComponent(UISlider);
slider.setThumbRadius(12);
const drawnRect = Rect.zero();
slider.calculateDrawnRect(drawnRect);
console.log(drawnRect.position.x, drawnRect.position.y, drawnRect.size.x, drawnRect.size.y);터치 누름.
Touch press.
- viewInputPositionVector2
- 누른 자리. (뷰 좌표)Press position. (view coordinates)
터치 이동.
Touch move.
- viewInputPositionVector2
- 옮긴 자리. (뷰 좌표)Moved position. (view coordinates)
터치 뗌.
Touch release.
- viewInputPositionVector2
- 뗀 자리. (뷰 좌표)Release position. (view coordinates)
터치 취소.
Touch cancel.
- viewInputPositionVector2
- 취소된 때의 자리. (뷰 좌표)Position at cancel. (view coordinates)
값/범위/비율.
Value/range/ratio.
반환Returnsnumber 범위 안에서 값의 비율. (0 ~ 1, 범위가 0 이하면 0)Ratio of the value within the range. (0 ~ 1, 0 if the range is 0 or less)
짝Counterpart: vanilla-engine UISlider.get_ratio
값 설정. (범위 안으로 자른다, 값 바뀜 이벤트는 부르지 않는다)
Sets the value. (clamped to the range, does not call the value changed event)
- valuenumber
- 새 값. (minValue ~ maxValue)New value. (minValue ~ maxValue)
짝Counterpart: vanilla-engine UISlider.set_value
값 반환.
Returns the value.
반환Returnsnumber 지금 값. (기본 0)The current value. (default 0)
짝Counterpart: vanilla-engine UISlider.get_value
범위 설정. (지금 값도 새 범위 안으로 자른다)
Sets the range. (the current value is also clamped to the new range)
- minValuenumber
- 가장 작은 값. (기본 0)Minimum value. (default 0)
- maxValuenumber
- 가장 큰 값. (기본 1)Maximum value. (default 1)
짝Counterpart: vanilla-engine UISlider.set_range
가장 작은 값 반환.
Returns the minimum value.
반환Returnsnumber 가장 작은 값.Minimum value.
짝Counterpart: vanilla-engine UISlider.get_min_value
가장 큰 값 반환.
Returns the maximum value.
반환Returnsnumber 가장 큰 값.Maximum value.
짝Counterpart: vanilla-engine UISlider.get_max_value
외부 setValue 후 콜백을 강제 호출하고 싶을 때.
For when you want to force the callback after an external setValue.
짝Counterpart: vanilla-engine UISlider.fire_value_changed
트랙 색 설정.
Sets the track color.
- colorColor | string
- 트랙 색. (기본 new Color(0.7, 0.7, 0.7, 1))Track color. (default new Color(0.7, 0.7, 0.7, 1))
짝Counterpart: vanilla-engine UISlider.set_track_color
트랙 색 반환.
Returns the track color.
반환ReturnsColor 트랙 색.Track color.
짝Counterpart: vanilla-engine UISlider.get_track_color
채움 색 설정.
Sets the fill color.
- colorColor | string
- 값까지 채우는 색. (기본 new Color(0.23, 0.51, 0.96, 1))Color filled up to the value. (default new Color(0.23, 0.51, 0.96, 1))
짝Counterpart: vanilla-engine UISlider.set_fill_color
채움 색 반환.
Returns the fill color.
반환ReturnsColor 채움 색.Fill color.
짝Counterpart: vanilla-engine UISlider.get_fill_color
손잡이 색 설정.
Sets the thumb color.
- colorColor | string
- 손잡이 원의 색. (기본 흰색, 손잡이 노드를 정했으면 쓰지 않는다)Color of the thumb circle. (default white, unused if a thumb node is set)
짝Counterpart: vanilla-engine UISlider.set_thumb_color
손잡이 색 반환.
Returns the thumb color.
반환ReturnsColor 손잡이 원의 색.Color of the thumb circle.
짝Counterpart: vanilla-engine UISlider.get_thumb_color
손잡이 반지름 설정.
Set the thumb radius.
- radiusnumber
- 손잡이 원의 반지름. (기본 16, 손잡이 노드를 정했으면 쓰지 않는다)Radius of the thumb circle. (default 16, unused if a thumb node is set)
짝Counterpart: vanilla-engine UISlider.set_thumb_radius
손잡이 반지름 반환.
Returns the thumb radius.
반환Returnsnumber 손잡이 원의 반지름.Radius of the thumb circle.
짝Counterpart: vanilla-engine UISlider.get_thumb_radius
트랙 두께 설정. (노드 가운데에 이 두께로 그린다)
Sets the track thickness. (drawn at this thickness in the middle of the node)
- thicknessnumber
- 트랙 두께. (0 이하면 노드 전체, 기본 0)Track thickness. (the whole node if 0 or less, default 0)
짝Counterpart: vanilla-engine UISlider.set_track_thickness
트랙 두께 반환.
Returns the track thickness.
반환Returnsnumber 트랙 두께. (0 이면 노드 전체)Track thickness. (0 means the whole node)
짝Counterpart: vanilla-engine UISlider.get_track_thickness
손잡이 노드 설정. (정하면 원을 그리지 않고 이 노드를 손잡이 자리로 옮긴다)
Sets the thumb node. (when set, moves this node to the thumb position instead of drawing a circle)
- nodeWorldNode
- 손잡이로 쓸 노드. (슬라이더 노드의 자식, 왼쪽 위 피봇과 앵커로 둔다, null 이면 원을 그린다)Node to use as the thumb. (a child of the slider node with top-left pivot and anchor, a circle is drawn if null)
짝Counterpart: vanilla-engine UISlider.set_thumb_node
import { Engine, EngineConfiguration, UIScene, UISlider, Paint, WorldNode, Pivot, Vector2, Color } from "./build/vanilla.js";
class MainScene extends UIScene {
constructor() {
super();
this.setLoadingMinDurationMs(0);
}
initialize(engine) {
super.initialize(engine);
const sliderNode = new WorldNode();
sliderNode.setPivot(Pivot.topLeft);
sliderNode.setAnchor(Pivot.topLeft);
sliderNode.setLocalPosition(Vector2.create(40, 60));
sliderNode.setContentSize(Vector2.create(240, 24));
const slider = sliderNode.addComponent(UISlider);
slider.setTrackThickness(4);
const thumbNode = new WorldNode();
thumbNode.setPivot(Pivot.topLeft);
thumbNode.setAnchor(Pivot.topLeft);
thumbNode.setContentSize(Vector2.create(20, 28));
const thumbPaint = thumbNode.addComponent(Paint);
thumbPaint.setColor(new Color(1, 0.6, 0.2, 1));
thumbPaint.setRoundSize(6);
sliderNode.addChild(thumbNode);
slider.setThumbNode(thumbNode);
slider.setValue(0.3);
const root = this.getRoot();
root.addChild(sliderNode);
}
}
const engineConfiguration = new EngineConfiguration();
engineConfiguration.canvasId = "mainCanvas";
engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
engineConfiguration.autoResizeOnWindowResize = true;
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());손잡이 노드 반환.
Returns the thumb node.
반환ReturnsWorldNode 손잡이 노드. (없으면 null)Thumb node. (null if none)
짝Counterpart: vanilla-engine UISlider.get_thumb_node
모서리 둥글기 설정.
Sets the corner roundness.
- radiusnumber
- 트랙과 채움의 모서리 반지름. (0 이하면 각진 사각형, 기본 0)Corner radius of the track and fill. (square corners if 0 or less, default 0)
짝Counterpart: vanilla-engine UISlider.set_corner_radius
모서리 둥글기 반환.
Returns the corner roundness.
반환Returnsnumber 트랙과 채움의 모서리 반지름.Corner radius of the track and fill.
짝Counterpart: vanilla-engine UISlider.get_corner_radius
방향 설정.
Sets the direction.
- directionstring
- 방향. (horizontal 이면 왼쪽에서 오른쪽, vertical 이면 아래에서 위로 찬다, 기본 horizontal)Direction. (horizontal fills left to right, vertical fills bottom to top, default horizontal)
짝Counterpart: vanilla-engine UISlider.set_direction
방향 반환.
Returns the direction.
반환Returnsstring 방향. (horizontal 이나 vertical)Direction. (horizontal or vertical)
짝Counterpart: vanilla-engine UISlider.get_direction
콜백 / 인터랙션.
Callback / interaction.
- callback(slider: UISlider) => void
- 누르거나 끌어 값이 바뀌면 부를 함수. (인자는 이 슬라이더, setValue 로 바꿀 때는 부르지 않는다, null 이면 부르지 않는다)Function called when pressing or dragging changes the value. (the argument is this slider, not called when changed with setValue, not called if null)
짝Counterpart: vanilla-engine UISlider.set_value_changed_event
값 바뀜 이벤트 반환.
Returns the value changed event.
반환Returns(slider: UISlider) => void 값 바뀜 이벤트 함수. (없으면 null)Value changed event function. (null if none)
짝Counterpart: vanilla-engine UISlider.get_value_changed_event
입력 받기 설정.
Sets whether it accepts input.
- isInteractableboolean
- 거짓이면 새 누름을 받지 않는다. (기본 참)If false, new presses are ignored. (default true)
짝Counterpart: vanilla-engine UISlider.set_interactable
입력 받기 여부 반환.
Returns whether it accepts input.
반환Returnsboolean 누름을 받으면 참.True if it accepts presses.
짝Counterpart: vanilla-engine UISlider.get_interactable
끄는 중인지.
Whether it is being dragged.
반환Returnsboolean 누른 뒤 떼거나 취소하기 전까지 참.True from press until release or cancel.
짝Counterpart: vanilla-engine UISlider.is_dragging