mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:27:44 +00:00
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.
This commit is contained in:
parent
2cf1dd5b6f
commit
2def3d8d3f
22 changed files with 411 additions and 29 deletions
|
@ -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 };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue