2020-12-30 03:52:27 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
2022-02-26 10:50:04 -07:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-12-30 03:52:27 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-12-30 03:52:27 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibGUI/Painter.h>
|
|
|
|
|
#include <LibGUI/SeparatorWidget.h>
|
|
|
|
|
#include <LibGfx/Palette.h>
|
|
|
|
|
|
2021-03-08 11:38:43 -05:00
|
|
|
REGISTER_WIDGET(GUI, HorizontalSeparator)
|
|
|
|
|
REGISTER_WIDGET(GUI, VerticalSeparator)
|
|
|
|
|
|
2023-02-28 19:24:56 +00:00
|
|
|
constexpr int minimum_size = 8;
|
|
|
|
|
|
2020-12-30 03:52:27 +01:00
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
|
|
SeparatorWidget::SeparatorWidget(Gfx::Orientation orientation)
|
|
|
|
|
: m_orientation(orientation)
|
|
|
|
|
{
|
2023-02-10 01:07:03 +01:00
|
|
|
set_preferred_size(SpecialDimension::Fit);
|
2020-12-30 03:52:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SeparatorWidget::paint_event(PaintEvent& event)
|
|
|
|
|
{
|
|
|
|
|
Painter painter(*this);
|
|
|
|
|
painter.add_clip_rect(event.rect());
|
|
|
|
|
|
|
|
|
|
if (m_orientation == Gfx::Orientation::Vertical) {
|
|
|
|
|
painter.translate(rect().center().x() - 1, 0);
|
2023-05-22 00:41:18 +02:00
|
|
|
painter.draw_line({ 0, 0 }, { 0, rect().bottom() - 1 }, palette().threed_shadow1());
|
|
|
|
|
painter.draw_line({ 1, 0 }, { 1, rect().bottom() - 1 }, palette().threed_highlight());
|
2020-12-30 03:52:27 +01:00
|
|
|
} else {
|
|
|
|
|
painter.translate(0, rect().center().y() - 1);
|
2023-05-22 00:41:18 +02:00
|
|
|
painter.draw_line({ 0, 0 }, { rect().right() - 1, 0 }, palette().threed_shadow1());
|
|
|
|
|
painter.draw_line({ 0, 1 }, { rect().right() - 1, 1 }, palette().threed_highlight());
|
2020-12-30 03:52:27 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-10 01:07:03 +01:00
|
|
|
Optional<UISize> SeparatorWidget::calculated_preferred_size() const
|
|
|
|
|
{
|
|
|
|
|
if (m_orientation == Gfx::Orientation::Vertical)
|
2023-02-28 19:24:56 +00:00
|
|
|
return UISize { minimum_size, SpecialDimension::OpportunisticGrow };
|
|
|
|
|
return UISize { SpecialDimension::OpportunisticGrow, minimum_size };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Optional<UISize> SeparatorWidget::calculated_min_size() const
|
|
|
|
|
{
|
|
|
|
|
if (m_orientation == Gfx::Orientation::Vertical)
|
|
|
|
|
return UISize { minimum_size, 0 };
|
|
|
|
|
return UISize { 0, minimum_size };
|
2023-02-10 01:07:03 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-30 03:52:27 +01:00
|
|
|
}
|