diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2024-07-12 12:37:10 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2024-07-12 12:37:10 +0200 |
| commit | 87d659ca1a14fe8cf4871b8db0f42d005964f565 (patch) | |
| tree | 704e94d644d2f27d474fdc211894cf0ab88614e4 /app | |
| parent | 61ba5c151040533f23642c07fc2230a5718396ee (diff) | |
| download | turns-87d659ca1a14fe8cf4871b8db0f42d005964f565.tar.xz turns-87d659ca1a14fe8cf4871b8db0f42d005964f565.zip | |
app/windows: add basic main window
Diffstat (limited to 'app')
| -rw-r--r-- | app/CMakeLists.txt | 22 | ||||
| -rw-r--r-- | app/include/turns/app/windows/main.hpp | 23 | ||||
| -rw-r--r-- | app/src/application.cpp | 4 | ||||
| -rw-r--r-- | app/src/windows/main.cpp | 16 | ||||
| -rw-r--r-- | app/tests/windows/main.cpp | 34 |
5 files changed, 97 insertions, 2 deletions
diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 88dea68..824e107 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -2,6 +2,7 @@ add_library("app" "src/application.cpp" + "src/windows/main.cpp" ) add_library("turns::app" ALIAS "app") @@ -11,6 +12,9 @@ target_compile_options("app" PUBLIC "$<$<CXX_COMPILER_ID:GNU,Clang>:-Wextra>" "$<$<CXX_COMPILER_ID:GNU,Clang>:-Werror>" "$<$<CXX_COMPILER_ID:GNU,Clang>:-pedantic-errors>" + PRIVATE + "$<$<AND:$<CXX_COMPILER_ID:GNU,Clang>,$<CONFIG:Debug>>:-fprofile-arcs>" + "$<$<AND:$<CXX_COMPILER_ID:GNU,Clang>,$<CONFIG:Debug>>:-ftest-coverage>" ) target_include_directories("app" PUBLIC @@ -18,6 +22,8 @@ target_include_directories("app" PUBLIC ) target_link_libraries("app" PUBLIC + "$<$<AND:$<CXX_COMPILER_ID:GNU,Clang>,$<CONFIG:Debug>>:gcov>" + "PkgConfig::adwaita" "PkgConfig::gtkmm" @@ -51,4 +57,18 @@ configure_file("desktop.in" install(FILES "${CMAKE_CURRENT_BINARY_DIR}/turns.desktop" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications" -)
\ No newline at end of file +) + +# Tests + +add_executable("app-tests" + "tests/windows/main.cpp" +) + +target_link_libraries("app-tests" PRIVATE + "Catch2::Catch2" + "turns::app" + "turns::gtk-test-main" +) + +catch_discover_tests("app-tests")
\ No newline at end of file diff --git a/app/include/turns/app/windows/main.hpp b/app/include/turns/app/windows/main.hpp new file mode 100644 index 0000000..9d2e1c3 --- /dev/null +++ b/app/include/turns/app/windows/main.hpp @@ -0,0 +1,23 @@ +#ifndef TURNS_APP_WINDOWS_MAIN_WINDOW_HPP +#define TURNS_APP_WINDOWS_MAIN_WINDOW_HPP + +#include <adwaita.h> +#include <glibmm/refptr.h> +#include <gtkmm/applicationwindow.h> +#include <gtkmm/builder.h> + +namespace turns::app::windows +{ + + struct main : Gtk::ApplicationWindow + { + main(BaseObjectType * base, Glib::RefPtr<Gtk::Builder> const builder); + + private: + AdwApplicationWindow * m_adw; + AdwWindowTitle * m_title; + }; + +} // namespace turns::app + +#endif
\ No newline at end of file diff --git a/app/src/application.cpp b/app/src/application.cpp index 014171e..660782e 100644 --- a/app/src/application.cpp +++ b/app/src/application.cpp @@ -1,5 +1,7 @@ #include "turns/app/application.hpp" +#include "turns/app/windows/main.hpp" + #include <glibmm.h> #include <gtkmm/builder.h> #include <gtkmm/window.h> @@ -18,7 +20,7 @@ namespace turns::app : Gtk::Application{"ch.arknet.Turns"} { auto builder = Gtk::Builder::create_from_resource("/turns/windows/main_window.ui"); - auto main_window = builder->get_widget<Gtk::ApplicationWindow>("main_window"); + auto main_window = Gtk::Builder::get_widget_derived<windows::main>(builder, "main_window"); m_main_window = ADW_APPLICATION_WINDOW(main_window->gobj()); diff --git a/app/src/windows/main.cpp b/app/src/windows/main.cpp new file mode 100644 index 0000000..f8437a6 --- /dev/null +++ b/app/src/windows/main.cpp @@ -0,0 +1,16 @@ +#include "turns/app/windows/main.hpp" + +#include <adwaita.h> + +namespace turns::app::windows +{ + + main::main(BaseObjectType * base, Glib::RefPtr<Gtk::Builder> const builder) + : Gtk::ApplicationWindow{base} + , m_adw{ADW_APPLICATION_WINDOW(gobj())} + , m_title(ADW_WINDOW_TITLE(builder->get_widget<Gtk::Widget>("title")->gobj())) + { + adw_window_title_set_subtitle(m_title, "No active turn-order"); + } + +} // namespace turns::app::windows
\ No newline at end of file diff --git a/app/tests/windows/main.cpp b/app/tests/windows/main.cpp new file mode 100644 index 0000000..d2ad60e --- /dev/null +++ b/app/tests/windows/main.cpp @@ -0,0 +1,34 @@ +#include "turns/app/windows/main.hpp" + +#include <catch2/catch_test_macros.hpp> + +#include <string> + +#include <adwaita.h> +#include <gtkmm/builder.h> +#include <gtkmm/widget.h> + +using namespace std::string_literals; + +namespace turns::app::windows::tests +{ + + TEST_CASE("Newly constructed main window", "[windows]") + { + auto builder = Gtk::Builder::create_from_resource("/turns/windows/main_window.ui"); + auto instance = Gtk::Builder::get_widget_derived<main>(builder, "main_window"); + + SECTION("construction via builder succeeds") + { + REQUIRE(instance); + } + + SECTION("the window title is not empty") + { + auto widget = builder->get_widget<Gtk::Widget>("title"); + auto adw = ADW_WINDOW_TITLE(widget->gobj()); + REQUIRE(adw_window_title_get_subtitle(adw) != ""s); + } + } + +} // namespace turns::app::windows::tests
\ No newline at end of file |
