ui/uitogglebutton
토글 버튼 컴포넌트.
Toggle button component.
UIToggleButtonextends UIButton
토글 버튼 컴포넌트.
Toggle button component.
import { Engine, EngineConfiguration, UIScene, UIToggleButton, UILabel, Paint, WorldNode, Pivot, Vector2, Color } from "./build/vanilla.js";
class MainScene extends UIScene {
constructor() {
super();
this.setLoadingMinDurationMs(0);
}
initialize(engine) {
super.initialize(engine);
const toggleNode = new WorldNode();
toggleNode.setPivot(Pivot.topLeft);
toggleNode.setAnchor(Pivot.topLeft);
toggleNode.setLocalPosition(Vector2.create(40, 40));
toggleNode.setContentSize(Vector2.create(180, 56));
const paint = toggleNode.addComponent(Paint);
paint.setColor(new Color(0.25, 0.6, 0.35, 1));
paint.setRoundSize(12);
const label = toggleNode.addComponent(UILabel);
label.setText("Sound");
label.setFontSize(20);
const toggleButton = toggleNode.addComponent(UIToggleButton);
toggleButton.setOnTintColor(new Color(0, 0, 0, 0.4));
toggleButton.setToggledEvent((button) => {
console.log("sound on", button.getIsOn());
});
const root = this.getRoot();
root.addChild(toggleNode);
toggleButton.setIsOn(true);
}
}
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());틴트 트랜지션 갱신 (오버라이드: 켜짐 상태 고정).
Updates the tint transition (override: held fixed in the on state).
- timeDeltanumber
- 지난 프레임부터의 시간. (초)Time since the last frame. (Seconds)
클릭 이벤트 설정 (오버라이드: 외부 콜백 별도 저장).
Sets the click event (override: stores the external callback separately).
- callbackfunction(UIToggleButton): void
- 클릭으로 켜짐이 바뀐 뒤 부를 함수. (토글 이벤트 다음에 부른다, null 이면 부르지 않는다)Function called after a click changes the on state. (called after the toggled event, not called if null)
짝Counterpart: vanilla-engine UIToggleButton.set_clicked_event
켜짐 여부 설정.
Sets whether on.
- isOnboolean
- 켜짐 여부. (토글 이벤트와 클릭 이벤트는 부르지 않는다)Whether it is on. (the toggled and clicked events are not called)
짝Counterpart: vanilla-engine UIToggleButton.set_is_on
켜짐 여부 반환.
Returns whether on.
반환Returnsboolean 켜져 있으면 참.True if enabled.
짝Counterpart: vanilla-engine UIToggleButton.get_is_on
켜짐 틴트 색상 설정.
Sets the on tint color.
- colorColor | string
- 켜져 있을 때 덮을 틴트 색. (눌림 틴트 색도 이 색이 된다, 기본 new Color(0, 0, 0, 0.3))Tint color applied while on. (the pressed tint color becomes this color too, default new Color(0, 0, 0, 0.3))
짝Counterpart: vanilla-engine UIToggleButton.set_on_tint_color
켜짐 틴트 색상 반환.
Returns the on tint color.
반환ReturnsColor 켜짐 틴트 색.On tint color.
짝Counterpart: vanilla-engine UIToggleButton.get_on_tint_color
토글 이벤트 설정.
Sets the toggle event.
- callbackfunction(UIToggleButton): void
- 클릭으로 켜짐이 바뀌면 부를 함수. (인자는 이 버튼, null 이면 부르지 않는다)Function called when a click changes the on state. (the argument is this button, not called if null)
짝Counterpart: vanilla-engine UIToggleButton.set_toggled_event
토글 이벤트 반환.
Returns the toggle event.
반환Returnsfunction(UIToggleButton): void 토글 이벤트 함수. (없으면 null)Toggled event function. (null if none)
짝Counterpart: vanilla-engine UIToggleButton.get_toggled_event