summaryrefslogtreecommitdiff
path: root/LibGUI/GWidget.h
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-02-10 11:07:13 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-02-10 11:07:13 +0100
commit2def3d8d3ff3c913919cd64b2bf75b77ee57d1cf (patch)
treeb4e92858629468605876ef0e9c48e9391019843e /LibGUI/GWidget.h
parent2cf1dd5b6f10b898f24203c879290d665531a989 (diff)
downloadserenity-2def3d8d3ff3c913919cd64b2bf75b77ee57d1cf.zip
LibGUI: Start adding an automatic widget layout system.
My needs are really quite simple, so I'm just going to add what I need as I go along. The first thing I needed was a simple box layout with widgets being able to say whether they prefer fixed or fill for both their vertical and horizontal sizes. I also made a simple GStatusBar so FileManager can show how many bytes worth of files are in the current directory.
Diffstat (limited to 'LibGUI/GWidget.h')
-rw-r--r--LibGUI/GWidget.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/LibGUI/GWidget.h b/LibGUI/GWidget.h
index cb40a6dfa0..8c64635898 100644
--- a/LibGUI/GWidget.h
+++ b/LibGUI/GWidget.h
@@ -5,16 +5,32 @@
#include <SharedGraphics/Rect.h>
#include <SharedGraphics/Color.h>
#include <SharedGraphics/Font.h>
+#include <AK/Badge.h>
#include <AK/AKString.h>
class GraphicsBitmap;
+class GLayout;
class GWindow;
+enum class SizePolicy { Fixed, Fill };
+enum class Orientation { Horizontal, Vertical };
+
class GWidget : public GObject {
public:
explicit GWidget(GWidget* parent = nullptr);
virtual ~GWidget() override;
+ GLayout* layout() { return m_layout.ptr(); }
+ void set_layout(OwnPtr<GLayout>&&);
+
+ SizePolicy horizontal_size_policy() const { return m_horizontal_size_policy; }
+ SizePolicy vertical_size_policy() const { return m_vertical_size_policy; }
+ SizePolicy size_policy(Orientation orientation) { return orientation == Orientation::Horizontal ? m_horizontal_size_policy : m_vertical_size_policy; }
+ void set_size_policy(SizePolicy horizontal_policy, SizePolicy vertical_policy);
+
+ Size preferred_size() const { return m_preferred_size; }
+ void set_preferred_size(const Size&);
+
virtual void event(GEvent&) override;
virtual void paint_event(GPaintEvent&);
virtual void resize_event(GResizeEvent&);
@@ -100,16 +116,26 @@ public:
void set_global_cursor_tracking(bool);
bool global_cursor_tracking() const;
+ void notify_layout_changed(Badge<GLayout>);
+
private:
void handle_paint_event(GPaintEvent&);
+ void handle_resize_event(GResizeEvent&);
+ void do_layout();
+ void invalidate_layout();
GWindow* m_window { nullptr };
+ OwnPtr<GLayout> m_layout;
Rect m_relative_rect;
Color m_background_color { 0xffffff };
Color m_foreground_color { 0x000000 };
RetainPtr<Font> m_font;
+ SizePolicy m_horizontal_size_policy { SizePolicy::Fill };
+ SizePolicy m_vertical_size_policy { SizePolicy::Fill };
+ Size m_preferred_size;
+
bool m_has_pending_paint_event { false };
bool m_fill_with_background_color { true };
};