mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 18:22:45 +00:00 
			
		
		
		
	 7f2eeb0b35
			
		
	
	
		7f2eeb0b35
		
	
	
	
	
		
			
			Any GWidget can have a tooltip and it will automatically pop up below the center of the widget when hovered. GActions added to GToolBars will use the action text() as their tooltip automagically. :^)
		
			
				
	
	
		
			39 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| #pragma once
 | |
| 
 | |
| #include <LibGUI/GFrame.h>
 | |
| #include <SharedGraphics/TextAlignment.h>
 | |
| 
 | |
| class GraphicsBitmap;
 | |
| 
 | |
| class GLabel final : public GFrame {
 | |
| public:
 | |
|     explicit GLabel(GWidget* parent = nullptr);
 | |
|     GLabel(const String& text, GWidget* parent = nullptr);
 | |
|     virtual ~GLabel() override;
 | |
| 
 | |
|     String text() const { return m_text; }
 | |
|     void set_text(const String&);
 | |
| 
 | |
|     void set_icon(RetainPtr<GraphicsBitmap>&&);
 | |
|     const GraphicsBitmap* icon() const { return m_icon.ptr(); }
 | |
|     GraphicsBitmap* icon() { return m_icon.ptr(); }
 | |
| 
 | |
|     TextAlignment text_alignment() const { return m_text_alignment; }
 | |
|     void set_text_alignment(TextAlignment text_alignment) { m_text_alignment = text_alignment; }
 | |
| 
 | |
|     bool should_stretch_icon() const { return m_should_stretch_icon; }
 | |
|     void set_should_stretch_icon(bool b) { m_should_stretch_icon = b; }
 | |
| 
 | |
|     void size_to_fit();
 | |
| 
 | |
|     virtual const char* class_name() const override { return "GLabel"; }
 | |
| 
 | |
| private:
 | |
|     virtual void paint_event(GPaintEvent&) override;
 | |
| 
 | |
|     String m_text;
 | |
|     RetainPtr<GraphicsBitmap> m_icon;
 | |
|     TextAlignment m_text_alignment { TextAlignment::Center };
 | |
|     bool m_should_stretch_icon { false };
 | |
| };
 | |
| 
 |