ladybird/Userland/Libraries/LibGUI/Label.h

59 lines
1.6 KiB
C
Raw Normal View History

/*
2023-02-20 19:03:44 +01:00
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
*
* 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 = default;
2023-04-29 10:41:48 -04:00
String const& text() const { return m_text; }
void set_text(String);
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 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
virtual Optional<UISize> calculated_min_size() const override;
virtual Optional<UISize> calculated_preferred_size() const override;
int text_calculated_preferred_height() const;
int text_calculated_preferred_width() const;
Gfx::IntRect text_rect() const;
protected:
2023-04-29 10:41:48 -04:00
explicit Label(String text = {});
virtual void paint_event(PaintEvent&) override;
virtual void did_change_font() override;
virtual void did_change_text() { }
private:
void size_to_fit();
2023-04-29 10:41:48 -04:00
String m_text;
Gfx::TextAlignment m_text_alignment { Gfx::TextAlignment::Center };
Gfx::TextWrapping m_text_wrapping { Gfx::TextWrapping::Wrap };
bool m_autosize { false };
2022-03-31 18:14:36 -07:00
size_t m_autosize_padding { 0 };
};
}