ladybird/Userland/Libraries/LibGUI/Label.h
sin-ack e11940fd01 Userland: Move text wrapping/elision into the new TextLayout :^)
This class now contains all the fun bits about laying out text in a
rect. It will handle line wrapping at a certain width, cutting off lines
that don't fit the given rect, and handling text elision.
Painter::draw_text now internally uses this.

Future work here would be not laying out text twice (once actually
preparing the lines to be rendered and once to get the bounding box),
and possibly adding left elision if necessary.

Additionally, this commit makes the Utf32View versions of
Painter::draw_text convert to Utf8View internally. The intention is to
completely remove those versions, but they're kept at the moment to keep
the scope of this PR small.
2021-07-26 21:14:39 +04:30

57 lines
1.3 KiB
C++

/*
* 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>
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; }
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 };
bool m_should_stretch_icon { false };
bool m_autosize { false };
};
}