blob: f0c2b8c1abb28f773f2786f804a9af94c61bc5e1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibGUI/Frame.h>
#include <LibGfx/TextAlignment.h>
#include <LibGfx/TextWrapping.h>
namespace GUI {
class Label : public Frame {
C_OBJECT(Label);
public:
virtual ~Label() override;
String text() const { return m_text; }
void set_text(String);
void set_icon(const Gfx::Bitmap*);
const Gfx::Bitmap* icon() const { return m_icon.ptr(); }
Gfx::Bitmap* icon() { return m_icon.ptr(); }
Gfx::TextAlignment text_alignment() const { return m_text_alignment; }
void set_text_alignment(Gfx::TextAlignment text_alignment) { m_text_alignment = text_alignment; }
Gfx::TextWrapping text_wrapping() const { return m_text_wrapping; }
void set_text_wrapping(Gfx::TextWrapping text_wrapping) { m_text_wrapping = text_wrapping; }
bool should_stretch_icon() const { return m_should_stretch_icon; }
void set_should_stretch_icon(bool b) { m_should_stretch_icon = b; }
bool is_autosize() const { return m_autosize; }
void set_autosize(bool);
int preferred_height() const;
Gfx::IntRect text_rect() const;
protected:
explicit Label(String text = {});
virtual void paint_event(PaintEvent&) override;
virtual void did_change_text() { }
private:
void size_to_fit();
String m_text;
RefPtr<Gfx::Bitmap> m_icon;
Gfx::TextAlignment m_text_alignment { Gfx::TextAlignment::Center };
Gfx::TextWrapping m_text_wrapping { Gfx::TextWrapping::Wrap };
bool m_should_stretch_icon { false };
bool m_autosize { false };
};
}
|