summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMustafa Quraish <mustafaq9@gmail.com>2021-09-02 20:16:19 -0400
committerAndreas Kling <kling@serenityos.org>2021-09-07 00:48:48 +0200
commit285a888b61e53e8de917a3adda3ba5f8644cf91d (patch)
tree0984db520fb26f9d5638595c99987de38d870578
parentfd895c7a24d4e24e2d1359dfa93403d811420967 (diff)
downloadserenity-285a888b61e53e8de917a3adda3ba5f8644cf91d.zip
PixelPaint: Fix layer dragging bug
A previous commit I made broke layer dragging since the hole_index was always being computed with respect to the top of the layer list widget, however we were now drawing layers from the bottom. When you didn't have enough layers to fill up the full height, dragging them around would be weird. This patch computes the hole index correctly using the same offset we start drawing from, and fixes the behavior.
-rw-r--r--Userland/Applications/PixelPaint/LayerListWidget.cpp12
-rw-r--r--Userland/Applications/PixelPaint/LayerListWidget.h1
2 files changed, 8 insertions, 5 deletions
diff --git a/Userland/Applications/PixelPaint/LayerListWidget.cpp b/Userland/Applications/PixelPaint/LayerListWidget.cpp
index 3f8018d4f1..3bd65ff67e 100644
--- a/Userland/Applications/PixelPaint/LayerListWidget.cpp
+++ b/Userland/Applications/PixelPaint/LayerListWidget.cpp
@@ -277,7 +277,9 @@ size_t LayerListWidget::hole_index_during_move() const
VERIFY(is_moving_gadget());
auto& moving_gadget = m_gadgets[m_moving_gadget_index.value()];
int center_y_of_moving_gadget = moving_gadget.rect.translated(0, moving_gadget.movement_delta.y()).center().y();
- return center_y_of_moving_gadget / vertical_step;
+
+ int top_of_gadgets = max(0, height() - m_total_gadget_height);
+ return (center_y_of_moving_gadget - top_of_gadgets) / vertical_step;
}
void LayerListWidget::select_bottom_layer()
@@ -316,8 +318,8 @@ void LayerListWidget::cycle_through_selection(int delta)
void LayerListWidget::relayout_gadgets()
{
- auto total_gadget_height = static_cast<int>(m_gadgets.size()) * vertical_step + 6;
- int y = max(0, height() - total_gadget_height);
+ m_total_gadget_height = static_cast<int>(m_gadgets.size()) * vertical_step + 6;
+ int y = max(0, height() - m_total_gadget_height);
Optional<size_t> hole_index;
if (is_moving_gadget())
@@ -334,8 +336,8 @@ void LayerListWidget::relayout_gadgets()
++index;
}
- set_content_size({ widget_inner_rect().width(), total_gadget_height });
- vertical_scrollbar().set_range(0, max(total_gadget_height - height(), 0));
+ set_content_size({ widget_inner_rect().width(), m_total_gadget_height });
+ vertical_scrollbar().set_range(0, max(m_total_gadget_height - height(), 0));
update();
}
diff --git a/Userland/Applications/PixelPaint/LayerListWidget.h b/Userland/Applications/PixelPaint/LayerListWidget.h
index 27144a3410..458e923f5c 100644
--- a/Userland/Applications/PixelPaint/LayerListWidget.h
+++ b/Userland/Applications/PixelPaint/LayerListWidget.h
@@ -73,6 +73,7 @@ private:
Gfx::IntPoint m_moving_event_origin;
size_t m_selected_gadget_index { 0 };
+ int m_total_gadget_height { 0 };
};
}