/* * Copyright (c) 2024, Sanil Gupta . * * SPDX-License-Identifier: BSD-2-Clause */ #include "ViewEventWidget.h" #include #include namespace Calendar { ErrorOr> ViewEventWidget::create(ViewEventDialog* parent_window, Vector& events) { auto widget = TRY(try_create()); auto* events_list = widget->find_descendant_of_type_named("events_list"); for (auto const& event : events) { String text = MUST(String::formatted("{} {}", event.start.to_byte_string("%H:%M"sv), event.summary)); auto label = GUI::Label::construct(text); label->set_fill_with_background_color(true); label->set_text_alignment(Gfx::TextAlignment::CenterLeft); label->set_text_wrapping(Gfx::TextWrapping::DontWrap); events_list->add_child(label); } auto* add_new_event_button = widget->find_descendant_of_type_named("add_event_button"); add_new_event_button->on_click = [window = parent_window](auto) { window->close_and_open_add_event_dialog(); }; return widget; } }