2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-01-20 01:49:48 -02:00
|
|
|
#pragma once
|
|
|
|
|
|
2020-02-06 16:33:02 -03:00
|
|
|
#include <LibGUI/Frame.h>
|
2020-09-18 04:49:51 -03:00
|
|
|
#include <LibGfx/TextAlignment.h>
|
2021-07-29 17:06:46 -03:00
|
|
|
#include <LibGfx/TextWrapping.h>
|
2019-02-12 12:23:07 -02:00
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
|
|
class Label : public Frame {
|
2020-12-26 09:10:50 -03:00
|
|
|
C_OBJECT(Label);
|
|
|
|
|
|
2019-01-20 01:49:48 -02:00
|
|
|
public:
|
2020-02-02 11:07:41 -03:00
|
|
|
virtual ~Label() override;
|
2019-01-20 01:49:48 -02:00
|
|
|
|
|
|
|
|
String text() const { return m_text; }
|
2020-12-26 09:10:50 -03:00
|
|
|
void set_text(String);
|
2019-01-20 01:49:48 -02:00
|
|
|
|
2020-03-29 13:41:34 -03:00
|
|
|
void set_icon(const Gfx::Bitmap*);
|
2020-02-06 07:56:38 -03:00
|
|
|
const Gfx::Bitmap* icon() const { return m_icon.ptr(); }
|
|
|
|
|
Gfx::Bitmap* icon() { return m_icon.ptr(); }
|
2019-02-12 12:23:07 -02:00
|
|
|
|
2020-02-06 07:56:38 -03:00
|
|
|
Gfx::TextAlignment text_alignment() const { return m_text_alignment; }
|
|
|
|
|
void set_text_alignment(Gfx::TextAlignment text_alignment) { m_text_alignment = text_alignment; }
|
2019-02-12 12:23:07 -02:00
|
|
|
|
2021-07-29 17:06:46 -03:00
|
|
|
Gfx::TextWrapping text_wrapping() const { return m_text_wrapping; }
|
|
|
|
|
void set_text_wrapping(Gfx::TextWrapping text_wrapping) { m_text_wrapping = text_wrapping; }
|
|
|
|
|
|
2019-03-22 00:20:48 -03:00
|
|
|
bool should_stretch_icon() const { return m_should_stretch_icon; }
|
|
|
|
|
void set_should_stretch_icon(bool b) { m_should_stretch_icon = b; }
|
|
|
|
|
|
2020-12-20 08:35:10 -03:00
|
|
|
bool is_autosize() const { return m_autosize; }
|
|
|
|
|
void set_autosize(bool);
|
2019-03-20 18:01:02 -03:00
|
|
|
|
2021-07-25 18:20:11 -03:00
|
|
|
int preferred_height() const;
|
2021-03-01 16:52:04 -03:00
|
|
|
|
2021-07-25 18:20:11 -03:00
|
|
|
Gfx::IntRect text_rect() const;
|
2020-12-26 11:34:49 -03:00
|
|
|
|
2019-09-21 09:22:49 -03:00
|
|
|
protected:
|
2020-12-26 09:10:50 -03:00
|
|
|
explicit Label(String text = {});
|
2019-09-21 09:22:49 -03:00
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
virtual void paint_event(PaintEvent&) override;
|
2020-12-26 09:10:50 -03:00
|
|
|
virtual void did_change_text() { }
|
2019-01-20 01:49:48 -02:00
|
|
|
|
2019-09-21 09:22:49 -03:00
|
|
|
private:
|
2020-12-20 08:35:10 -03:00
|
|
|
void size_to_fit();
|
|
|
|
|
|
2019-01-20 01:49:48 -02:00
|
|
|
String m_text;
|
2020-02-06 07:56:38 -03:00
|
|
|
RefPtr<Gfx::Bitmap> m_icon;
|
|
|
|
|
Gfx::TextAlignment m_text_alignment { Gfx::TextAlignment::Center };
|
2021-07-29 17:06:46 -03:00
|
|
|
Gfx::TextWrapping m_text_wrapping { Gfx::TextWrapping::Wrap };
|
2019-03-22 00:20:48 -03:00
|
|
|
bool m_should_stretch_icon { false };
|
2020-12-20 08:35:10 -03:00
|
|
|
bool m_autosize { false };
|
2019-01-20 01:49:48 -02:00
|
|
|
};
|
2020-02-02 11:07:41 -03:00
|
|
|
|
|
|
|
|
}
|