diff options
-rw-r--r-- | .editorconfig | 4 | ||||
-rw-r--r-- | CMakeLists.txt | 7 | ||||
-rw-r--r-- | include/cru/common/base.hpp | 2 | ||||
-rw-r--r-- | src/CMakeLists.txt | 8 | ||||
-rw-r--r-- | src/ui/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/ui/content_control.cpp | 5 | ||||
-rw-r--r-- | src/ui/control.cpp | 9 | ||||
-rw-r--r-- | src/ui/controls/button.cpp | 6 | ||||
-rw-r--r-- | src/ui/controls/flex_layout.cpp | 2 | ||||
-rw-r--r-- | src/ui/layout_control.cpp | 10 | ||||
-rw-r--r-- | src/ui/render/flex_layout_render_object.cpp | 4 | ||||
-rw-r--r-- | src/ui/render/render_object.cpp | 11 | ||||
-rw-r--r-- | src/ui/render/text_render_object.cpp | 6 | ||||
-rw-r--r-- | src/ui/render/window_render_object.cpp | 6 | ||||
-rw-r--r-- | src/ui/window.cpp | 2 | ||||
-rw-r--r-- | src/win/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/win/debug_logger.hpp | 2 | ||||
-rw-r--r-- | src/win/graph/direct/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/win/native/god_window.cpp | 3 | ||||
-rw-r--r-- | src/win/native/window.cpp | 11 |
20 files changed, 83 insertions, 23 deletions
diff --git a/.editorconfig b/.editorconfig index a957f24a..10f91e46 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,3 +11,7 @@ indent_size = 2 [*.hpp] indent_style = space indent_size = 2 + +[CMakeLists.txt] +indent_style = tab +indent_size = 4 diff --git a/CMakeLists.txt b/CMakeLists.txt index 9403b9fe..7c8da389 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,12 @@ cmake_minimum_required(VERSION 3.14) project(CruUI) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) + +if (MSVC) + string(REGEX REPLACE "/W[0-4]\\s*" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) + add_compile_options(/utf-8 /W4 /WX) +endif() set(CRU_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include) diff --git a/include/cru/common/base.hpp b/include/cru/common/base.hpp index 2c935046..4264142d 100644 --- a/include/cru/common/base.hpp +++ b/include/cru/common/base.hpp @@ -3,6 +3,8 @@ #include <stdexcept> +#define CRU_UNUSED(entity) static_cast<void>(entity); + #define CRU_DEFAULT_COPY(classname) \ classname(const classname&) = default; \ classname& operator=(const classname&) = default; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d486336b..e2eb921c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,10 +3,14 @@ add_subdirectory(common) add_subdirectory(platform) if(WIN32) - add_subdirectory(win) + add_subdirectory(win) endif() add_subdirectory(ui) add_executable(demo main.cpp) -target_link_libraries(demo PRIVATE cru_ui cru_win_native) +target_link_libraries(demo PRIVATE cru_ui) + +if(WIN32) + target_link_libraries(demo PRIVATE cru_win_native) +endif() diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 51d36e0d..111e3e33 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -42,8 +42,4 @@ target_sources(cru_ui PUBLIC ${CRU_UI_INCLUDE_DIR}/render/text_render_object.hpp ${CRU_UI_INCLUDE_DIR}/render/window_render_object.hpp ) -target_link_libraries(cru_ui PUBLIC cru_base) - -if(WIN32) target_link_libraries(cru_ui PUBLIC cru_platform_native) -endif() diff --git a/src/ui/content_control.cpp b/src/ui/content_control.cpp index 6383a10e..5bc8eda4 100644 --- a/src/ui/content_control.cpp +++ b/src/ui/content_control.cpp @@ -28,5 +28,8 @@ void ContentControl::SetChild(Control* child) { OnChildChanged(old_child, child); } -void ContentControl::OnChildChanged(Control* old_child, Control* new_child) {} +void ContentControl::OnChildChanged(Control* old_child, Control* new_child) { + CRU_UNUSED(old_child) + CRU_UNUSED(new_child) +} } // namespace cru::ui diff --git a/src/ui/control.cpp b/src/ui/control.cpp index 5f760939..cde602b7 100644 --- a/src/ui/control.cpp +++ b/src/ui/control.cpp @@ -105,9 +105,12 @@ void Control::SetCursor(std::shared_ptr<ICursor> cursor) { } } -void Control::OnParentChanged(Control* old_parent, Control* new_parent) {} +void Control::OnParentChanged(Control* old_parent, Control* new_parent) { + CRU_UNUSED(old_parent) + CRU_UNUSED(new_parent) +} -void Control::OnAttachToWindow(Window* window) {} +void Control::OnAttachToWindow(Window* window) { CRU_UNUSED(window) } -void Control::OnDetachToWindow(Window* window) {} +void Control::OnDetachToWindow(Window* window) { CRU_UNUSED(window) } } // namespace cru::ui diff --git a/src/ui/controls/button.cpp b/src/ui/controls/button.cpp index b7f972be..75651a1d 100644 --- a/src/ui/controls/button.cpp +++ b/src/ui/controls/button.cpp @@ -36,6 +36,8 @@ Button::Button() : click_detector_(this) { render_object_->SetBorderEnabled(true); MouseEnterEvent()->Direct()->AddHandler([this](event::MouseEventArgs& args) { + CRU_UNUSED(args) + if (click_detector_.GetPressingButton() & trigger_button_) { SetState(ButtonState::Press); } else { @@ -44,6 +46,8 @@ Button::Button() : click_detector_(this) { }); MouseLeaveEvent()->Direct()->AddHandler([this](event::MouseEventArgs& args) { + CRU_UNUSED(args) + if (click_detector_.GetPressingButton() & trigger_button_) { SetState(ButtonState::Normal); } else { @@ -75,6 +79,8 @@ void Button::OnChildChanged(Control* old_child, Control* new_child) { } void Button::OnStateChange(ButtonState oldState, ButtonState newState) { + CRU_UNUSED(oldState) + switch (newState) { case ButtonState::Normal: Set(render_object_.get(), style_.normal); diff --git a/src/ui/controls/flex_layout.cpp b/src/ui/controls/flex_layout.cpp index cf6d4aad..6491b180 100644 --- a/src/ui/controls/flex_layout.cpp +++ b/src/ui/controls/flex_layout.cpp @@ -44,6 +44,8 @@ void FlexLayout::OnAddChild(Control* child, int position) { } void FlexLayout::OnRemoveChild(Control* child, int position) { + CRU_UNUSED(child) + render_object_->RemoveChild(position); } } // namespace cru::ui::controls diff --git a/src/ui/layout_control.cpp b/src/ui/layout_control.cpp index 00215a8e..cd9587c7 100644 --- a/src/ui/layout_control.cpp +++ b/src/ui/layout_control.cpp @@ -38,7 +38,13 @@ void LayoutControl::RemoveChild(const int position) { OnRemoveChild(child, position); } -void LayoutControl::OnAddChild(Control* child, int position) {} +void LayoutControl::OnAddChild(Control* child, int position) { + CRU_UNUSED(child) + CRU_UNUSED(position) +} -void LayoutControl::OnRemoveChild(Control* child, int position) {} +void LayoutControl::OnRemoveChild(Control* child, int position) { + CRU_UNUSED(child) + CRU_UNUSED(position) +} } // namespace cru::ui diff --git a/src/ui/render/flex_layout_render_object.cpp b/src/ui/render/flex_layout_render_object.cpp index 3370ffc1..a5fde12a 100644 --- a/src/ui/render/flex_layout_render_object.cpp +++ b/src/ui/render/flex_layout_render_object.cpp @@ -42,11 +42,15 @@ RenderObject* FlexLayoutRenderObject::HitTest(const Point& point) { } // namespace cru::ui::render void FlexLayoutRenderObject::OnAddChild(RenderObject* new_child, int position) { + CRU_UNUSED(new_child) + child_layout_data_.emplace(child_layout_data_.cbegin() + position); } void FlexLayoutRenderObject::OnRemoveChild(RenderObject* removed_child, int position) { + CRU_UNUSED(removed_child) + child_layout_data_.erase(child_layout_data_.cbegin() + position); } diff --git a/src/ui/render/render_object.cpp b/src/ui/render/render_object.cpp index 8e65dad0..b6a9e8e4 100644 --- a/src/ui/render/render_object.cpp +++ b/src/ui/render/render_object.cpp @@ -42,14 +42,23 @@ void RenderObject::Layout(const Rect& rect) { } void RenderObject::OnParentChanged(RenderObject* old_parent, - RenderObject* new_parent) {} + RenderObject* new_parent) { + CRU_UNUSED(old_parent) + CRU_UNUSED(new_parent) +} void RenderObject::OnAddChild(RenderObject* new_child, int position) { + CRU_UNUSED(new_child) + CRU_UNUSED(position) + InvalidateLayout(); InvalidatePaint(); } void RenderObject::OnRemoveChild(RenderObject* removed_child, int position) { + CRU_UNUSED(removed_child) + CRU_UNUSED(position) + InvalidateLayout(); InvalidatePaint(); } diff --git a/src/ui/render/text_render_object.cpp b/src/ui/render/text_render_object.cpp index 9afb9f6e..260c6688 100644 --- a/src/ui/render/text_render_object.cpp +++ b/src/ui/render/text_render_object.cpp @@ -8,7 +8,7 @@ #include <algorithm> #include <cassert> -//TODO: Null Check!!! +// TODO: Null Check!!! namespace cru::ui::render { TextRenderObject::TextRenderObject( @@ -78,7 +78,9 @@ Size TextRenderObject::OnMeasureContent(const Size& available_size) { return text_layout_->GetTextBounds().GetSize(); } -void TextRenderObject::OnLayoutContent(const Rect& content_rect) {} +void TextRenderObject::OnLayoutContent(const Rect& content_rect) { + CRU_UNUSED(content_rect) +} void TextRenderObject::OnAfterLayout() { const auto&& size = GetContentRect().GetSize(); diff --git a/src/ui/render/window_render_object.cpp b/src/ui/render/window_render_object.cpp index 8e48b7c9..12fc2ce1 100644 --- a/src/ui/render/window_render_object.cpp +++ b/src/ui/render/window_render_object.cpp @@ -92,16 +92,20 @@ namespace { void SetRenderHostRecursive(RenderObject* render_object, IRenderHost* host) { render_object->SetRenderHost(host); for (const auto child : render_object->GetChildren()) { - SetRenderHostRecursive(render_object, host); + SetRenderHostRecursive(child, host); } } } // namespace void WindowRenderObject::OnAddChild(RenderObject* new_child, int position) { + CRU_UNUSED(position) + SetRenderHostRecursive(new_child, render_host_.get()); } void WindowRenderObject::OnRemoveChild(RenderObject* new_child, int position) { + CRU_UNUSED(position) + SetRenderHostRecursive(new_child, nullptr); } diff --git a/src/ui/window.cpp b/src/ui/window.cpp index 73cbc60b..6ff44b4b 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -203,6 +203,8 @@ void Window::OnNativePaint(std::nullptr_t) { } void Window::OnNativeResize(const Size& size) { + CRU_UNUSED(size) + render_object_->GetRenderHost()->InvalidateLayout(); } diff --git a/src/win/CMakeLists.txt b/src/win/CMakeLists.txt index 5727e4c0..696ef200 100644 --- a/src/win/CMakeLists.txt +++ b/src/win/CMakeLists.txt @@ -13,7 +13,6 @@ target_sources(cru_win_base PUBLIC ${CRU_WIN_BASE_INCLUDE_DIR}/win_pre_config.hpp ) target_compile_definitions(cru_win_base PUBLIC UNICODE _UNICODE) # use unicode -target_include_directories(cru_win_base PUBLIC .) target_link_libraries(cru_win_base PUBLIC cru_base) add_subdirectory(graph) diff --git a/src/win/debug_logger.hpp b/src/win/debug_logger.hpp index c5321828..b6694279 100644 --- a/src/win/debug_logger.hpp +++ b/src/win/debug_logger.hpp @@ -15,6 +15,8 @@ class WinDebugLoggerSource : public ::cru::log::ILogSource { ~WinDebugLoggerSource() = default; void Write(::cru::log::LogLevel level, const std::string_view& s) override { + CRU_UNUSED(level) + const std::wstring&& ws = ToUtf16String(s); ::OutputDebugStringW(ws.data()); } diff --git a/src/win/graph/direct/CMakeLists.txt b/src/win/graph/direct/CMakeLists.txt index b277fa32..492f6749 100644 --- a/src/win/graph/direct/CMakeLists.txt +++ b/src/win/graph/direct/CMakeLists.txt @@ -21,4 +21,5 @@ target_sources(cru_win_graph_direct PUBLIC ${CRU_WIN_GRAPH_DIRECT_INCLUDE_DIR}/resource.hpp ${CRU_WIN_GRAPH_DIRECT_INCLUDE_DIR}/text_layout.hpp ) -target_link_libraries(cru_win_graph_direct PUBLIC D3D11 D2d1 DWrite cru_win_base cru_platform_graph) +target_link_libraries(cru_win_graph_direct PUBLIC D3D11 D2d1 DWrite) +target_link_libraries(cru_win_graph_direct PUBLIC cru_win_base cru_platform_graph) diff --git a/src/win/native/god_window.cpp b/src/win/native/god_window.cpp index be54f698..00577002 100644 --- a/src/win/native/god_window.cpp +++ b/src/win/native/god_window.cpp @@ -51,6 +51,9 @@ GodWindow::~GodWindow() { bool GodWindow::HandleGodWindowMessage(HWND hwnd, UINT msg, WPARAM w_param, LPARAM l_param, LRESULT* result) { + CRU_UNUSED(hwnd) + CRU_UNUSED(l_param) + switch (msg) { case invoke_later_message_id: { const auto p_action = reinterpret_cast<std::function<void()>*>(w_param); diff --git a/src/win/native/window.cpp b/src/win/native/window.cpp index 6fd94838..f996af02 100644 --- a/src/win/native/window.cpp +++ b/src/win/native/window.cpp @@ -33,8 +33,8 @@ WinNativeWindow::WinNativeWindow(WinUiApplication* application, const auto window_manager = application->GetWindowManager(); hwnd_ = CreateWindowExW( - 0, window_manager->GetGeneralWindowClass()->GetName(), L"", window_style, - CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, + 0, window_class->GetName(), L"", window_style, CW_USEDEFAULT, + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, parent == nullptr ? nullptr : parent->GetWindowHandle(), nullptr, application->GetInstanceHandle(), nullptr); @@ -419,7 +419,10 @@ void WinNativeWindow::OnMouseUpInternal(platform::native::MouseButton button, mouse_up_event_.Raise({button, dip_point}); } -void WinNativeWindow::OnMouseWheelInternal(short delta, POINT point) {} +void WinNativeWindow::OnMouseWheelInternal(short delta, POINT point) { + CRU_UNUSED(delta) + CRU_UNUSED(point) +} void WinNativeWindow::OnKeyDownInternal(int virtual_code) { key_down_event_.Raise(virtual_code); @@ -429,7 +432,7 @@ void WinNativeWindow::OnKeyUpInternal(int virtual_code) { key_up_event_.Raise(virtual_code); } -void WinNativeWindow::OnCharInternal(wchar_t c) {} +void WinNativeWindow::OnCharInternal(wchar_t c) { CRU_UNUSED(c) } void WinNativeWindow::OnActivatedInternal() {} |