2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2023-02-20 19:03:44 +01:00
|
|
|
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
|
2022-02-26 10:50:04 -07:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2019-01-20 04:49:48 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2020-02-06 20:33:02 +01:00
|
|
|
#include <LibGUI/Frame.h>
|
2020-09-18 09:49:51 +02:00
|
|
|
#include <LibGfx/TextAlignment.h>
|
2021-07-29 20:06:46 +00:00
|
|
|
#include <LibGfx/TextWrapping.h>
|
2019-02-12 15:23:07 +01:00
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
|
|
class Label : public Frame {
|
2020-12-26 13:10:50 +01:00
|
|
|
C_OBJECT(Label);
|
|
|
|
|
|
2019-01-20 04:49:48 +01:00
|
|
|
public:
|
2022-02-26 10:50:04 -07:00
|
|
|
virtual ~Label() override = default;
|
2019-01-20 04:49:48 +01:00
|
|
|
|
2023-04-29 10:41:48 -04:00
|
|
|
String const& text() const { return m_text; }
|
|
|
|
|
void set_text(String);
|
2019-01-20 04:49:48 +01:00
|
|
|
|
2020-02-06 11:56:38 +01: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 15:23:07 +01:00
|
|
|
|
2021-07-29 20:06:46 +00:00
|
|
|
Gfx::TextWrapping text_wrapping() const { return m_text_wrapping; }
|
|
|
|
|
void set_text_wrapping(Gfx::TextWrapping text_wrapping) { m_text_wrapping = text_wrapping; }
|
|
|
|
|
|
2020-12-20 12:35:10 +01:00
|
|
|
bool is_autosize() const { return m_autosize; }
|
2022-03-31 18:14:36 -07:00
|
|
|
void set_autosize(bool, size_t padding = 0);
|
2019-03-20 22:01:02 +01:00
|
|
|
|
2023-04-14 08:54:12 -04:00
|
|
|
virtual Optional<UISize> calculated_min_size() const override;
|
2022-02-22 20:25:30 +01:00
|
|
|
virtual Optional<UISize> calculated_preferred_size() const override;
|
|
|
|
|
int text_calculated_preferred_height() const;
|
2023-02-09 15:21:15 +01:00
|
|
|
int text_calculated_preferred_width() const;
|
2021-03-01 14:52:04 -05:00
|
|
|
|
2021-07-25 21:20:11 +00:00
|
|
|
Gfx::IntRect text_rect() const;
|
2020-12-26 15:34:49 +01:00
|
|
|
|
2019-09-21 14:22:49 +02:00
|
|
|
protected:
|
2023-04-29 10:41:48 -04:00
|
|
|
explicit Label(String text = {});
|
2019-09-21 14:22:49 +02:00
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
virtual void paint_event(PaintEvent&) override;
|
2023-04-14 08:54:16 -04:00
|
|
|
virtual void did_change_font() override;
|
2020-12-26 13:10:50 +01:00
|
|
|
virtual void did_change_text() { }
|
2019-01-20 04:49:48 +01:00
|
|
|
|
2019-09-21 14:22:49 +02:00
|
|
|
private:
|
2020-12-20 12:35:10 +01:00
|
|
|
void size_to_fit();
|
|
|
|
|
|
2023-04-29 10:41:48 -04:00
|
|
|
String m_text;
|
2020-02-06 11:56:38 +01:00
|
|
|
Gfx::TextAlignment m_text_alignment { Gfx::TextAlignment::Center };
|
2021-07-29 20:06:46 +00:00
|
|
|
Gfx::TextWrapping m_text_wrapping { Gfx::TextWrapping::Wrap };
|
2020-12-20 12:35:10 +01:00
|
|
|
bool m_autosize { false };
|
2022-03-31 18:14:36 -07:00
|
|
|
size_t m_autosize_padding { 0 };
|
2019-01-20 04:49:48 +01:00
|
|
|
};
|
2020-02-02 15:07:41 +01:00
|
|
|
|
|
|
|
|
}
|