25 void ComboBox::initialiseOverride()
27 Base::initialiseOverride();
30 assignWidget(mButton,
"Button");
31 if (mButton !=
nullptr)
33 mButton->eventMouseButtonPressed +=
newDelegate(
this, &ComboBox::notifyButtonPressed);
37 assignWidget(mList,
"List");
41 std::string_view list_skin = getUserString(
"ListSkin");
42 std::string_view list_layer = getUserString(
"ListLayer");
44 mList =
static_cast<ListBox*
>(_createSkinWidget(
46 ListBox::getClassTypeName(),
55 mList->setActivateOnClick(
true);
57 mList->setVisible(
false);
58 mList->eventKeyLostFocus +=
newDelegate(
this, &ComboBox::notifyListLostFocus);
59 mList->eventListSelectAccept +=
newDelegate(
this, &ComboBox::notifyListSelectAccept);
60 mList->eventListMouseItemActivate +=
newDelegate(
this, &ComboBox::notifyListMouseItemActivate);
61 mList->eventListChangePosition +=
newDelegate(
this, &ComboBox::notifyListChangePosition);
63 mList->setNeedToolTip(
true);
64 mList->eventToolTip +=
newDelegate(
this, &ComboBox::notifyToolTip);
68 if (mScrollViewClient !=
nullptr)
70 mScrollViewClient->eventMouseWheel +=
newDelegate(
this, &ComboBox::notifyMouseWheel);
71 mScrollViewClient->eventMouseButtonPressed +=
newDelegate(
this, &ComboBox::notifyMousePressed);
73 mScrollViewClient->setNeedToolTip(
true);
74 mScrollViewClient->eventToolTip +=
newDelegate(
this, &ComboBox::notifyToolTip);
78 eventEditTextChange +=
newDelegate(
this, &ComboBox::notifyEditTextChange);
81 void ComboBox::shutdownOverride()
84 eventChangeAbsoluteCoord -=
newDelegate(
this, &ComboBox::notifyChangeCoord);
89 Base::shutdownOverride();
92 void ComboBox::notifyButtonPressed(Widget* _sender,
int _left,
int _top, MouseButton _id)
94 if (MouseButton::Left != _id)
105 void ComboBox::notifyListLostFocus(Widget* _sender, Widget* _new)
110 Widget* focus = InputManager::getInstance().getMouseFocusWidget();
113 if (focus == mButton)
117 if (mModeDrop && focus == mScrollViewClient)
124 void ComboBox::notifyListSelectAccept(ListBox* _widget,
size_t _position)
126 mItemIndex = _position;
127 Base::setCaption(mItemIndex !=
ITEM_NONE ? mList->getItemNameAt(mItemIndex) : UString());
130 InputManager::getInstance().setKeyFocusWidget(
this);
134 _resetContainer(
false);
136 eventComboAccept(
this, mItemIndex);
140 void ComboBox::notifyListChangePosition(ListBox* _widget,
size_t _position)
142 mItemIndex = _position;
144 _resetContainer(
false);
146 eventComboChangePosition(
this, _position);
149 void ComboBox::onKeyButtonPressed(KeyCode _key,
Char _char)
151 Base::onKeyButtonPressed(_key, _char);
153 if (_key == KeyCode::ArrowDown)
156 if (!InputManager::getInstance().isCaptureMouse())
161 else if ((_key == KeyCode::Return) || (_key == KeyCode::NumpadEnter))
163 _resetContainer(
false);
165 eventComboAccept(
this, mItemIndex);
169 void ComboBox::notifyListMouseItemActivate(ListBox* _widget,
size_t _position)
171 mItemIndex = _position;
172 Base::setCaption(mItemIndex !=
ITEM_NONE ? mList->getItemNameAt(mItemIndex) : UString());
174 InputManager::getInstance().setKeyFocusWidget(
this);
178 _resetContainer(
false);
180 eventComboAccept(
this, mItemIndex);
184 void ComboBox::notifyMouseWheel(Widget* _sender,
int _rel)
186 if (mList->getItemCount() == 0)
188 if (InputManager::getInstance().getKeyFocusWidget() !=
this)
190 if (InputManager::getInstance().isCaptureMouse())
201 Base::setCaption(mList->getItemNameAt(mItemIndex));
202 mList->setIndexSelected(mItemIndex);
203 mList->beginToItemAt(mItemIndex);
205 _resetContainer(
false);
207 eventComboChangePosition(
this, mItemIndex);
212 if ((mItemIndex + 1) < mList->getItemCount())
218 Base::setCaption(mList->getItemNameAt(mItemIndex));
219 mList->setIndexSelected(mItemIndex);
220 mList->beginToItemAt(mItemIndex);
222 _resetContainer(
false);
224 eventComboChangePosition(
this, mItemIndex);
229 void ComboBox::notifyMousePressed(Widget* _sender,
int _left,
int _top, MouseButton _id)
232 Base::notifyMousePressed(_sender, _left, _top, _id);
237 notifyButtonPressed(
nullptr, _left, _top, _id);
240 void ComboBox::notifyEditTextChange(EditBox* _sender)
246 mList->setIndexSelected(mItemIndex);
247 mList->beginToItemFirst();
249 _resetContainer(
false);
251 eventComboChangePosition(
this, mItemIndex);
255 void ComboBox::showList()
258 if (mList->getItemCount() == 0)
265 IntCoord coord = calculateListPosition();
266 mList->setCoord(coord);
267 eventChangeAbsoluteCoord +=
newDelegate(
this, &ComboBox::notifyChangeCoord);
272 ControllerManager::getInstance().addItem(mList, controller);
276 mList->setVisible(
true);
279 InputManager::getInstance().setKeyFocusWidget(mList);
282 void ComboBox::actionWidgetHide(Widget* _widget, ControllerItem* _controller)
284 _widget->setVisible(
false);
285 _widget->setEnabled(
true);
288 void ComboBox::hideList()
293 eventChangeAbsoluteCoord -=
newDelegate(
this, &ComboBox::notifyChangeCoord);
298 controller->eventPostAction +=
newDelegate(
this, &ComboBox::actionWidgetHide);
299 ControllerManager::getInstance().addItem(mList, controller);
303 mList->setVisible(
false);
307 void ComboBox::notifyChangeCoord(Widget* _sender)
310 IntCoord coord = calculateListPosition();
311 if (mList->getCoord() != coord)
312 mList->setCoord(coord);
315 void ComboBox::setIndexSelected(
size_t _index)
319 mList->setIndexSelected(_index);
322 Base::setCaption(UString());
325 Base::setCaption(mList->getItemNameAt(_index));
329 void ComboBox::setItemNameAt(
size_t _index,
const UString& _name)
331 mList->setItemNameAt(_index, _name);
333 mList->setIndexSelected(mItemIndex);
336 void ComboBox::setItemDataAt(
size_t _index, Any _data)
338 mList->setItemDataAt(_index, _data);
340 mList->setIndexSelected(mItemIndex);
343 void ComboBox::insertItemAt(
size_t _index,
const UString& _item, Any _data)
345 mList->insertItemAt(_index, _item, _data);
347 mList->setIndexSelected(mItemIndex);
350 void ComboBox::removeItemAt(
size_t _index)
352 mList->removeItemAt(_index);
354 mList->clearIndexSelected();
357 void ComboBox::removeAllItems()
360 mList->removeAllItems();
363 void ComboBox::setComboModeDrop(
bool _drop)
366 setEditStatic(mModeDrop);
369 ControllerFadeAlpha* ComboBox::createControllerFadeAlpha(
float _alpha,
float _coef,
bool _enable)
371 ControllerItem* item = ControllerManager::getInstance().createItem(ControllerFadeAlpha::getClassTypeName());
372 ControllerFadeAlpha* controller = item->castType<ControllerFadeAlpha>();
374 controller->setAlpha(_alpha);
375 controller->setCoef(_coef);
376 controller->setEnabled(_enable);
381 size_t ComboBox::findItemIndexWith(
const UString& _name)
383 return mList->findItemIndexWith(_name);
386 void ComboBox::setFlowDirection(FlowDirection _value)
388 mFlowDirection = _value;
391 IntCoord ComboBox::calculateListPosition()
394 if (mFlowDirection.isVertical())
395 length = mList->getOptimalHeight();
397 length = mMaxListLength;
399 if (mMaxListLength > 0 && length > mMaxListLength)
400 length = mMaxListLength;
402 IntCoord coord = getAbsoluteCoord();
404 IntSize sizeView = mList->getParentSize();
406 if (mFlowDirection == FlowDirection::TopToBottom)
408 if ((coord.bottom() + length) <= sizeView.height)
409 coord.top += coord.height;
412 coord.height = length;
414 else if (mFlowDirection == FlowDirection::BottomToTop)
416 if ((coord.top - length) >= 0)
419 coord.top += coord.height;
420 coord.height = length;
422 else if (mFlowDirection == FlowDirection::LeftToRight)
424 if ((coord.right() + length) <= sizeView.width)
425 coord.left += coord.width;
427 coord.left -= length;
428 coord.width = length;
430 else if (mFlowDirection == FlowDirection::RightToLeft)
432 if ((coord.left - length) >= 0)
433 coord.left -= length;
435 coord.left += coord.width;
436 coord.width = length;
442 void ComboBox::setPropertyOverride(std::string_view _key, std::string_view _value)
445 if (_key ==
"ModeDrop")
449 else if (_key ==
"FlowDirection")
453 else if (_key ==
"MaxListLength")
457 else if (_key ==
"ItemHeight")
461 else if (_key ==
"SmoothShow")
465 else if (_key ==
"AddItem")
466 addItem(LanguageManager::getInstance().replaceTags(UString(_value)));
470 Base::setPropertyOverride(_key, _value);
474 eventChangeProperty(
this, _key, _value);
477 size_t ComboBox::getItemCount()
const
479 return mList->getItemCount();
482 void ComboBox::addItem(
const UString& _name, Any _data)
484 return insertItemAt(
ITEM_NONE, _name, _data);
487 size_t ComboBox::getIndexSelected()
const
492 void ComboBox::clearIndexSelected()
497 void ComboBox::clearItemDataAt(
size_t _index)
499 setItemDataAt(_index, Any::Null);
502 const UString& ComboBox::getItemNameAt(
size_t _index)
const
504 return mList->getItemNameAt(_index);
507 void ComboBox::beginToItemAt(
size_t _index)
509 mList->beginToItemAt(_index);
512 void ComboBox::beginToItemFirst()
518 void ComboBox::beginToItemLast()
521 beginToItemAt(getItemCount() - 1);
524 void ComboBox::beginToItemSelected()
527 beginToItemAt(getIndexSelected());
530 bool ComboBox::getComboModeDrop()
const
535 void ComboBox::setSmoothShow(
bool _value)
537 mShowSmooth = _value;
540 bool ComboBox::getSmoothShow()
const
545 void ComboBox::setItemHeight(
int _height)
547 _height = std::max(1, _height);
548 if (mList->getItemHeight() == _height)
551 mList->setItemHeight(_height);
553 notifyChangeCoord(
this);
556 int ComboBox::getItemHeight()
const
558 return mList->getItemHeight();
561 void ComboBox::setMaxListLength(
int _value)
563 mMaxListLength = _value;
566 int ComboBox::getMaxListLength()
const
568 return mMaxListLength;
571 FlowDirection ComboBox::getFlowDirection()
const
573 return mFlowDirection;
576 void ComboBox::notifyToolTip(Widget* _sender,
const ToolTipInfo& _info)
578 if (getNeedToolTip())
579 eventToolTip(
this, _info);
582 size_t ComboBox::_getItemCount()
const
584 return getItemCount();
587 void ComboBox::_addItem(
const MyGUI::UString& _name)
592 void ComboBox::_removeItemAt(
size_t _index)
594 removeItemAt(_index);
597 void ComboBox::_setItemNameAt(
size_t _index,
const UString& _name)
599 setItemNameAt(_index, _name);
602 const UString& ComboBox::_getItemNameAt(
size_t _index)
const
604 return getItemNameAt(_index);
607 void ComboBox::_resetContainer(
bool _update)
609 Base::_resetContainer(_update);
610 if (mList !=
nullptr)
611 mList->_resetContainer(_update);
#define MYGUI_ASSERT_RANGE_AND_NONE(index, size, owner)
T parseValue(std::string_view value)
constexpr float ALPHA_MAX
constexpr float ALPHA_MIN
const float COMBO_ALPHA_MAX
const float COMBO_ALPHA_MIN
constexpr size_t ITEM_NONE
types::TCoord< int > IntCoord
types::TSize< int > IntSize
const float COMBO_ALPHA_COEF
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))