mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-11 01:06:01 +03:00
VisualBuilder: Don't allow moving/resizing widgets that are in a layout
Also paint these widgets' grabbers differently to make it stand out visually which widgets have managed geometry. :^)
This commit is contained in:
parent
5e439bb3c8
commit
9d460d55d1
Notes:
sideshowbarker
2024-07-19 12:03:43 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/9d460d55d1f
@ -96,7 +96,11 @@ void VBForm::second_paint_event(GPaintEvent& event)
|
|||||||
for (auto& widget : m_widgets) {
|
for (auto& widget : m_widgets) {
|
||||||
if (widget.is_selected()) {
|
if (widget.is_selected()) {
|
||||||
for_each_direction([&](auto direction) {
|
for_each_direction([&](auto direction) {
|
||||||
painter.fill_rect(widget.grabber_rect(direction), Color::Black);
|
bool in_layout = widget.is_in_layout();
|
||||||
|
auto grabber_rect = widget.grabber_rect(direction);
|
||||||
|
painter.fill_rect(grabber_rect, in_layout ? Color::White : Color::Black);
|
||||||
|
if (in_layout)
|
||||||
|
painter.draw_rect(grabber_rect, Color::Black);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -211,6 +215,8 @@ void VBForm::mousedown_event(GMouseEvent& event)
|
|||||||
if (m_resize_direction == Direction::None) {
|
if (m_resize_direction == Direction::None) {
|
||||||
bool hit_grabber = false;
|
bool hit_grabber = false;
|
||||||
for_each_selected_widget([&](auto& widget) {
|
for_each_selected_widget([&](auto& widget) {
|
||||||
|
if (widget.is_in_layout())
|
||||||
|
return;
|
||||||
auto grabber = widget.grabber_at(event.position());
|
auto grabber = widget.grabber_at(event.position());
|
||||||
if (grabber != Direction::None) {
|
if (grabber != Direction::None) {
|
||||||
hit_grabber = true;
|
hit_grabber = true;
|
||||||
@ -245,6 +251,8 @@ void VBForm::mousemove_event(GMouseEvent& event)
|
|||||||
update();
|
update();
|
||||||
auto delta = event.position() - m_transform_event_origin;
|
auto delta = event.position() - m_transform_event_origin;
|
||||||
for_each_selected_widget([&](auto& widget) {
|
for_each_selected_widget([&](auto& widget) {
|
||||||
|
if (widget.is_in_layout())
|
||||||
|
return;
|
||||||
auto new_rect = widget.transform_origin_rect().translated(delta);
|
auto new_rect = widget.transform_origin_rect().translated(delta);
|
||||||
new_rect.set_x(new_rect.x() - (new_rect.x() % m_grid_size));
|
new_rect.set_x(new_rect.x() - (new_rect.x() % m_grid_size));
|
||||||
new_rect.set_y(new_rect.y() - (new_rect.y() % m_grid_size));
|
new_rect.set_y(new_rect.y() - (new_rect.y() % m_grid_size));
|
||||||
@ -301,6 +309,8 @@ void VBForm::mousemove_event(GMouseEvent& event)
|
|||||||
|
|
||||||
update();
|
update();
|
||||||
for_each_selected_widget([&](auto& widget) {
|
for_each_selected_widget([&](auto& widget) {
|
||||||
|
if (widget.is_in_layout())
|
||||||
|
return;
|
||||||
auto new_rect = widget.transform_origin_rect();
|
auto new_rect = widget.transform_origin_rect();
|
||||||
Size minimum_size { 5, 5 };
|
Size minimum_size { 5, 5 };
|
||||||
new_rect.set_x(new_rect.x() + change_x);
|
new_rect.set_x(new_rect.x() + change_x);
|
||||||
@ -317,6 +327,8 @@ void VBForm::mousemove_event(GMouseEvent& event)
|
|||||||
set_cursor_type_from_grabber(m_resize_direction);
|
set_cursor_type_from_grabber(m_resize_direction);
|
||||||
} else {
|
} else {
|
||||||
for (auto& widget : m_selected_widgets) {
|
for (auto& widget : m_selected_widgets) {
|
||||||
|
if (widget->is_in_layout())
|
||||||
|
continue;
|
||||||
auto grabber_at = widget->grabber_at(event.position());
|
auto grabber_at = widget->grabber_at(event.position());
|
||||||
set_cursor_type_from_grabber(grabber_at);
|
set_cursor_type_from_grabber(grabber_at);
|
||||||
if (grabber_at != Direction::None)
|
if (grabber_at != Direction::None)
|
||||||
|
@ -105,7 +105,8 @@ void VBWidget::add_property(const String& name, Function<GVariant(const GWidget&
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define VB_ADD_PROPERTY(gclass, name, getter, setter, variant_type) \
|
#define VB_ADD_PROPERTY(gclass, name, getter, setter, variant_type) \
|
||||||
add_property(name, \
|
add_property( \
|
||||||
|
name, \
|
||||||
[](auto& widget) -> GVariant { return ((const gclass&)widget).getter(); }, \
|
[](auto& widget) -> GVariant { return ((const gclass&)widget).getter(); }, \
|
||||||
[](auto& widget, auto& value) { ((gclass&)widget).setter(value.to_##variant_type()); })
|
[](auto& widget, auto& value) { ((gclass&)widget).setter(value.to_##variant_type()); })
|
||||||
|
|
||||||
@ -206,3 +207,12 @@ void VBWidget::capture_transform_origin_rect()
|
|||||||
{
|
{
|
||||||
m_transform_origin_rect = rect();
|
m_transform_origin_rect = rect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool VBWidget::is_in_layout() const
|
||||||
|
{
|
||||||
|
if (auto* parent_widget = m_gwidget->parent_widget()) {
|
||||||
|
if (parent_widget->layout())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@ -72,6 +72,8 @@ public:
|
|||||||
Rect transform_origin_rect() const { return m_transform_origin_rect; }
|
Rect transform_origin_rect() const { return m_transform_origin_rect; }
|
||||||
void capture_transform_origin_rect();
|
void capture_transform_origin_rect();
|
||||||
|
|
||||||
|
bool is_in_layout() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VBWidget(VBWidgetType, VBForm&, VBWidget* parent);
|
VBWidget(VBWidgetType, VBForm&, VBWidget* parent);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user