DropDownList.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // Copyright (c) 2008-2013 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "Menu.h"
  24. namespace Urho3D
  25. {
  26. class ListView;
  27. /// %Menu %UI element that displays a popup list view.
  28. class URHO3D_API DropDownList : public Menu
  29. {
  30. OBJECT(DropDownList)
  31. public:
  32. /// Construct.
  33. DropDownList(Context* context);
  34. /// Destruct.
  35. ~DropDownList();
  36. /// Register object factory.
  37. static void RegisterObject(Context* context);
  38. /// Apply attribute changes that can not be applied immediately.
  39. virtual void ApplyAttributes();
  40. /// Return UI rendering batches.
  41. virtual void GetBatches(PODVector<UIBatch>& batches, PODVector<float>& vertexData, const IntRect& currentScissor);
  42. /// React to the popup being shown.
  43. virtual void OnShowPopup();
  44. /// React to editable status change.
  45. virtual void OnSetEditable();
  46. /// Add item to the end of the list.
  47. void AddItem(UIElement* item);
  48. /// Insert item to a specific position.
  49. void InsertItem(unsigned index, UIElement* item);
  50. /// Remove specific item.
  51. void RemoveItem(UIElement* item);
  52. /// Remove item at index.
  53. void RemoveItem(unsigned index);
  54. /// Remove all items.
  55. void RemoveAllItems();
  56. /// Set selection.
  57. void SetSelection(unsigned index);
  58. /// Set place holder text. This is the text shown when there is no selection in drop down list.
  59. void SetPlaceholderText(const String& text);
  60. /// Set whether popup should be automatically resized to match the dropdown button width.
  61. void SetResizePopup(bool enable);
  62. /// Return number of items.
  63. unsigned GetNumItems() const;
  64. /// Return item at index.
  65. UIElement* GetItem(unsigned index) const;
  66. /// Return all items.
  67. PODVector<UIElement*> GetItems() const;
  68. /// Return selection index, or M_MAX_UNSIGNED if none selected.
  69. unsigned GetSelection() const;
  70. /// Return selected item, or null if none selected.
  71. UIElement* GetSelectedItem() const;
  72. /// Return listview element.
  73. ListView* GetListView() const { return listView_; }
  74. /// Return selected item placeholder element.
  75. UIElement* GetPlaceholder() const { return placeholder_; }
  76. /// Return place holder text.
  77. const String& GetPlaceholderText() const;
  78. /// Return whether popup should be automatically resized.
  79. bool GetResizePopup() const { return resizePopup_; }
  80. /// Set selection attribute.
  81. void SetSelectionAttr(unsigned index);
  82. protected:
  83. /// Filter implicit attributes in serialization process.
  84. virtual bool FilterImplicitAttributes(XMLElement& dest) const;
  85. /// Filter implicit attributes in serialization process.
  86. virtual bool FilterPopupImplicitAttributes(XMLElement& dest) const;
  87. /// Listview element.
  88. SharedPtr<ListView> listView_;
  89. /// Selected item placeholder element.
  90. SharedPtr<UIElement> placeholder_;
  91. /// Resize popup flag.
  92. bool resizePopup_;
  93. private:
  94. /// Handle listview item selected event.
  95. void HandleItemSelected(StringHash eventType, VariantMap& eventData);
  96. /// Selected item index attribute.
  97. unsigned selectionAttr_;
  98. };
  99. }