ImGuiProgressList.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/std/string/string.h>
  10. #include <AzCore/std/functional.h>
  11. #include <AzCore/std/containers/vector.h>
  12. #include <AzCore/Component/TickBus.h>
  13. namespace AtomSampleViewer
  14. {
  15. //! A simple modal window that displays a list of items (strings).
  16. //! Useful for cases when a set of items are pending some kind of processing.
  17. class ImGuiProgressList final
  18. : public AZ::TickBus::Handler
  19. {
  20. public:
  21. // TickBus::Handler
  22. void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
  23. //! Needs to be called once before being able to call AddItem/RemoveItem/TickPopup.
  24. //! @itemsList can be empty.
  25. void OpenPopup(AZStd::string_view title, AZStd::string_view description, const AZStd::vector<AZStd::string>& itemsList,
  26. AZStd::function<void()> onUserAction, bool automaticallyCloseOnAction = true, AZStd::string_view actionButtonLabel = "Close");
  27. void ClosePopup();
  28. void AddItem(AZStd::string_view item);
  29. void RemoveItem(AZStd::string_view item);
  30. void TickPopup();
  31. private:
  32. enum class State
  33. {
  34. Closed,
  35. Opening,
  36. Open
  37. };
  38. int32_t m_selectedItemIndex = -1;
  39. State m_state = State::Closed;
  40. AZStd::string m_title;
  41. AZStd::string m_description;
  42. AZStd::string m_actionButtonLabel;
  43. AZStd::function<void()> m_onUserAction;
  44. bool m_automaticallyCloseOnAction = true;
  45. AZStd::vector<AZStd::string> m_itemsList;
  46. };
  47. } // namespace AtomSampleViewer