UIComboBox.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <UI/UITexturedQuad.h>
  5. #include <UI/UIButton.h>
  6. /// Combo box with previous and next button
  7. class UIComboBox : public UIElement
  8. {
  9. public:
  10. JPH_DECLARE_RTTI_VIRTUAL(UIComboBox)
  11. using ItemChangedAction = function<void(int)>;
  12. /// Properties
  13. void SetItems(const Array<String> &inItems) { mItems = inItems; }
  14. void SetCurrentItem(int inItem) { mCurrentItem = inItem; }
  15. void SetPreviousButton(UIButton *inPreviousButton) { mPreviousButton = inPreviousButton; }
  16. void SetNextButton(UIButton *inNextButton) { mNextButton = inNextButton; }
  17. void SetStaticText(UIStaticText *inStaticText) { mStaticText = inStaticText; UpdateStaticText(); }
  18. void SetItemChangedAction(ItemChangedAction inAction) { mItemChangedAction = inAction; }
  19. /// Cloning / copying
  20. virtual void CopyTo(UIElement *ioElement) const override;
  21. /// Event handling (returns true if the event has been handled)
  22. virtual bool HandleUIEvent(EUIEvent inEvent, UIElement *inSender) override;
  23. /// Calculate auto layout
  24. virtual void AutoLayout() override;
  25. protected:
  26. /// Internal function to update the current item
  27. void SetItemInternal(int inItem);
  28. /// Update static text box
  29. void UpdateStaticText();
  30. /// Properties
  31. Array<String> mItems;
  32. int mCurrentItem = 0;
  33. UIButton * mPreviousButton = nullptr;
  34. UIButton * mNextButton = nullptr;
  35. UIStaticText * mStaticText = nullptr;
  36. ItemChangedAction mItemChangedAction;
  37. };