2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2021-05-26 21:59:10 +02:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2022-02-26 10:50:04 -07:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2019-03-30 13:53:30 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
2020-08-26 00:06:48 +02:00
|
|
|
#include <LibGUI/Widget.h>
|
2019-03-30 13:53:30 +01:00
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
namespace GUI {
|
|
|
|
|
|
2020-08-26 00:06:48 +02:00
|
|
|
class Splitter : public Widget {
|
|
|
|
|
C_OBJECT(Splitter);
|
|
|
|
|
|
2019-03-30 13:53:30 +01:00
|
|
|
public:
|
2022-08-05 06:30:47 -04:00
|
|
|
enum class OpportunisticResizee {
|
2022-02-20 08:07:31 -05:00
|
|
|
First,
|
|
|
|
|
Second
|
|
|
|
|
};
|
|
|
|
|
|
2022-02-26 10:50:04 -07:00
|
|
|
virtual ~Splitter() override = default;
|
2019-03-30 13:53:30 +01:00
|
|
|
|
|
|
|
|
protected:
|
2020-02-23 12:07:13 +01:00
|
|
|
explicit Splitter(Gfx::Orientation);
|
2019-09-21 16:11:02 +02:00
|
|
|
|
2020-02-11 11:33:01 +01:00
|
|
|
virtual void paint_event(PaintEvent&) override;
|
|
|
|
|
virtual void resize_event(ResizeEvent&) override;
|
2020-02-02 15:07:41 +01:00
|
|
|
virtual void mousedown_event(MouseEvent&) override;
|
|
|
|
|
virtual void mousemove_event(MouseEvent&) override;
|
|
|
|
|
virtual void mouseup_event(MouseEvent&) override;
|
2020-02-02 12:34:39 +01:00
|
|
|
virtual void leave_event(Core::Event&) override;
|
2019-03-30 13:53:30 +01:00
|
|
|
|
2020-02-11 11:33:01 +01:00
|
|
|
virtual void did_layout() override;
|
2022-02-20 08:12:34 -05:00
|
|
|
virtual void custom_layout() override;
|
2020-02-11 11:33:01 +01:00
|
|
|
|
2022-08-05 06:30:47 -04:00
|
|
|
OpportunisticResizee opportunisitic_resizee() const { return m_opportunistic_resizee; }
|
|
|
|
|
void set_opportunisitic_resizee(OpportunisticResizee resizee) { m_opportunistic_resizee = resizee; }
|
2022-02-20 08:07:31 -05:00
|
|
|
|
2019-03-30 13:53:30 +01:00
|
|
|
private:
|
2020-08-26 22:24:19 -06:00
|
|
|
void override_cursor(bool do_override);
|
2021-09-14 21:08:57 +02:00
|
|
|
Gfx::IntRect rect_between_widgets(GUI::Widget const& first_widget, GUI::Widget const& second_widget, bool honor_grabbable_margins) const;
|
2020-02-11 10:56:26 +01:00
|
|
|
|
2020-02-16 09:17:49 +01:00
|
|
|
Gfx::Orientation m_orientation;
|
2019-03-30 13:53:30 +01:00
|
|
|
bool m_resizing { false };
|
2020-08-26 22:24:19 -06:00
|
|
|
bool m_overriding_cursor { false };
|
2020-06-10 10:57:59 +02:00
|
|
|
Gfx::IntPoint m_resize_origin;
|
2020-02-02 15:07:41 +01:00
|
|
|
WeakPtr<Widget> m_first_resizee;
|
|
|
|
|
WeakPtr<Widget> m_second_resizee;
|
2020-06-10 10:57:59 +02:00
|
|
|
Gfx::IntSize m_first_resizee_start_size;
|
|
|
|
|
Gfx::IntSize m_second_resizee_start_size;
|
2022-08-05 06:30:47 -04:00
|
|
|
OpportunisticResizee m_opportunistic_resizee { OpportunisticResizee::Second };
|
2022-02-20 08:12:34 -05:00
|
|
|
size_t m_last_child_count { 0 };
|
2022-08-05 06:25:56 -04:00
|
|
|
int m_first_resizee_max_size { 0 };
|
|
|
|
|
int m_second_resizee_max_size { 0 };
|
2021-05-26 21:59:10 +02:00
|
|
|
|
|
|
|
|
void recompute_grabbables();
|
|
|
|
|
|
|
|
|
|
struct Grabbable {
|
|
|
|
|
// Index in m_grabbables, for convenience.
|
|
|
|
|
size_t index { 0 };
|
|
|
|
|
|
|
|
|
|
// The full grabbable rect, includes the content margin of adjacent elements.
|
|
|
|
|
Gfx::IntRect grabbable_rect;
|
|
|
|
|
// The rect used for painting. Does not include content margins.
|
|
|
|
|
Gfx::IntRect paint_rect;
|
|
|
|
|
|
|
|
|
|
WeakPtr<Widget> first_widget;
|
|
|
|
|
WeakPtr<Widget> second_widget;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Grabbable* grabbable_at(Gfx::IntPoint const&);
|
|
|
|
|
void set_hovered_grabbable(Grabbable*);
|
|
|
|
|
|
|
|
|
|
Vector<Grabbable> m_grabbables;
|
|
|
|
|
Optional<size_t> m_hovered_index;
|
2019-03-30 13:53:30 +01:00
|
|
|
};
|
2020-02-02 15:07:41 +01:00
|
|
|
|
2020-02-06 14:40:59 +01:00
|
|
|
class VerticalSplitter final : public Splitter {
|
|
|
|
|
C_OBJECT(VerticalSplitter)
|
|
|
|
|
public:
|
2022-02-26 10:50:04 -07:00
|
|
|
virtual ~VerticalSplitter() override = default;
|
2020-02-06 14:40:59 +01:00
|
|
|
|
|
|
|
|
private:
|
2020-02-23 12:07:13 +01:00
|
|
|
VerticalSplitter()
|
|
|
|
|
: Splitter(Gfx::Orientation::Vertical)
|
2020-02-06 14:40:59 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class HorizontalSplitter final : public Splitter {
|
|
|
|
|
C_OBJECT(HorizontalSplitter)
|
|
|
|
|
public:
|
2022-02-26 10:50:04 -07:00
|
|
|
virtual ~HorizontalSplitter() override = default;
|
2020-02-06 14:40:59 +01:00
|
|
|
|
|
|
|
|
private:
|
2020-02-23 12:07:13 +01:00
|
|
|
HorizontalSplitter()
|
|
|
|
|
: Splitter(Gfx::Orientation::Horizontal)
|
2020-02-06 14:40:59 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
}
|