mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-01 16:58:52 +00:00
LibGUI: Allow specifying Layout margins and spacing in the constructor
This is comfier than `my_widget->layout()->set_margins(...)`.
This commit is contained in:
parent
ab6ef53247
commit
43dddafd16
Notes:
sideshowbarker
2024-07-17 02:06:40 +09:00
Author: https://github.com/AtkinsSJ
Commit: 43dddafd16
Pull-request: https://github.com/SerenityOS/serenity/pull/17495
Reviewed-by: https://github.com/awesomekling ✅
4 changed files with 14 additions and 10 deletions
|
@ -17,8 +17,9 @@ REGISTER_LAYOUT(GUI, VerticalBoxLayout)
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
BoxLayout::BoxLayout(Orientation orientation)
|
BoxLayout::BoxLayout(Orientation orientation, Margins margins, int spacing)
|
||||||
: m_orientation(orientation)
|
: Layout(margins, spacing)
|
||||||
|
, m_orientation(orientation)
|
||||||
{
|
{
|
||||||
register_property(
|
register_property(
|
||||||
"orientation", [this] { return m_orientation == Gfx::Orientation::Vertical ? "Vertical" : "Horizontal"; }, nullptr);
|
"orientation", [this] { return m_orientation == Gfx::Orientation::Vertical ? "Vertical" : "Horizontal"; }, nullptr);
|
||||||
|
|
|
@ -26,7 +26,7 @@ public:
|
||||||
virtual UISize min_size() const override;
|
virtual UISize min_size() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit BoxLayout(Gfx::Orientation);
|
explicit BoxLayout(Gfx::Orientation, Margins = {}, int spacing = Layout::default_spacing);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Gfx::Orientation m_orientation;
|
Gfx::Orientation m_orientation;
|
||||||
|
@ -36,8 +36,8 @@ class VerticalBoxLayout final : public BoxLayout {
|
||||||
C_OBJECT(VerticalBoxLayout);
|
C_OBJECT(VerticalBoxLayout);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit VerticalBoxLayout()
|
explicit VerticalBoxLayout(Margins margins = {}, int spacing = Layout::default_spacing)
|
||||||
: BoxLayout(Gfx::Orientation::Vertical)
|
: BoxLayout(Gfx::Orientation::Vertical, margins, spacing)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
virtual ~VerticalBoxLayout() override = default;
|
virtual ~VerticalBoxLayout() override = default;
|
||||||
|
@ -47,8 +47,8 @@ class HorizontalBoxLayout final : public BoxLayout {
|
||||||
C_OBJECT(HorizontalBoxLayout);
|
C_OBJECT(HorizontalBoxLayout);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit HorizontalBoxLayout()
|
explicit HorizontalBoxLayout(Margins margins = {}, int spacing = Layout::default_spacing)
|
||||||
: BoxLayout(Gfx::Orientation::Horizontal)
|
: BoxLayout(Gfx::Orientation::Horizontal, margins, spacing)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
virtual ~HorizontalBoxLayout() override = default;
|
virtual ~HorizontalBoxLayout() override = default;
|
||||||
|
|
|
@ -14,7 +14,9 @@ REGISTER_ABSTRACT_CORE_OBJECT(GUI, Layout)
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
Layout::Layout()
|
Layout::Layout(Margins initial_margins, int spacing)
|
||||||
|
: m_margins(initial_margins)
|
||||||
|
, m_spacing(spacing)
|
||||||
{
|
{
|
||||||
REGISTER_INT_PROPERTY("spacing", spacing, set_spacing);
|
REGISTER_INT_PROPERTY("spacing", spacing, set_spacing);
|
||||||
REGISTER_MARGINS_PROPERTY("margins", margins, set_margins);
|
REGISTER_MARGINS_PROPERTY("margins", margins, set_margins);
|
||||||
|
|
|
@ -58,11 +58,12 @@ public:
|
||||||
Margins const& margins() const { return m_margins; }
|
Margins const& margins() const { return m_margins; }
|
||||||
void set_margins(Margins const&);
|
void set_margins(Margins const&);
|
||||||
|
|
||||||
|
static constexpr int default_spacing = 3;
|
||||||
int spacing() const { return m_spacing; }
|
int spacing() const { return m_spacing; }
|
||||||
void set_spacing(int);
|
void set_spacing(int);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Layout();
|
Layout(Margins, int spacing);
|
||||||
|
|
||||||
struct Entry {
|
struct Entry {
|
||||||
enum class Type {
|
enum class Type {
|
||||||
|
@ -83,7 +84,7 @@ protected:
|
||||||
Vector<Entry> m_entries;
|
Vector<Entry> m_entries;
|
||||||
|
|
||||||
Margins m_margins;
|
Margins m_margins;
|
||||||
int m_spacing { 3 };
|
int m_spacing { default_spacing };
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue