GLabel.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. virtual ~GLabel() override;
  9. String text() const { return m_text; }
  10. void set_text(const StringView&);
  11. void set_icon(GraphicsBitmap*);
  12. const GraphicsBitmap* icon() const { return m_icon.ptr(); }
  13. GraphicsBitmap* icon() { return m_icon.ptr(); }
  14. TextAlignment text_alignment() const { return m_text_alignment; }
  15. void set_text_alignment(TextAlignment text_alignment) { m_text_alignment = text_alignment; }
  16. bool should_stretch_icon() const { return m_should_stretch_icon; }
  17. void set_should_stretch_icon(bool b) { m_should_stretch_icon = b; }
  18. void size_to_fit();
  19. protected:
  20. explicit GLabel(GWidget* parent = nullptr);
  21. GLabel(const StringView& text, GWidget* parent = nullptr);
  22. virtual void paint_event(GPaintEvent&) override;
  23. private:
  24. String m_text;
  25. RefPtr<GraphicsBitmap> m_icon;
  26. TextAlignment m_text_alignment { TextAlignment::Center };
  27. bool m_should_stretch_icon { false };
  28. };