mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-02 01:08:48 +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 {
|
||||
|
||||
BoxLayout::BoxLayout(Orientation orientation)
|
||||
: m_orientation(orientation)
|
||||
BoxLayout::BoxLayout(Orientation orientation, Margins margins, int spacing)
|
||||
: Layout(margins, spacing)
|
||||
, m_orientation(orientation)
|
||||
{
|
||||
register_property(
|
||||
"orientation", [this] { return m_orientation == Gfx::Orientation::Vertical ? "Vertical" : "Horizontal"; }, nullptr);
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
virtual UISize min_size() const override;
|
||||
|
||||
protected:
|
||||
explicit BoxLayout(Gfx::Orientation);
|
||||
explicit BoxLayout(Gfx::Orientation, Margins = {}, int spacing = Layout::default_spacing);
|
||||
|
||||
private:
|
||||
Gfx::Orientation m_orientation;
|
||||
|
@ -36,8 +36,8 @@ class VerticalBoxLayout final : public BoxLayout {
|
|||
C_OBJECT(VerticalBoxLayout);
|
||||
|
||||
private:
|
||||
explicit VerticalBoxLayout()
|
||||
: BoxLayout(Gfx::Orientation::Vertical)
|
||||
explicit VerticalBoxLayout(Margins margins = {}, int spacing = Layout::default_spacing)
|
||||
: BoxLayout(Gfx::Orientation::Vertical, margins, spacing)
|
||||
{
|
||||
}
|
||||
virtual ~VerticalBoxLayout() override = default;
|
||||
|
@ -47,8 +47,8 @@ class HorizontalBoxLayout final : public BoxLayout {
|
|||
C_OBJECT(HorizontalBoxLayout);
|
||||
|
||||
private:
|
||||
explicit HorizontalBoxLayout()
|
||||
: BoxLayout(Gfx::Orientation::Horizontal)
|
||||
explicit HorizontalBoxLayout(Margins margins = {}, int spacing = Layout::default_spacing)
|
||||
: BoxLayout(Gfx::Orientation::Horizontal, margins, spacing)
|
||||
{
|
||||
}
|
||||
virtual ~HorizontalBoxLayout() override = default;
|
||||
|
|
|
@ -14,7 +14,9 @@ REGISTER_ABSTRACT_CORE_OBJECT(GUI, Layout)
|
|||
|
||||
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_MARGINS_PROPERTY("margins", margins, set_margins);
|
||||
|
|
|
@ -58,11 +58,12 @@ public:
|
|||
Margins const& margins() const { return m_margins; }
|
||||
void set_margins(Margins const&);
|
||||
|
||||
static constexpr int default_spacing = 3;
|
||||
int spacing() const { return m_spacing; }
|
||||
void set_spacing(int);
|
||||
|
||||
protected:
|
||||
Layout();
|
||||
Layout(Margins, int spacing);
|
||||
|
||||
struct Entry {
|
||||
enum class Type {
|
||||
|
@ -83,7 +84,7 @@ protected:
|
|||
Vector<Entry> m_entries;
|
||||
|
||||
Margins m_margins;
|
||||
int m_spacing { 3 };
|
||||
int m_spacing { default_spacing };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue