GLabel.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #pragma once
  2. #include <LibGUI/GFrame.h>
  3. #include <LibDraw/TextAlignment.h>
  4. class GraphicsBitmap;
  5. class GLabel : public GFrame {
  6. C_OBJECT(GLabel)
  7. public:
  8. explicit GLabel(GWidget* parent = nullptr);
  9. GLabel(const StringView& text, GWidget* parent = nullptr);
  10. virtual ~GLabel() override;
  11. String text() const { return m_text; }
  12. void set_text(const StringView&);
  13. void set_icon(GraphicsBitmap*);
  14. const GraphicsBitmap* icon() const { return m_icon.ptr(); }
  15. GraphicsBitmap* icon() { return m_icon.ptr(); }
  16. TextAlignment text_alignment() const { return m_text_alignment; }
  17. void set_text_alignment(TextAlignment text_alignment) { m_text_alignment = text_alignment; }
  18. bool should_stretch_icon() const { return m_should_stretch_icon; }
  19. void set_should_stretch_icon(bool b) { m_should_stretch_icon = b; }
  20. void size_to_fit();
  21. private:
  22. virtual void paint_event(GPaintEvent&) override;
  23. String m_text;
  24. RefPtr<GraphicsBitmap> m_icon;
  25. TextAlignment m_text_alignment { TextAlignment::Center };
  26. bool m_should_stretch_icon { false };
  27. };