2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-02-10 08:07:13 -02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/OwnPtr.h>
|
|
|
|
|
#include <AK/Vector.h>
|
|
|
|
|
#include <AK/WeakPtr.h>
|
2020-03-05 05:21:46 -03:00
|
|
|
#include <LibCore/Object.h>
|
2020-02-16 05:17:49 -03:00
|
|
|
#include <LibGUI/Forward.h>
|
2020-02-06 16:33:02 -03:00
|
|
|
#include <LibGUI/Margins.h>
|
2021-01-04 14:17:14 -03:00
|
|
|
#include <LibGfx/Forward.h>
|
2019-02-10 08:07:13 -02:00
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
namespace GUI {
|
2019-02-10 08:07:13 -02:00
|
|
|
|
2020-03-05 05:21:46 -03:00
|
|
|
class Layout : public Core::Object {
|
|
|
|
|
C_OBJECT_ABSTRACT(Layout);
|
|
|
|
|
|
2019-02-10 08:07:13 -02:00
|
|
|
public:
|
2020-02-02 11:07:41 -03:00
|
|
|
virtual ~Layout();
|
2019-02-10 08:07:13 -02:00
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
void add_widget(Widget&);
|
|
|
|
|
void insert_widget_before(Widget& widget, Widget& before_widget);
|
|
|
|
|
void add_layout(OwnPtr<Layout>&&);
|
2019-05-08 22:06:20 -03:00
|
|
|
void add_spacer();
|
2019-02-10 08:07:13 -02:00
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
void remove_widget(Widget&);
|
2019-04-03 20:44:35 -03:00
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
virtual void run(Widget&) = 0;
|
2021-01-04 14:17:14 -03:00
|
|
|
virtual Gfx::IntSize preferred_size() const = 0;
|
2019-02-10 08:07:13 -02:00
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
void notify_adopted(Badge<Widget>, Widget&);
|
|
|
|
|
void notify_disowned(Badge<Widget>, Widget&);
|
2019-02-10 08:07:13 -02:00
|
|
|
|
2020-12-29 21:23:15 -03:00
|
|
|
const Margins& margins() const { return m_margins; }
|
2020-02-02 11:07:41 -03:00
|
|
|
void set_margins(const Margins&);
|
2019-02-20 05:04:28 -03:00
|
|
|
|
|
|
|
|
int spacing() const { return m_spacing; }
|
|
|
|
|
void set_spacing(int);
|
|
|
|
|
|
2019-02-10 08:07:13 -02:00
|
|
|
protected:
|
2020-03-05 05:21:46 -03:00
|
|
|
Layout();
|
|
|
|
|
|
2019-02-10 08:07:13 -02:00
|
|
|
struct Entry {
|
2019-06-07 12:13:23 -03:00
|
|
|
enum class Type {
|
2019-05-08 22:06:20 -03:00
|
|
|
Invalid = 0,
|
|
|
|
|
Widget,
|
|
|
|
|
Layout,
|
|
|
|
|
Spacer,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Type type { Type::Invalid };
|
2020-02-02 11:07:41 -03:00
|
|
|
WeakPtr<Widget> widget;
|
|
|
|
|
OwnPtr<Layout> layout;
|
2019-02-10 08:07:13 -02:00
|
|
|
};
|
2019-05-08 22:06:20 -03:00
|
|
|
void add_entry(Entry&&);
|
|
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
WeakPtr<Widget> m_owner;
|
2019-02-10 08:07:13 -02:00
|
|
|
Vector<Entry> m_entries;
|
2019-02-20 05:04:28 -03:00
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
Margins m_margins;
|
2019-09-04 13:54:03 -03:00
|
|
|
int m_spacing { 3 };
|
2019-02-10 08:07:13 -02:00
|
|
|
};
|
2020-02-02 11:07:41 -03:00
|
|
|
|
|
|
|
|
}
|