diff options
author | Olivier De Cannière <olivier.decanniere96@gmail.com> | 2022-07-15 23:30:00 +0200 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2022-09-20 13:12:00 -0400 |
commit | 9414525d7552434d2099aaeb17b861ba57e55d54 (patch) | |
tree | 0bd43c5066756f189a9e3d4e4968df1b9426b29c /Userland | |
parent | aa4dd6c1bc4dc28cf096aff76b3487501fe7af1f (diff) | |
download | serenity-9414525d7552434d2099aaeb17b861ba57e55d54.zip |
Calendar: Support preferred first day of the week
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibGUI/Calendar.cpp | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/Calendar.h | 11 |
2 files changed, 14 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGUI/Calendar.cpp b/Userland/Libraries/LibGUI/Calendar.cpp index a1f35e5ee9..1ce01c89be 100644 --- a/Userland/Libraries/LibGUI/Calendar.cpp +++ b/Userland/Libraries/LibGUI/Calendar.cpp @@ -271,7 +271,7 @@ void Calendar::update_tiles(unsigned view_year, unsigned view_month) view_month = i + 1; auto first_day_of_current_month = Core::DateTime::create(view_year, view_month, 1); - unsigned start_of_month = first_day_of_current_month.weekday(); + unsigned start_of_month = (first_day_of_current_month.weekday() - to_underlying(m_first_day_of_week) + 7) % 7; unsigned days_from_previous_month_to_show = start_of_month == 0 ? 7 : start_of_month; for (unsigned j = 0; j < 42; j++) { @@ -425,7 +425,8 @@ void Calendar::paint_event(GUI::PaintEvent& event) y_offset, m_days[i].width, 16); - painter.draw_text(day_rect, m_days[i].name, small_font->bold_variant(), Gfx::TextAlignment::Center, palette().base_text()); + auto const& day_name = m_days[(i + to_underlying(m_first_day_of_week)) % 7].name; + painter.draw_text(day_rect, day_name, small_font->bold_variant(), Gfx::TextAlignment::Center, palette().base_text()); } y_offset += days_of_the_week_rect.height(); painter.draw_line({ 0, y_offset }, { frame_inner_rect().width(), y_offset }, palette().threed_shadow2(), 1); diff --git a/Userland/Libraries/LibGUI/Calendar.h b/Userland/Libraries/LibGUI/Calendar.h index 4a0b4f77a5..9ca630cf44 100644 --- a/Userland/Libraries/LibGUI/Calendar.h +++ b/Userland/Libraries/LibGUI/Calendar.h @@ -128,6 +128,17 @@ private: Gfx::IntSize m_event_size; Gfx::IntSize m_month_size[12]; Mode m_mode { Month }; + + enum class DayOfWeek { + Sunday, + Monday, + Tuesday, + Wednesday, + Thursday, + Friday, + Saturday + }; + DayOfWeek m_first_day_of_week { DayOfWeek::Sunday }; }; } |