mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:07:35 +00:00
LibGUI/Splitter: Support setting minimum resizee size
This commit is contained in:
parent
fd896ad29d
commit
e5647e2ddf
2 changed files with 14 additions and 5 deletions
|
@ -18,6 +18,9 @@ namespace GUI {
|
||||||
Splitter::Splitter(Orientation orientation)
|
Splitter::Splitter(Orientation orientation)
|
||||||
: m_orientation(orientation)
|
: m_orientation(orientation)
|
||||||
{
|
{
|
||||||
|
REGISTER_INT_PROPERTY("first_resizee_minimum_size", first_resizee_minimum_size, set_first_resizee_minimum_size);
|
||||||
|
REGISTER_INT_PROPERTY("second_resizee_minimum_size", second_resizee_minimum_size, set_second_resizee_minimum_size);
|
||||||
|
|
||||||
set_background_role(ColorRole::Button);
|
set_background_role(ColorRole::Button);
|
||||||
set_layout<BoxLayout>(orientation);
|
set_layout<BoxLayout>(orientation);
|
||||||
set_fill_with_background_color(true);
|
set_fill_with_background_color(true);
|
||||||
|
@ -149,20 +152,19 @@ void Splitter::mousemove_event(MouseEvent& event)
|
||||||
m_resizing = false;
|
m_resizing = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int minimum_size = 0;
|
|
||||||
auto new_first_resizee_size = m_first_resizee_start_size;
|
auto new_first_resizee_size = m_first_resizee_start_size;
|
||||||
auto new_second_resizee_size = m_second_resizee_start_size;
|
auto new_second_resizee_size = m_second_resizee_start_size;
|
||||||
|
|
||||||
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_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));
|
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.primary_size_for_orientation(m_orientation) < minimum_size) {
|
if (new_first_resizee_size.primary_size_for_orientation(m_orientation) < m_first_resizee_minimum_size) {
|
||||||
int correction = minimum_size - new_first_resizee_size.primary_size_for_orientation(m_orientation);
|
int correction = m_first_resizee_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_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);
|
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) {
|
if (new_second_resizee_size.primary_size_for_orientation(m_orientation) < m_second_resizee_minimum_size) {
|
||||||
int correction = minimum_size - new_second_resizee_size.primary_size_for_orientation(m_orientation);
|
int correction = m_second_resizee_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_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);
|
new_first_resizee_size.set_primary_size_for_orientation(m_orientation, new_first_resizee_size.primary_size_for_orientation(m_orientation) - correction);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,11 @@ class Splitter : public Widget {
|
||||||
public:
|
public:
|
||||||
virtual ~Splitter() override;
|
virtual ~Splitter() override;
|
||||||
|
|
||||||
|
int first_resizee_minimum_size() { return m_first_resizee_minimum_size; }
|
||||||
|
void set_first_resizee_minimum_size(int minimum_size) { m_first_resizee_minimum_size = minimum_size; }
|
||||||
|
int second_resizee_minimum_size() { return m_second_resizee_minimum_size; }
|
||||||
|
void set_second_resizee_minimum_size(int minimum_size) { m_second_resizee_minimum_size = minimum_size; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit Splitter(Gfx::Orientation);
|
explicit Splitter(Gfx::Orientation);
|
||||||
|
|
||||||
|
@ -41,6 +46,8 @@ private:
|
||||||
WeakPtr<Widget> m_second_resizee;
|
WeakPtr<Widget> m_second_resizee;
|
||||||
Gfx::IntSize m_first_resizee_start_size;
|
Gfx::IntSize m_first_resizee_start_size;
|
||||||
Gfx::IntSize m_second_resizee_start_size;
|
Gfx::IntSize m_second_resizee_start_size;
|
||||||
|
int m_first_resizee_minimum_size { 0 };
|
||||||
|
int m_second_resizee_minimum_size { 0 };
|
||||||
Gfx::IntRect m_grabbable_rect;
|
Gfx::IntRect m_grabbable_rect;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue