LevelSelectDialog.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2020-2022, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "LevelSelectDialog.h"
  7. #include <LibGUI/BoxLayout.h>
  8. #include <LibGUI/Button.h>
  9. #include <LibGUI/Label.h>
  10. #include <LibGUI/ListView.h>
  11. namespace Breakout {
  12. LevelSelectDialog::LevelSelectDialog(Window* parent_window)
  13. : Dialog(parent_window)
  14. {
  15. set_rect(0, 0, 300, 250);
  16. set_title("Level Select");
  17. build();
  18. }
  19. GUI::Dialog::ExecResult LevelSelectDialog::show(int& board_number, Window* parent_window)
  20. {
  21. auto box = LevelSelectDialog::construct(parent_window);
  22. box->set_resizable(false);
  23. if (parent_window)
  24. box->set_icon(parent_window->icon());
  25. auto result = box->exec();
  26. board_number = box->level();
  27. return result;
  28. }
  29. void LevelSelectDialog::build()
  30. {
  31. auto& main_widget = set_main_widget<GUI::Widget>();
  32. main_widget.set_fill_with_background_color(true);
  33. auto& layout = main_widget.set_layout<GUI::VerticalBoxLayout>();
  34. layout.set_margins(4);
  35. main_widget.add<GUI::Label>("Choose a level").set_text_alignment(Gfx::TextAlignment::Center);
  36. auto& level_list = main_widget.add<GUI::Widget>();
  37. auto& scroll_layout = level_list.set_layout<GUI::VerticalBoxLayout>();
  38. scroll_layout.set_spacing(4);
  39. level_list.add<GUI::Button>("Rainbow").on_click = [this](auto) {
  40. m_level = -1;
  41. done(ExecResult::OK);
  42. };
  43. level_list.add<GUI::Button>(":^)").on_click = [this](auto) {
  44. m_level = 0;
  45. done(ExecResult::OK);
  46. };
  47. }
  48. }