24 #include "../Exception.h" 28 #if defined(_WIN32) && defined(HR_ENGINE_SHARED) 30 # define MR_DllDeclare __declspec( dllexport ) 32 # define MR_DllDeclare __declspec( dllimport ) 35 # define MR_DllDeclare 63 void InitIcon(
bool enabled,
bool checked);
98 virtual boost::optional<size_t> FindChildIndex(
const UiViewModel &child)
const = 0;
108 virtual void SetSelection(
const boost::optional<size_t> &newSel) = 0;
112 bool OnAction()
override;
116 void OnChildRequestedFocus(
UiViewModel &child)
override;
122 void DropFocus()
override;
134 boost::optional<size_t> newSel;
135 if (idx < filteredItems.size()) {
136 newSel = filteredItems[
idx];
139 SetSelection(newSel);
148 return static_cast<bool>(selItem);
156 SetSelection(boost::none);
164 double GetScroll()
const {
return -(GetChildOffset().y); }
166 void ScrollTo(
double y);
167 void ScrollToFocused();
174 void Layout()
override;
201 SUPER(display, size, layoutFlags), mode(mode) { }
211 size_t idx,
const T &value,
const std::string &text,
213 SUPER(display, text, showIcon, layoutFlags),
214 pickList(pickList), idx(idx), value(value)
216 clickedConn = GetClickedSignal().connect([&](
ClickRegion&) {
244 child(child), item(item) { }
257 items[filteredItems[*focusedItem]].child.child.get() :
268 for (
auto i : filteredItems) {
269 if (items[i].child.child.get() == &child) {
281 if (selItem != newSel) {
283 items[*selItem].item.SetChecked(
false);
286 items[*newSel].item.SetChecked(
true);
289 valueChangedSignal();
296 boost::optional<size_t> newSel = sel ?
297 boost::make_optional(sel->
GetIndex()) :
300 if (selItem != newSel) {
309 valueChangedSignal();
319 void Add(
const std::string &label,
const T &value)
321 size_t idx = items.size();
322 auto item = NewChild<DefaultItem>(*
this, display,
idx, value, label,
323 (mode == Mode::RADIO));
324 items.emplace_back(*(GetChildren().back()), *item);
325 filteredItems.push_back(items.size() - 1);
335 Add(boost::lexical_cast<std::string>(value), value);
352 boost::optional<size_t> newSel;
353 for (
auto idx : filteredItems) {
354 if (items[
idx].item.GetValue() ==
val) {
360 SetSelection(newSel);
370 boost::make_optional<const T&>(items[*selItem].item.GetValue()) :
387 auto prevFocusedChild = GetFocusedChild();
388 auto prevFocusedIdx = focusedItem;
390 bool deselected =
false;
391 bool foundFocusedChild =
false;
392 filteredItems.clear();
394 for (
auto &item : items) {
395 bool visible = item.child.visible = fn(item.item.GetValue());
397 if (item.child.child.get() == prevFocusedChild) {
401 foundFocusedChild =
true;
402 focusedItem = filteredItems.size();
404 filteredItems.push_back(idx);
406 else if (selItem && *selItem == idx) {
407 items[*selItem].item.SetChecked(
false);
408 selItem = boost::none;
414 if (prevFocusedChild && !foundFocusedChild) {
415 prevFocusedChild->DropFocus();
416 focusedItem = boost::none;
420 if (filteredItems.empty()) {
425 focusedItem = std::min(*focusedItem, filteredItems.size() - 1);
426 if (!GetFocusedChild()->TryFocus()) {
428 focusedItem = boost::none;
437 valueChangedSignal();
446 ApplyFilter([](
const T&){
return true; });
455 filteredItems.clear();
462 selItem = boost::none;
463 valueChangedSignal();
469 SUPER::Reserve(capacity);
470 items.reserve(capacity);
471 filteredItems.reserve(capacity);
valueChangedSignal_t & GetValueChangedSignal()
Definition: PickList.h:171
void SetValue(const T &val)
Set the selected value.
Definition: PickList.h:347
std::vector< size_t > filteredItems
Indexes of filtered items.
Definition: PickList.h:177
Child & child
Definition: PickList.h:249
boost::signals2::signal< void()> valueChangedSignal_t
Definition: PickList.h:170
Base class for UI (2D) components.
Definition: UiViewModel.h:56
void ClearSelection()
If an item is selected, unset the selection so that nothing is selected.
Definition: PickList.h:154
virtual ~PickList()
Definition: PickList.h:202
virtual ~BasePickList()
Definition: PickList.h:77
ItemChild(Child &child, DefaultItem &item)
Definition: PickList.h:243
boost::optional< const T & > GetValue() const
Get the value of the selected item.
Definition: PickList.h:367
Definition: PickList.h:205
void ApplyFilter(Fn fn)
Apply a filter to the list items.
Definition: PickList.h:385
const T value
Definition: PickList.h:235
Base class for widgets that contain other widgets.
Definition: BaseContainer.h:63
void SetSelectedItem(DefaultItem *sel)
Definition: PickList.h:294
void Add(const T &value)
Add a list item with a default label.
Definition: PickList.h:333
boost::optional< size_t > FindChildIndex(const UiViewModel &child) const override
Search for the index of the given child widget.
Definition: PickList.h:261
void SetSelection(const boost::optional< size_t > &newSel) override
Set the selected item by index.
Definition: PickList.h:279
MR_UInt32 uiLayoutFlags_t
Definition: UiLayoutFlags.h:53
void RemoveFilter()
Undo any applied filter (so all items are visible).
Definition: PickList.h:444
boost::optional< size_t > selItem
items index of selected.
Definition: PickList.h:178
Mode
Definition: PickList.h:80
double GetScroll() const
Retrieve how far down the list we have scrolled.
Definition: PickList.h:164
PickList< T > & pickList
Definition: PickList.h:233
Base class for display managers.
Definition: Display.h:73
Generic base for PickList.
Definition: PickList.h:70
virtual ~PickListItem()
Definition: PickList.h:59
void Clear() override
Remove all child elements.
Definition: PickList.h:449
valueChangedSignal_t valueChangedSignal
Definition: PickList.h:181
luabind::object val
Definition: Rulebook.cpp:52
DefaultItem(PickList< T > &pickList, Display &display, size_t idx, const T &value, const std::string &text, bool showIcon, uiLayoutFlags_t layoutFlags=0)
Definition: PickList.h:210
A navigation direction.
Definition: Nav.h:45
UiViewModel * GetFocusedChild() const override
Get the focused child widget.
Definition: PickList.h:254
PickList(Display &display, const Vec2 &size, uiLayoutFlags_t layoutFlags=0)
Definition: PickList.h:196
Maps the container child wrapper to each item.
Definition: PickList.h:240
bool HasSelected() const
Check if this list has a selected item.
Definition: PickList.h:146
void Reserve(size_t capacity) override
Increase the capacity of the of this container.
Definition: PickList.h:467
std::vector< ItemChild > items
Definition: PickList.h:476
int idx
Definition: SdlDisplay.cpp:254
Base class for clickable areas.
Definition: ClickRegion.h:49
const size_t idx
Definition: PickList.h:234
size_t GetIndex() const
Definition: PickList.h:229
virtual ~DefaultItem()
Definition: PickList.h:223
void Add(const std::string &label, const T &value)
Add a list item with a specific label.
Definition: PickList.h:319
Definition: Announcement.h:24
Scrollable list of selectable items.
Definition: PickList.h:191
const T & GetValue() const
Definition: PickList.h:230
DefaultItem & item
Definition: PickList.h:250
A single list item.
Definition: PickList.h:52
boost::optional< size_t > focusedItem
filteredItems index of focused.
Definition: PickList.h:179
PickList(Display &display, Mode mode, const Vec2 &size, uiLayoutFlags_t layoutFlags=0)
Definition: PickList.h:199
boost::signals2::scoped_connection clickedConn
Definition: PickList.h:236
void SetIndex(size_t idx)
Select an item by index.
Definition: PickList.h:132
double listHeight
Definition: PickList.h:180
Mode mode
Definition: PickList.h:475