ui/uibutton
버튼. (원본 ui/uibutton.js 의 UIButton, ButtonState)
- 누름 / 뗌 / 취소 / 클릭 / 길게 누름 / 마우스 오버 이벤트와, 누르거나 올렸을 때 색이 변하는 틴트 트랜지션.
- 클릭은 눌렀다가 버튼 영역 안에서 뗄 때만 일어난다. (길게 누름이 발화한 누름은 클릭을 삼킨다)
- 틴트는 원본처럼 호스트 노드와 모든 자손의 Sprite / UIImageView(덮는 색), Paint / Text / UILabel(원래 색 보간)에 건다. 호스트 노드의 다른 컴포넌트는 tick / 터치 중에 형제로 찾는다. (NodeTree 가 부르는 컴포넌트만 잠깐 꺼낸다) 원본은 Sprite 가 Paint 를 상속해 getComponents(Paint) 에도 잡힌다. 그래서 스프라이트에는 덮는 색 다음에 원래 색 보간이 한 번 더 걸려 뒤의 것이 이긴다. 같은 결과를 내려고 러스트 판도 스프라이트(와 UIImageView 의 스프라이트)를 두 번 담는다.
- 원본과 다른 것:
- 이벤트는
Box<dyn FnMut(&mut UIButton, &mut ComponentContext)>다. 원본 콜백은 버튼만 받는다. 문맥을 함께 넘겨 콜백에서 다른 노드를 바꾸거나 만들고 지울 수 있게 했다. (클릭 이벤트의 bool 반환은 원본에서도 쓰지 않아 뺐다) 받은 이벤트는Rc<RefCell>에 담는다. 이벤트 getter 는 그 Rc 를 돌려주고, 부르는 쪽은 borrow_mut 로 빌려 버튼과 문맥을 넘겨 부른다. 부르는 동안 같은 이벤트를 다시 부르면(콜백 안에서 fire_click_events 같은) 이미 빌려 있어 건너뛴다. - 원본 setInteractable / UIToggleButton.set_is_on 은 그 자리에서 색 대상을 모으고 틴트를 건다. 러스트 판은 노드에 닿을 수 없는 자리라 다음 tick 에 모으고 건다. (tick 이 매 프레임 틴트를 다시 거므로 보이는 결과는 같다)
- 제외 컴포넌트는 인스턴스 대신 (노드, 컴포넌트 타입) 으로 정한다:
exclude_component_from_tint::<Paint>(node_id). - setStateEvent(원본도 빈 함수)는 옮기지 않았다.
- attach_to_tree 에서 호스트 노드를 interactable 로 켠다. node_tree.add_component(node_id, UIButton::new()) 로 붙인다.
Button. (UIButton, ButtonState of the original ui/uibutton.js)
- Press / release / cancel / click / long press / mouse over events, and a tint transition that changes color when pressed or hovered.
- A click happens only when pressed and then released inside the button area. (a press that fired a long press swallows the click)
- As in the original, the tint applies to Sprite / UIImageView (cover color) and Paint / Text / UILabel (original color interpolation) of the host node and all descendants. Other components of the host node are found as siblings during tick / touch. (NodeTree briefly takes out only the component it is calling) In the original, Sprite inherits Paint, so it is also caught by getComponents(Paint). So sprites get the original color interpolation once more after the cover color, and the later one wins. To produce the same result, the Rust version also holds sprites (and UIImageView's sprites) twice.
- Differences from the original:
- Events are
Box<dyn FnMut(&mut UIButton, &mut ComponentContext)>. Original callbacks take only the button. The context is passed along so callbacks can change, create, and delete other nodes. (the bool return of click events was dropped because the original never used it either) Received events are stored inRc<RefCell>. Event getters return that Rc, and the caller borrows it with borrow_mut and calls it with the button and the context. If the same event is called again while it is being called (like fire_click_events inside the callback), it is skipped because it is already borrowed. - The original setInteractable / UIToggleButton.set_is_on gather the color targets and apply the tint on the spot. The Rust version cannot reach the nodes there, so it gathers and applies them on the next tick. (tick reapplies the tint every frame, so the visible result is the same)
- Excluded components are specified by (node, component type) instead of instance:
exclude_component_from_tint::<Paint>(node_id). - setStateEvent (an empty function in the original too) was not ported.
- attach_to_tree turns the host node interactable. Attach with node_tree.add_component(node_id, UIButton::new()).
UIButtonEventtype
버튼 이벤트. (버튼과 문맥을 받는다)
Button event. (takes the button and the context)
pub type UIButtonEvent = Box<dyn FnMut(&mut UIButton, &mut ComponentContext)>UIButtonstruct traits Default, Component
버튼.
Button.
use std::cell::Cell;
use std::rc::Rc;
use vanilla::{ComponentContext, Engine, EngineConfiguration, NodeTree, Paint, Text, TouchKind, UIButton, Vector2};
let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let button_id = node_tree.create_child(root_id, "OkButton");
node_tree[button_id].set_local_position(Vector2::create(200.0, 100.0));
node_tree[button_id].set_content_size(Vector2::create(160.0, 48.0));
node_tree[button_id].add_component(Paint::create_with_color("#3b82f6"));
node_tree[button_id].add_component(Text::create_with_text("OK", 24.0));
let click_count = Rc::new(Cell::new(0));
let click_count_for_event = click_count.clone();
let button = node_tree.add_component(button_id, UIButton::new()).expect("button");
button.set_click_event(Box::new(move |_button: &mut UIButton, _context: &mut ComponentContext| {
click_count_for_event.set(click_count_for_event.get() + 1);
}));
assert!(node_tree[button_id].is_interactable());
let inside = Vector2::create(210.0, 105.0);
node_tree.dispatch_touch(button_id, &engine, TouchKind::Press, inside);
node_tree.dispatch_touch(button_id, &engine, TouchKind::Release, inside);
assert_eq!(click_count.get(), 1);
let outside = Vector2::create(400.0, 105.0);
node_tree.dispatch_touch(button_id, &engine, TouchKind::Press, inside);
node_tree.dispatch_touch(button_id, &engine, TouchKind::Release, outside);
assert_eq!(click_count.get(), 1);생성.
- 트리에 붙이려면 node_tree.add_component(node_id, UIButton::new()) 를 쓴다. (붙을 때 컨텐트 노드를 만들고 호스트 노드를 interactable 로 켠다)
Constructor.
- To attach to a tree, use node_tree.add_component(node_id, UIButton::new()). (on attach, creates the content node and turns the host node interactable)
반환ReturnsUIButton 이벤트가 없는 새 버튼. (길게 누름 0.5 초, 최소 눌림 0 초, 눌림 틴트 검정 알파 0.3, 오버 틴트 흰색 알파 0.12, 트랜지션 0.3 초)New button with no events. (long press 0.5 seconds, minimum press 0 seconds, pressed tint black alpha 0.3, over tint white alpha 0.12, transition 0.3 seconds)
짝Counterpart: vanilla.js UIButton.constructor
품은 컨트롤 반환.
Returns the embedded control.
반환Returns&UIControl 품은 UIControl.The embedded UIControl.
품은 컨트롤 반환. (변경용)
Returns the embedded control. (mutable)
반환Returns&mut UIControl 품은 UIControl.The embedded UIControl.
컨텐트 노드 핸들.
Content node handle.
반환ReturnsOption<NodeId> 호스트 노드 밑에 만든 컨텐트 노드. 트리에 붙기 전이면 None.Content node created under the host node. None before being attached to a tree.
짝Counterpart: vanilla.js UIView.getContent
트랜지션 대상에서 노드를 제외. (그 노드와 모든 자손의 컴포넌트가 색 대상에서 빠진다)
- 다음에 색 대상을 모을 때(누름, 오버, 사용 불가)부터 빠진다.
Excludes a node from the transition targets. (components of that node and all its descendants drop out of the color targets)
- Takes effect the next time color targets are gathered (press, over, disabled).
- node_idNodeId
- 틴트에서 뺄 노드. (이미 든 노드면 그대로)Node to exclude from the tint. (unchanged if already included)
짝Counterpart: vanilla.js UIButton.excludeNodeFromTint
use vanilla::{Color, Engine, EngineConfiguration, NodeTree, Paint, TouchKind, UIButton, Vector2};
let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let button_id = node_tree.create_child(root_id, "Button");
node_tree[button_id].set_content_size(Vector2::create(100.0, 40.0));
node_tree[button_id].add_component(Paint::create_with_color(Color::white()));
let badge_id = node_tree.create_child(button_id, "Badge");
node_tree[badge_id].add_component(Paint::create_with_color(Color::white()));
let button = node_tree.add_component(button_id, UIButton::new()).expect("button");
button.exclude_node_from_tint(badge_id);
node_tree.dispatch_touch(button_id, &engine, TouchKind::Press, Vector2::zero());
node_tree.tick(&engine, 0.3);
let button_color = node_tree[button_id].get_component::<Paint>().expect("paint").get_color();
let badge_color = node_tree[badge_id].get_component::<Paint>().expect("paint").get_color();
assert!((button_color.red - 0.7).abs() < 0.001);
assert_eq!(badge_color, Color::white());트랜지션 대상에서 그 노드의 T 타입 컴포넌트만 제외. (원본은 컴포넌트 인스턴스를 받는다)
- 다음에 색 대상을 모을 때부터 빠진다. 자손 노드의 T 는 빠지지 않는다.
Excludes only the T-type components of that node from the transition targets. (the original takes a component instance)
- Takes effect the next time color targets are gathered. T on descendant nodes is not excluded.
- node_idNodeId
- T 타입 컴포넌트를 뺄 노드. (호스트 노드나 그 자손)Node whose T-type component to exclude. (the host node or one of its descendants)
짝Counterpart: vanilla.js UIButton.excludeComponentFromTint
use vanilla::{Color, Engine, EngineConfiguration, NodeTree, Paint, Text, TouchKind, UIButton, Vector2};
let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let button_id = node_tree.create_child(root_id, "Button");
node_tree[button_id].set_content_size(Vector2::create(100.0, 40.0));
node_tree[button_id].add_component(Paint::create_with_color(Color::white()));
node_tree[button_id].add_component(Text::create_with_text("OK", 20.0));
let button = node_tree.add_component(button_id, UIButton::new()).expect("button");
button.exclude_component_from_tint::<Paint>(button_id);
node_tree.dispatch_touch(button_id, &engine, TouchKind::Press, Vector2::zero());
node_tree.tick(&engine, 0.3);
let paint_color = node_tree[button_id].get_component::<Paint>().expect("paint").get_color();
let text_color = node_tree[button_id].get_component::<Text>().expect("text").get_text_color();
assert_eq!(paint_color, Color::white());
assert!(text_color.red < 1.0);제외 목록 비우기.
Clears the exclusion list.
짝Counterpart: vanilla.js UIButton.clearTintExclusions
클릭 알림만 부르기. (누르지 않고 클릭이 난 것처럼 Clicked, Click 차례로, UIHitArea 가 넓힌 자리의 클릭을 넘길 때)
- 지금 부르는 중인 이벤트는 건너뛴다. (클릭됨 이벤트 안에서 부르면 클릭만 한 번 더 불린다)
Fires only the click notifications. (Clicked, then Click, as if clicked without pressing, for forwarding a click on the area widened by UIHitArea)
- An event currently being called is skipped. (calling it inside the clicked event fires only the click once more)
- context&mut ComponentContext
- 이 버튼 노드의 문맥. (이벤트에 그대로 넘긴다)Context of this button node. (passed straight to the events)
짝Counterpart: vanilla.js UIButton.fireClickEvents
use std::cell::Cell;
use std::rc::Rc;
use vanilla::{ComponentContext, Engine, EngineConfiguration, NodeTree, TouchKind, UIButton, Vector2};
let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let button_id = node_tree.create_child(root_id, "Button");
let click_count = Rc::new(Cell::new(0));
let click_count_for_event = click_count.clone();
let button = node_tree.add_component(button_id, UIButton::new()).expect("button");
button.set_click_event(Box::new(move |_button: &mut UIButton, _context: &mut ComponentContext| {
click_count_for_event.set(click_count_for_event.get() + 1);
}));
let relay_id = node_tree.create_child(root_id, "Relay");
node_tree[relay_id].set_content_size(Vector2::create(40.0, 40.0));
let relay_button = node_tree.add_component(relay_id, UIButton::new()).expect("relay");
relay_button.set_click_event(Box::new(move |_relay_button: &mut UIButton, context: &mut ComponentContext| {
context.with_component_mut::<UIButton, ()>(button_id, |button, button_context| {
button.fire_click_events(button_context);
});
}));
node_tree.dispatch_touch(relay_id, &engine, TouchKind::Press, Vector2::zero());
node_tree.dispatch_touch(relay_id, &engine, TouchKind::Release, Vector2::zero());
assert_eq!(click_count.get(), 1);버튼 상태 설정.
Sets the button state.
- button_stateButtonState
- 새 상태. (이벤트를 부르거나 틴트를 다시 걸지 않는다)New state. (does not fire events or reapply the tint)
짝Counterpart: vanilla.js UIButton.setButtonState
버튼 상태 반환.
Returns the button state.
반환ReturnsButtonState 지금 상태.The current state.
짝Counterpart: vanilla.js UIButton.getButtonState
길게 누름 이벤트 설정. (임계 시간을 넘기면 한 번 알리고, 그 누름의 클릭은 삼킨다)
- 임계 시간은 set_long_press_seconds 로 정한다. 시간은 tick 에서 센다.
Sets the long press event. (notifies once past the threshold time and swallows that press's click)
- The threshold time is set with set_long_press_seconds. Time is counted in tick.
- long_pressed_eventUIButtonEvent
- 길게 누름이 되었을 때 부를 함수. (버튼과 문맥을 받는다)Function called on a long press. (takes the button and the context)
짝Counterpart: vanilla.js UIButton.setLongPressedEvent
use std::cell::Cell;
use std::rc::Rc;
use vanilla::{ComponentContext, Engine, EngineConfiguration, NodeTree, TouchKind, UIButton, Vector2};
let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let button_id = node_tree.create_child(root_id, "Slot");
node_tree[button_id].set_content_size(Vector2::create(80.0, 80.0));
let delete_count = Rc::new(Cell::new(0));
let open_count = Rc::new(Cell::new(0));
let delete_count_for_event = delete_count.clone();
let open_count_for_event = open_count.clone();
let button = node_tree.add_component(button_id, UIButton::new()).expect("button");
button.set_long_press_seconds(0.5);
button.set_long_pressed_event(Box::new(move |_button: &mut UIButton, _context: &mut ComponentContext| {
delete_count_for_event.set(delete_count_for_event.get() + 1);
}));
button.set_click_event(Box::new(move |_button: &mut UIButton, _context: &mut ComponentContext| {
open_count_for_event.set(open_count_for_event.get() + 1);
}));
node_tree.dispatch_touch(button_id, &engine, TouchKind::Press, Vector2::zero());
node_tree.tick(&engine, 0.3);
node_tree.tick(&engine, 0.3);
node_tree.dispatch_touch(button_id, &engine, TouchKind::Release, Vector2::zero());
assert_eq!(delete_count.get(), 1);
assert_eq!(open_count.get(), 0);
node_tree.dispatch_touch(button_id, &engine, TouchKind::Press, Vector2::zero());
node_tree.tick(&engine, 0.1);
node_tree.dispatch_touch(button_id, &engine, TouchKind::Release, Vector2::zero());
assert_eq!(delete_count.get(), 1);
assert_eq!(open_count.get(), 1);이번 누름이 이어진 시간 반환. (누르고 있지 않으면 0. 게이지 연출용)
Returns how long the current press has lasted. (0 if not pressing. for gauge effects)
반환Returnsf64 누른 뒤 지난 초. (tick 에서 쌓는다, 누르고 있지 않으면 0)Seconds since the press. (accumulated in tick, 0 if not pressing)
짝Counterpart: vanilla.js UIButton.getPressedElapsedSeconds
길게 누름 판정 시간 설정. (초)
Sets the long press threshold time. (seconds)
- long_press_secondsf64
- 누름이 이만큼 이어지면 길게 누름으로 본다. (초, 기본 0.5)A press lasting this long counts as a long press. (seconds, default 0.5)
짝Counterpart: vanilla.js UIButton.setLongPressSeconds
길게 누름 판정 시간 반환.
Returns the long press threshold time.
반환Returnsf64 길게 누름 판정 시간. (초)Long press threshold time. (seconds)
짝Counterpart: vanilla.js UIButton.getLongPressSeconds
최소 눌림 표시 시간 설정. (짧게 눌러도 이 시간만큼 눌린 모습을 보인 뒤 클릭한다. 기본 0 = 바로)
- 시간을 못 채운 뗌은 미뤄 두었다가 tick 에서 처리하고, 그동안 상태는 Pressed 다.
Sets the minimum pressed display time. (even a short press shows the pressed look for this long before clicking. default 0 = immediate)
- A release before the time is up is deferred and handled in tick, and the state stays Pressed meanwhile.
- minimum_pressed_secondsf64
- 최소 눌림 표시 시간. (초, 0 보다 작으면 0)Minimum pressed display time. (seconds, 0 if less than 0)
짝Counterpart: vanilla.js UIButton.setMinimumPressedSeconds
use std::cell::Cell;
use std::rc::Rc;
use vanilla::{ButtonState, ComponentContext, Engine, EngineConfiguration, NodeTree, TouchKind, UIButton, Vector2};
let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let button_id = node_tree.create_child(root_id, "Button");
node_tree[button_id].set_content_size(Vector2::create(100.0, 40.0));
let click_count = Rc::new(Cell::new(0));
let click_count_for_event = click_count.clone();
let button = node_tree.add_component(button_id, UIButton::new()).expect("button");
button.set_minimum_pressed_seconds(0.2);
button.set_click_event(Box::new(move |_button: &mut UIButton, _context: &mut ComponentContext| {
click_count_for_event.set(click_count_for_event.get() + 1);
}));
node_tree.dispatch_touch(button_id, &engine, TouchKind::Press, Vector2::zero());
node_tree.dispatch_touch(button_id, &engine, TouchKind::Release, Vector2::zero());
let button_state = node_tree[button_id].get_component::<UIButton>().expect("button").get_button_state();
assert_eq!(button_state, ButtonState::Pressed);
assert_eq!(click_count.get(), 0);
node_tree.tick(&engine, 0.25);
assert_eq!(click_count.get(), 1);최소 눌림 표시 시간 반환.
Returns the minimum pressed display time.
반환Returnsf64 최소 눌림 표시 시간. (초, 기본 0)Minimum pressed display time. (seconds, default 0)
짝Counterpart: vanilla.js UIButton.getMinimumPressedSeconds
클릭 이벤트 설정. (클릭됨 이벤트 다음에 불린다)
- 클릭은 눌렀다가 버튼 영역 안에서 뗄 때만 난다. 길게 누름이 발화한 누름은 클릭을 삼킨다.
Sets the click event. (called after the clicked event)
- A click happens only when pressed and then released inside the button area. A press that fired a long press swallows the click.
- click_eventUIButtonEvent
- 클릭할 때 부를 함수. (버튼과 문맥을 받는다, 문맥으로 다른 노드를 바꿀 수 있다)Function called on click. (takes the button and the context, the context can change other nodes)
짝Counterpart: vanilla.js UIButton.setClickEvent
use vanilla::{ComponentContext, Engine, EngineConfiguration, NodeTree, TouchKind, UIButton, Vector2};
let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let panel_id = node_tree.create_child(root_id, "Panel");
let close_id = node_tree.create_child(root_id, "Close");
node_tree[close_id].set_content_size(Vector2::create(40.0, 40.0));
let close_button = node_tree.add_component(close_id, UIButton::new()).expect("button");
close_button.set_click_event(Box::new(move |_button: &mut UIButton, context: &mut ComponentContext| {
context.get_node_tree_mut()[panel_id].set_visible(false);
}));
node_tree.dispatch_touch(close_id, &engine, TouchKind::Press, Vector2::zero());
node_tree.dispatch_touch(close_id, &engine, TouchKind::Release, Vector2::zero());
assert!(!node_tree[panel_id].is_visible());클릭 이벤트 반환. (부를 때는 borrow_mut 로 빌린다)
Returns the click event. (borrow it with borrow_mut to call it)
반환ReturnsOption<Rc<RefCell<UIButtonEvent>>> 건 클릭 이벤트. 걸지 않았으면 None.The set click event. None if not set.
짝Counterpart: vanilla.js UIButton.getClickEvent
use std::cell::Cell;
use std::rc::Rc;
use vanilla::{ComponentContext, Engine, EngineConfiguration, NodeTree, TouchKind, UIButton, Vector2};
let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let button_id = node_tree.create_child(root_id, "Button");
let click_count = Rc::new(Cell::new(0));
let click_count_for_event = click_count.clone();
let button = node_tree.add_component(button_id, UIButton::new()).expect("button");
assert!(button.get_click_event().is_none());
button.set_click_event(Box::new(move |_button: &mut UIButton, _context: &mut ComponentContext| {
click_count_for_event.set(click_count_for_event.get() + 1);
}));
button.set_pressed_event(Box::new(|button: &mut UIButton, context: &mut ComponentContext| {
if let Some(click_event) = button.get_click_event() {
(*click_event.borrow_mut())(button, context);
}
}));
node_tree.dispatch_touch(button_id, &engine, TouchKind::Press, Vector2::zero());
assert_eq!(click_count.get(), 1);누름 이벤트 설정.
Sets the press event.
- pressed_eventUIButtonEvent
- 누를 때 부를 함수. (버튼과 문맥을 받는다, 누를 수 없으면 불리지 않는다)Function called on press. (takes the button and the context, not called if not pressable)
짝Counterpart: vanilla.js UIButton.setPressedEvent
누름 이벤트 반환. (부를 때는 borrow_mut 로 빌린다)
Returns the press event. (borrow it with borrow_mut to call it)
반환ReturnsOption<Rc<RefCell<UIButtonEvent>>> 건 누름 이벤트. 걸지 않았으면 None.The set press event. None if not set.
짝Counterpart: vanilla.js UIButton.getPressedEvent
뗌 이벤트 설정. (영역 밖에서 떼도 불린다)
Sets the release event. (called even when released outside the area)
- released_eventUIButtonEvent
- 뗄 때 부를 함수. (버튼과 문맥을 받는다, 클릭됨, 클릭 이벤트보다 먼저 불리고 취소에는 불리지 않는다)Function called on release. (takes the button and the context, called before the clicked and click events, not called on cancel)
짝Counterpart: vanilla.js UIButton.setReleasedEvent
뗌 이벤트 반환. (부를 때는 borrow_mut 로 빌린다)
Returns the release event. (borrow it with borrow_mut to call it)
반환ReturnsOption<Rc<RefCell<UIButtonEvent>>> 건 뗌 이벤트. 걸지 않았으면 None.The set release event. None if not set.
짝Counterpart: vanilla.js UIButton.getReleasedEvent
클릭됨 이벤트 설정.
Sets the clicked event.
- clicked_eventUIButtonEvent
- 클릭할 때 클릭 이벤트보다 먼저 부를 함수. (버튼과 문맥을 받는다)Function called before the click event on click. (takes the button and the context)
짝Counterpart: vanilla.js UIButton.setClickedEvent
클릭됨 이벤트 반환. (부를 때는 borrow_mut 로 빌린다)
Returns the clicked event. (borrow it with borrow_mut to call it)
반환ReturnsOption<Rc<RefCell<UIButtonEvent>>> 건 클릭됨 이벤트. 걸지 않았으면 None.The set clicked event. None if not set.
짝Counterpart: vanilla.js UIButton.getClickedEvent
오버 틴트 색 설정.
Sets the over tint color.
- colorimpl Into<Color>
- 마우스를 올렸을 때 덮거나 섞을 색. (알파가 세기, 기본 흰색 알파 0.12)Color to cover or blend with when hovered. (alpha is the strength, default white alpha 0.12)
짝Counterpart: vanilla.js UIButton.setHoverTintColor
오버 틴트 색 반환.
Returns the over tint color.
반환ReturnsColor 오버 틴트 색.Hover tint color.
짝Counterpart: vanilla.js UIButton.getHoverTintColor
오버 진입 이벤트 설정.
Sets the over enter event.
- hover_eventUIButtonEvent
- 마우스가 버튼 위로 들어올 때 한 번 부를 함수. (버튼과 문맥을 받는다)Function called once when the mouse enters the button. (takes the button and the context)
짝Counterpart: vanilla.js UIButton.setHoverEvent
오버 진입 이벤트 반환. (부를 때는 borrow_mut 로 빌린다)
Returns the over enter event. (borrow it with borrow_mut to call it)
반환ReturnsOption<Rc<RefCell<UIButtonEvent>>> 건 오버 진입 이벤트. 걸지 않았으면 None.The set over enter event. None if not set.
짝Counterpart: vanilla.js UIButton.getHoverEvent
눌림 틴트 색 설정.
Sets the pressed tint color.
- colorimpl Into<Color>
- 누를 때 덮거나 섞을 색. (알파가 세기, 기본 검정 알파 0.3)Color to cover or blend with when pressed. (alpha is the strength, default black alpha 0.3)
짝Counterpart: vanilla.js UIButton.setPressedTintColor
눌림 틴트 색 반환.
Returns the pressed tint color.
반환ReturnsColor 눌림 틴트 색.Pressed tint color.
짝Counterpart: vanilla.js UIButton.getPressedTintColor
트랜지션 시간 설정. (초)
Sets the transition time. (seconds)
- transition_durationf64
- 틴트가 끝까지 차오르거나 빠지는 시간. (초, 기본 0.3)Time for the tint to fully fill in or fade out. (seconds, default 0.3)
짝Counterpart: vanilla.js UIButton.setTransitionDuration
트랜지션 시간 반환.
Returns the transition time.
반환Returnsf64 트랜지션 시간. (초)Transition time. (seconds)
짝Counterpart: vanilla.js UIButton.getTransitionDuration
사용 가능 설정. (끄면 다음 tick 에 색 대상을 모아 어두운 틴트를 건다)
Sets whether it is enabled. (when turned off, gathers color targets on the next tick and applies a dark tint)
- is_interactablebool
- 누를 수 있게 하려면 true. (끄면 상태가 Disabled, 켜면 Normal, 지금과 같으면 그대로)true to make it pressable. (off sets the state to Disabled, on sets Normal, unchanged if the same as now)
짝Counterpart: vanilla.js UIButton.setInteractable
사용 가능 여부.
Whether it is enabled.
반환Returnsbool 누를 수 있으면 true. (기본 true)true if pressable. (default true)
짝Counterpart: vanilla.js UIButton.getInteractable
ButtonStateenum traits Clone, Copy, Debug, PartialEq, Eq, crate::core::reflection::ToReflectValue
버튼 상태.
Button state.
| 이름Name | 설명Description |
|---|---|
Normal | 보통. (누르지도 올리지도 않음)Normal. (neither pressed nor hovered) |
Hover | 마우스를 올려 둔 상태.Mouse hovering over it. |
Pressed | 누르고 있는 상태. (최소 눌림 시간을 채우려고 뗌을 미루는 동안도)Being pressed. (also while the release is deferred to fill the minimum press time) |
Released | 뗌을 처리하는 중. (뗌, 클릭 이벤트를 부르는 동안만이고 끝나면 Normal)Handling the release. (only while firing the release and click events, then Normal) |
Disabled | 누를 수 없는 상태. (set_interactable(false))Not pressable. (set_interactable(false)) |