mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:57:47 +00:00
LibGUI: Add content margins
Introduce the basic interface through which widgets can define a rect relative to which Layout margins are now applied.
This commit is contained in:
parent
8249ea792e
commit
72139e1262
2 changed files with 11 additions and 5 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <AK/JsonObject.h>
|
#include <AK/JsonObject.h>
|
||||||
#include <LibGUI/BoxLayout.h>
|
#include <LibGUI/BoxLayout.h>
|
||||||
|
#include <LibGUI/Margins.h>
|
||||||
#include <LibGUI/Widget.h>
|
#include <LibGUI/Widget.h>
|
||||||
#include <LibGfx/Orientation.h>
|
#include <LibGfx/Orientation.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -125,7 +126,8 @@ void BoxLayout::run(Widget& widget)
|
||||||
if (items.is_empty())
|
if (items.is_empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int available_size = widget.size().primary_size_for_orientation(orientation()) - spacing() * (items.size() - 1);
|
Gfx::IntRect content_rect = widget.content_rect();
|
||||||
|
int available_size = content_rect.size().primary_size_for_orientation(orientation()) - spacing() * (items.size() - 1);
|
||||||
int unfinished_items = items.size();
|
int unfinished_items = items.size();
|
||||||
|
|
||||||
if (orientation() == Gfx::Orientation::Horizontal)
|
if (orientation() == Gfx::Orientation::Horizontal)
|
||||||
|
@ -180,10 +182,10 @@ void BoxLayout::run(Widget& widget)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass 3: Place the widgets.
|
// Pass 3: Place the widgets.
|
||||||
int current_x = margins().left();
|
int current_x = margins().left() + content_rect.x();
|
||||||
int current_y = margins().top();
|
int current_y = margins().top() + content_rect.y();
|
||||||
|
|
||||||
auto widget_rect_with_margins_subtracted = widget.rect();
|
auto widget_rect_with_margins_subtracted = content_rect;
|
||||||
widget_rect_with_margins_subtracted.take_from_left(margins().left());
|
widget_rect_with_margins_subtracted.take_from_left(margins().left());
|
||||||
widget_rect_with_margins_subtracted.take_from_top(margins().top());
|
widget_rect_with_margins_subtracted.take_from_top(margins().top());
|
||||||
widget_rect_with_margins_subtracted.take_from_right(margins().right());
|
widget_rect_with_margins_subtracted.take_from_right(margins().right());
|
||||||
|
@ -195,7 +197,7 @@ void BoxLayout::run(Widget& widget)
|
||||||
rect.set_primary_size_for_orientation(orientation(), item.size);
|
rect.set_primary_size_for_orientation(orientation(), item.size);
|
||||||
|
|
||||||
if (item.widget) {
|
if (item.widget) {
|
||||||
int secondary = widget.size().secondary_size_for_orientation(orientation());
|
int secondary = widget.content_size().secondary_size_for_orientation(orientation());
|
||||||
if (orientation() == Gfx::Orientation::Horizontal)
|
if (orientation() == Gfx::Orientation::Horizontal)
|
||||||
secondary -= margins().top() + margins().bottom();
|
secondary -= margins().top() + margins().bottom();
|
||||||
else
|
else
|
||||||
|
|
|
@ -134,8 +134,12 @@ public:
|
||||||
int height() const { return m_relative_rect.height(); }
|
int height() const { return m_relative_rect.height(); }
|
||||||
int length(Orientation orientation) const { return orientation == Orientation::Vertical ? height() : width(); }
|
int length(Orientation orientation) const { return orientation == Orientation::Vertical ? height() : width(); }
|
||||||
|
|
||||||
|
virtual Margins content_margins() const { return { 0 }; }
|
||||||
|
|
||||||
Gfx::IntRect rect() const { return { 0, 0, width(), height() }; }
|
Gfx::IntRect rect() const { return { 0, 0, width(), height() }; }
|
||||||
Gfx::IntSize size() const { return m_relative_rect.size(); }
|
Gfx::IntSize size() const { return m_relative_rect.size(); }
|
||||||
|
Gfx::IntRect content_rect() const { return this->content_margins().applied_to(rect()); };
|
||||||
|
Gfx::IntSize content_size() const { return this->content_rect().size(); };
|
||||||
|
|
||||||
// Invalidate the widget (or an area thereof), causing a repaint to happen soon.
|
// Invalidate the widget (or an area thereof), causing a repaint to happen soon.
|
||||||
void update();
|
void update();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue