summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-07-20 22:17:46 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-07-20 22:17:46 +0200
commit5b440a72f957e31e526d7f11f918dd6ec749c9bf (patch)
treed9f2449b7877f1757acfbf474c397523f7b9e8e5
parent2a14ba99a77894a42af1551013269aed840fc3d1 (diff)
downloadserenity-5b440a72f957e31e526d7f11f918dd6ec749c9bf.zip
GSplitter: Implement using the orientation-based geometry helpers.
-rw-r--r--Libraries/LibGUI/GSplitter.cpp43
1 files changed, 14 insertions, 29 deletions
diff --git a/Libraries/LibGUI/GSplitter.cpp b/Libraries/LibGUI/GSplitter.cpp
index e6942e58ae..60574e35fc 100644
--- a/Libraries/LibGUI/GSplitter.cpp
+++ b/Libraries/LibGUI/GSplitter.cpp
@@ -36,13 +36,13 @@ void GSplitter::mousedown_event(GMouseEvent& event)
if (event.button() != GMouseButton::Left)
return;
m_resizing = true;
- int x_or_y = m_orientation == Orientation::Horizontal ? event.x() : event.y();
+ int x_or_y = event.position().primary_offset_for_orientation(m_orientation);
GWidget* first_resizee { nullptr };
GWidget* second_resizee { nullptr };
int fudge = layout()->spacing();
for_each_child_widget([&](auto& child) {
- int child_start = m_orientation == Orientation::Horizontal ? child.relative_rect().left() : child.relative_rect().top();
- int child_end = m_orientation == Orientation::Horizontal ? child.relative_rect().right() : child.relative_rect().bottom();
+ int child_start = child.relative_rect().first_edge_for_orientation(m_orientation);
+ int child_end = child.relative_rect().last_edge_for_orientation(m_orientation);
if (x_or_y > child_end && (x_or_y - fudge) <= child_end)
first_resizee = &child;
if (x_or_y < child_start && (x_or_y + fudge) >= child_start)
@@ -71,34 +71,19 @@ void GSplitter::mousemove_event(GMouseEvent& event)
int minimum_size = 0;
auto new_first_resizee_size = m_first_resizee_start_size;
auto new_second_resizee_size = m_second_resizee_start_size;
- if (m_orientation == Orientation::Horizontal) {
- new_first_resizee_size.set_width(new_first_resizee_size.width() + delta.x());
- new_second_resizee_size.set_width(new_second_resizee_size.width() - delta.x());
- if (new_first_resizee_size.width() < minimum_size) {
- int correction = minimum_size - new_first_resizee_size.width();
- new_first_resizee_size.set_width(new_first_resizee_size.width() + correction);
- new_second_resizee_size.set_width(new_second_resizee_size.width() - correction);
- }
- if (new_second_resizee_size.width() < minimum_size) {
- int correction = minimum_size - new_second_resizee_size.width();
- new_second_resizee_size.set_width(new_second_resizee_size.width() + correction);
- new_first_resizee_size.set_width(new_first_resizee_size.width() - correction);
- }
- } else {
- new_first_resizee_size.set_height(new_first_resizee_size.height() + delta.y());
- new_second_resizee_size.set_height(new_second_resizee_size.height() - delta.y());
+ new_first_resizee_size.set_primary_size_for_orientation(m_orientation, new_first_resizee_size.primary_size_for_orientation(m_orientation) + delta.primary_offset_for_orientation(m_orientation));
+ new_second_resizee_size.set_primary_size_for_orientation(m_orientation, new_second_resizee_size.primary_size_for_orientation(m_orientation) - delta.primary_offset_for_orientation(m_orientation));
- if (new_first_resizee_size.height() < minimum_size) {
- int correction = minimum_size - new_first_resizee_size.height();
- new_first_resizee_size.set_height(new_first_resizee_size.height() + correction);
- new_second_resizee_size.set_height(new_second_resizee_size.height() - correction);
- }
- if (new_second_resizee_size.height() < minimum_size) {
- int correction = minimum_size - new_second_resizee_size.height();
- new_second_resizee_size.set_height(new_second_resizee_size.height() + correction);
- new_first_resizee_size.set_height(new_first_resizee_size.height() - correction);
- }
+ if (new_first_resizee_size.primary_size_for_orientation(m_orientation) < minimum_size) {
+ int correction = minimum_size - new_first_resizee_size.primary_size_for_orientation(m_orientation);
+ new_first_resizee_size.set_primary_size_for_orientation(m_orientation, new_first_resizee_size.primary_size_for_orientation(m_orientation) + correction);
+ new_second_resizee_size.set_primary_size_for_orientation(m_orientation, new_second_resizee_size.primary_size_for_orientation(m_orientation) - correction);
+ }
+ if (new_second_resizee_size.primary_size_for_orientation(m_orientation) < minimum_size) {
+ int correction = minimum_size - new_second_resizee_size.primary_size_for_orientation(m_orientation);
+ new_second_resizee_size.set_primary_size_for_orientation(m_orientation, new_second_resizee_size.primary_size_for_orientation(m_orientation) + correction);
+ new_first_resizee_size.set_primary_size_for_orientation(m_orientation, new_first_resizee_size.primary_size_for_orientation(m_orientation) - correction);
}
m_first_resizee->set_preferred_size(new_first_resizee_size);
m_second_resizee->set_preferred_size(new_second_resizee_size);