DropDownList.h 3.5 KB

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