Tray.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibGUI/Frame.h>
  9. #include <LibGfx/Bitmap.h>
  10. namespace GUI {
  11. class Tray : public GUI::Frame {
  12. C_OBJECT(Tray);
  13. public:
  14. virtual ~Tray() override = default;
  15. size_t add_item(String text, RefPtr<Gfx::Bitmap>, String custom_data);
  16. void set_item_checked(size_t index, bool);
  17. Function<void(String const&)> on_item_activation;
  18. protected:
  19. virtual void paint_event(GUI::PaintEvent&) override;
  20. virtual void mousemove_event(GUI::MouseEvent&) override;
  21. virtual void mousedown_event(GUI::MouseEvent&) override;
  22. virtual void mouseup_event(GUI::MouseEvent&) override;
  23. virtual void leave_event(Core::Event&) override;
  24. virtual void focusin_event(GUI::FocusEvent&) override;
  25. virtual void focusout_event(GUI::FocusEvent&) override;
  26. virtual void keydown_event(GUI::KeyEvent&) override;
  27. private:
  28. Tray();
  29. struct Item {
  30. String text;
  31. RefPtr<Gfx::Bitmap> bitmap;
  32. String custom_data;
  33. size_t index { 0 };
  34. Gfx::IntRect rect(Tray const&) const;
  35. };
  36. Item* item_at(Gfx::IntPoint const&);
  37. Vector<Item> m_items;
  38. Optional<size_t> m_pressed_item_index;
  39. Optional<size_t> m_hovered_item_index;
  40. Optional<size_t> m_checked_item_index;
  41. };
  42. }