LibGUI: Make the calendar widget scrollable
This commit is contained in:
parent
28b5438395
commit
e504b63406
Notes:
sideshowbarker
2024-07-17 08:38:37 +09:00
Author: https://github.com/implicitfield Commit: https://github.com/SerenityOS/serenity/commit/e504b63406 Pull-request: https://github.com/SerenityOS/serenity/pull/19513 Reviewed-by: https://github.com/alimpfard
3 changed files with 20 additions and 1 deletions
|
@ -39,6 +39,7 @@ Calendar::Calendar(Core::DateTime date_time, Mode mode)
|
|||
m_weekend_length = weekend_length;
|
||||
|
||||
set_fill_with_background_color(true);
|
||||
set_scrollbars_enabled(false);
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
Day day;
|
||||
|
@ -777,6 +778,17 @@ void Calendar::mousedown_event(GUI::MouseEvent& event)
|
|||
}
|
||||
}
|
||||
|
||||
void Calendar::mousewheel_event(GUI::MouseEvent& event)
|
||||
{
|
||||
if (event.wheel_delta_y() > 0)
|
||||
show_next_date();
|
||||
else
|
||||
show_previous_date();
|
||||
|
||||
if (on_scroll)
|
||||
on_scroll();
|
||||
}
|
||||
|
||||
void Calendar::doubleclick_event(GUI::MouseEvent& event)
|
||||
{
|
||||
int months;
|
||||
|
|
|
@ -11,13 +11,14 @@
|
|||
#include <AK/DeprecatedString.h>
|
||||
#include <LibConfig/Listener.h>
|
||||
#include <LibCore/DateTime.h>
|
||||
#include <LibGUI/AbstractScrollableWidget.h>
|
||||
#include <LibGUI/Frame.h>
|
||||
#include <LibGUI/Widget.h>
|
||||
|
||||
namespace GUI {
|
||||
|
||||
class Calendar final
|
||||
: public GUI::Frame
|
||||
: public GUI::AbstractScrollableWidget
|
||||
, public Config::Listener {
|
||||
C_OBJECT(Calendar)
|
||||
|
||||
|
@ -77,6 +78,7 @@ public:
|
|||
virtual void config_string_did_change(StringView, StringView, StringView, StringView) override;
|
||||
virtual void config_i32_did_change(StringView, StringView, StringView, i32 value) override;
|
||||
|
||||
Function<void()> on_scroll;
|
||||
Function<void()> on_tile_click;
|
||||
Function<void()> on_tile_doubleclick;
|
||||
Function<void()> on_month_click;
|
||||
|
@ -92,6 +94,7 @@ private:
|
|||
virtual void mousemove_event(GUI::MouseEvent&) override;
|
||||
virtual void mousedown_event(MouseEvent&) override;
|
||||
virtual void mouseup_event(MouseEvent&) override;
|
||||
virtual void mousewheel_event(MouseEvent&) override;
|
||||
virtual void doubleclick_event(MouseEvent&) override;
|
||||
virtual void leave_event(Core::Event&) override;
|
||||
|
||||
|
|
|
@ -83,6 +83,10 @@ ClockWidget::ClockWidget()
|
|||
m_calendar = calendar_container.add<GUI::Calendar>();
|
||||
m_selected_calendar_button->set_text(m_calendar->formatted_date().release_value_but_fixme_should_propagate_errors());
|
||||
|
||||
m_calendar->on_scroll = [&] {
|
||||
update_selected_calendar_button();
|
||||
};
|
||||
|
||||
m_calendar->on_tile_click = [&] {
|
||||
m_selected_calendar_button->set_text(m_calendar->formatted_date().release_value_but_fixme_should_propagate_errors());
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue