ui/uidropdown
드롭다운. (콤보박스)
Dropdown. (combo box)
UIDropdownextends WorldNode
드롭다운. (콤보박스)
- 닫힌 머리 단추에 현재 값이 보이고, 누르면 아래로 선택지 목록이 펼쳐진다.
- 사용:
const dropdown = new UIDropdown({ width: 180, height: 30 });
dropdown.setOptionList(["Dark", "Light", "System"]);
dropdown.setChangedEvent((self) => { self.getSelectedText(); });
panelNode.addChild(dropdown);Dropdown. (combo box)
- The closed header button shows the current value, and pressing it expands the option list downward.
- Usage:
const dropdown = new UIDropdown({ width: 180, height: 30 });
dropdown.setOptionList(["Dark", "Light", "System"]);
dropdown.setChangedEvent((self) => { self.getSelectedText(); });
panelNode.addChild(dropdown);import { Engine, EngineConfiguration, UIScene, UIDropdown, Color, Vector2 } from "./build/vanilla.js";
class DropdownScene extends UIScene {
create() {
super.create();
const dropdown = new UIDropdown({ width: 200, height: 32, fontSize: 14, highlightColor: new Color(0.3, 0.8, 1, 0.3) });
dropdown.setOptionList(["Low", "Medium", "High", "Ultra"]);
dropdown.setSelectedIndex(2);
dropdown.setChangedEvent((self) => {
const selectedText = self.getSelectedText();
console.log(selectedText);
});
dropdown.setLocalPosition(Vector2.create(220, 80));
const root = this.getRoot();
root.addChild(dropdown);
dropdown.setOpen(true);
}
}
const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const scene = new DropdownScene();
scene.setLoadingMinDurationMs(0);
engine.run(scene);생성.
Constructor.
- optionsobject
- { width = 180, height = 30, optionHeight = 28, fontSize = 12, baseColor?, popupColor?, highlightColor?, textColor? }
짝Counterpart: vanilla-engine UIDropdown.new
선택지 목록 설정. (펼침 목록 행을 다시 만든다)
Sets the option list. (rebuilds the expanded list rows)
- optionListstring[]
- 선택지 글 목록. (복사해 쥔다, 선택 순서가 목록 밖이면 마지막으로 줄인다)Option text list. (copied and kept, the selected index is reduced to the last one if it falls outside the list)
짝Counterpart: vanilla-engine UIDropdown.set_option_list
선택 처리.
Handles selection.
- optionIndexnumber
- 고를 선택지 순서. (목록 밖이면 아무것도 하지 않는다, 고르면 목록을 접고 바뀌었을 때만 changedEvent 를 부른다)Index of the option to pick. (does nothing if outside the list, picking folds the list and calls changedEvent only if it changed)
짝Counterpart: vanilla-engine UIDropdown.select_index
펼침 / 접힘.
- 펼칠 때 목록을 트리 뿌리로 옮겨 나중에 그려지는 형제 노드에 가려지지 않게 한다. (접으면 되돌린다)
Expand / collapse.
- When expanding, moves the list to the tree root so it is not hidden by sibling nodes drawn later. (restored when collapsed)
- isOpenboolean
- 참이면 펼친다.If true, it unfolds.
짝Counterpart: vanilla-engine UIDropdown.set_open
선택이 바뀌었을 때 처리기 설정. (selectIndex 로 다른 것을 골랐을 때만, setSelectedIndex 로는 부르지 않는다)
Sets the handler for when the selection changes. (only when a different option is picked with selectIndex, not called by setSelectedIndex)
- changedEventFunction
- (self)
짝Counterpart: vanilla-engine UIDropdown.set_changed_event
import { UIDropdown } from "./build/vanilla.js";
const dropdown = new UIDropdown({ width: 160 });
dropdown.setOptionList(["Low", "Medium", "High"]);
dropdown.setChangedEvent((self) => {
const selectedText = self.getSelectedText();
console.log(selectedText);
});
dropdown.setSelectedIndex(1);
dropdown.selectIndex(2);선택 순서 설정. (처리기를 부르지 않고 머리 글과 강조만 바꾼다)
Sets the selected index. (changes only the header text and the highlight without calling the handler)
- selectedIndexnumber
- 선택 순서. (0 ~ 선택지 수 - 1 로 자른다)Selected index. (clamped to 0 ~ option count - 1)
짝Counterpart: vanilla-engine UIDropdown.set_selected_index
선택 순서 반환.
Returns the selected index.
반환Returnsnumber 선택 순서. (선택지가 없어도 0)Selected index. (0 even if there are no options)
짝Counterpart: vanilla-engine UIDropdown.get_selected_index
고른 선택지 글 반환.
Returns the text of the picked option.
반환Returnsstring 고른 선택지 글. (선택지가 없으면 빈 글)Text of the picked option. (empty string if there are no options)
짝Counterpart: vanilla-engine UIDropdown.get_selected_text
펼쳐져 있는지 반환.
Returns whether it is unfolded.
반환Returnsboolean 펼쳐져 있으면 참.True if unfolded.
짝Counterpart: vanilla-engine UIDropdown.is_open
선택지 목록 반환.
Returns the option list.
반환Returnsstring[] 선택지 글 목록. (setOptionList 로 준 차례, 고쳐 쓰지 않는다)List of option texts. (In the order given to setOptionList, do not modify)
짝Counterpart: vanilla-engine UIDropdown.get_option_list
펼침 목록 노드 반환. (펼친 동안은 트리 뿌리의 자식)
Returns the popup list node. (A child of the tree root while open)
반환ReturnsWorldNode 펼침 목록 노드.Popup list node.
짝Counterpart: vanilla-engine UIDropdown.get_popup_node
선택지 행 노드 목록 반환. (선택지 차례, setOptionList 마다 다시 만든다)
Returns the option row nodes. (In option order, rebuilt on every setOptionList)
반환ReturnsWorldNode[] 행 노드. (새 배열)Row nodes. (a new array)
짝Counterpart: vanilla-engine UIDropdown.get_option_nodes
import { UIDropdown } from "./build/vanilla.js";
const dropdown = new UIDropdown({ width: 160 });
dropdown.setOptionList(["Low", "Medium", "High"]);
const optionNodes = dropdown.getOptionNodes();
console.log(optionNodes.length, optionNodes[1].getName(), dropdown.getOptionList()[1]);
dropdown.selectIndex(1);
console.log(dropdown.getSelectedText());