From bbfe5ab665242b5fab459687230245fadf9ca425 Mon Sep 17 00:00:00 2001 From: daiqingshuang Date: Thu, 10 Apr 2025 13:34:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E7=9A=84=E5=B8=83=E5=B1=80=E8=AF=AD?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmake/project_cpp_standard.cmake | 2 ++ example/src/main.cpp | 10 ++---- src/mirage_core/src/misc/key_type/key_type.h | 2 +- src/mirage_image/color.cpp | 4 +-- .../render/windows/windows_render_state.cpp | 5 ++- .../texture/windows/rw_texture2d_d3d11.cpp | 1 - .../src/widget/leaf_widget/mtext_block.h | 2 +- src/mirage_widget/src/widget/mleaf_widget.h | 2 +- src/mirage_widget/src/widget/slot_util.h | 2 +- src/mirage_widget/src/widget/widget_new.h | 35 +++---------------- src/mirage_widget/src/window/mwindow_impl.cpp | 3 +- 11 files changed, 19 insertions(+), 49 deletions(-) diff --git a/cmake/project_cpp_standard.cmake b/cmake/project_cpp_standard.cmake index 53bf74e..318f3ee 100644 --- a/cmake/project_cpp_standard.cmake +++ b/cmake/project_cpp_standard.cmake @@ -32,6 +32,8 @@ function(set_cpp_standard standard) # GCC/Clang 特定选项 if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra) + # 禁用未使用参数的警告 + add_compile_options(-Wno-unused-parameter) # 根据 C++ 标准添加特定选项 if(${standard} GREATER 14) # 更兼容的写法,避免使用 GREATER_EQUAL add_compile_options(-Wshadow -Wnon-virtual-dtor) diff --git a/example/src/main.cpp b/example/src/main.cpp index e687b5b..f552426 100644 --- a/example/src/main.cpp +++ b/example/src/main.cpp @@ -75,9 +75,7 @@ int main(int argc, char* argv[]) { mslot(mbutton) .margin({10}) .visibility(visibility_t::visible) - [ - text_block - ] + (text_block) ); // const auto button2 = mnew(mbutton) @@ -89,14 +87,12 @@ int main(int argc, char* argv[]) { const auto& window = mwindow::create({ 800, 600 }, L"Hello, World!"); window->set_content( - mborder() + mnew(mborder) [ mslot(mborder) .h_alignment(horizontal_alignment_t::center) .v_alignment(vertical_alignment_t::center) - [ - button - ] + (button) ] ); diff --git a/src/mirage_core/src/misc/key_type/key_type.h b/src/mirage_core/src/misc/key_type/key_type.h index a5d8fc1..2a81766 100644 --- a/src/mirage_core/src/misc/key_type/key_type.h +++ b/src/mirage_core/src/misc/key_type/key_type.h @@ -68,7 +68,7 @@ enum class key_code : uint16_t { p = 0x29, left_bracket = 0x2A, // [ right_bracket = 0x2B, // ] - backslash = 0x2C, // \ + backslash = 0x2C, // 左斜杠 caps_lock = 0x2D, a = 0x2E, diff --git a/src/mirage_image/color.cpp b/src/mirage_image/color.cpp index 1198af0..dd1b11e 100644 --- a/src/mirage_image/color.cpp +++ b/src/mirage_image/color.cpp @@ -137,14 +137,14 @@ std::optional parse_rgb_rgba_color(const std::string& in_str) { // **按逗号分割** const auto& components_str = split_string(content, ','); - const size_t expected_components = is_rgba ? 4 : 3; + const auto expected_components = is_rgba ? 4uz : 3uz; if (components_str.size() != expected_components) { return std::nullopt; // 组件数量不正确 } std::array components; - int32_t index = 0; + auto index = 0uz; bool uses_float = false; bool uses_int = false; diff --git a/src/mirage_render/src/render/windows/windows_render_state.cpp b/src/mirage_render/src/render/windows/windows_render_state.cpp index b16b923..7011999 100644 --- a/src/mirage_render/src/render/windows/windows_render_state.cpp +++ b/src/mirage_render/src/render/windows/windows_render_state.cpp @@ -48,6 +48,7 @@ bool windows_render_state::init(ID3D11Device* in_device, IDXGIFactory* in_factor .Denominator = 1 }, .Format = format, + .ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED, }, .SampleDesc = { .Count = 1, @@ -181,13 +182,11 @@ void windows_render_state::rebuild_swapchain(const Eigen::Vector2i& size) { context->Flush(); // 2. 释放当前渲染目标视图 - DXGI_FORMAT format = DXGI_FORMAT_B8G8R8A8_UNORM; // 默认格式 auto dx_render_target_view = get_dx_render_target_view(); if (dx_render_target_view) { - // 保存格式以便稍后使用 + // 保存格式以便稍后使用 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc = {}; dx_render_target_view->GetDesc(&rtv_desc); - format = rtv_desc.Format; // 释放资源 dx_render_target_view->Release(); diff --git a/src/mirage_render/src/texture/windows/rw_texture2d_d3d11.cpp b/src/mirage_render/src/texture/windows/rw_texture2d_d3d11.cpp index 3f62d98..9ddab46 100644 --- a/src/mirage_render/src/texture/windows/rw_texture2d_d3d11.cpp +++ b/src/mirage_render/src/texture/windows/rw_texture2d_d3d11.cpp @@ -48,7 +48,6 @@ void rw_texture2d::create(const texture_data& in_data) { desc.sample_count = 1; auto d3d_device = (ID3D11Device*)sg_d3d11_device(); - auto d3d_context = (ID3D11DeviceContext*)sg_d3d11_device_context(); // 创建纹理 ID3D11Texture2D* tex2d = nullptr; diff --git a/src/mirage_widget/src/widget/leaf_widget/mtext_block.h b/src/mirage_widget/src/widget/leaf_widget/mtext_block.h index b4a258b..f702941 100644 --- a/src/mirage_widget/src/widget/leaf_widget/mtext_block.h +++ b/src/mirage_widget/src/widget/leaf_widget/mtext_block.h @@ -39,7 +39,7 @@ public: auto get_line_spacing() const { return line_spacing_; } auto get_max_width() const { return max_width_; } - hit_test_handle on_mouse_move(const Eigen::Vector2f& in_position) override { return hit_test_handle::handled(); } + hit_test_handle on_mouse_move(const Eigen::Vector2f& in_position) override { (void)in_position; return hit_test_handle::handled(); } auto compute_desired_size(float in_layout_scale_multiplier) const -> Eigen::Vector2f override; hit_test_handle on_mouse_wheel(const Eigen::Vector2f& in_position, const wheel_event& in_delta) override; private: diff --git a/src/mirage_widget/src/widget/mleaf_widget.h b/src/mirage_widget/src/widget/mleaf_widget.h index e40121c..aa6d00d 100644 --- a/src/mirage_widget/src/widget/mleaf_widget.h +++ b/src/mirage_widget/src/widget/mleaf_widget.h @@ -7,5 +7,5 @@ */ class mleaf_widget : public mwidget { public: - void arrange_children(const geometry_t& in_allotted_geometry) override {} + void arrange_children(const geometry_t& in_allotted_geometry) override { (void)in_allotted_geometry; } }; diff --git a/src/mirage_widget/src/widget/slot_util.h b/src/mirage_widget/src/widget/slot_util.h index 07b419f..44ff396 100644 --- a/src/mirage_widget/src/widget/slot_util.h +++ b/src/mirage_widget/src/widget/slot_util.h @@ -31,7 +31,7 @@ return me(); \ } \ const auto& get() const { return widget_; } \ - auto& operator[](const std::shared_ptr& in_widget) { \ + auto& operator()(const std::shared_ptr& in_widget) { \ set(in_widget); \ return me(); \ } \ diff --git a/src/mirage_widget/src/widget/widget_new.h b/src/mirage_widget/src/widget/widget_new.h index d15e682..3f5b36b 100644 --- a/src/mirage_widget/src/widget/widget_new.h +++ b/src/mirage_widget/src/widget/widget_new.h @@ -6,29 +6,6 @@ #include "widget_new.h" #include "compound_widget/mbutton.h" -// 前向声明 -template -struct mwidget_decl; - -template -concept has_add_slot = requires(T& t) { - { t.add_slot() }; -}; - -template -concept has_set_content = requires(T& t, std::shared_ptr in_widget) { - t.set_content(in_widget); -}; - -template -struct mwidget_slot_guard { - auto& operator+(const typename WidgetType::slot_type& in_slot) { - slots_.push_back(in_slot); - return *this; - } - std::vector slots_; -}; - template struct mwidget_decl { mwidget_decl() { @@ -44,16 +21,14 @@ struct mwidget_decl { mwidget_decl(const mwidget_decl&) = delete; mwidget_decl& operator=(const mwidget_decl&) = delete; - std::shared_ptr operator<<=(const mwidget_slot_guard& in_guard) { - for (const auto& slot: in_guard.slots_) { - widget_->push_slot(slot); - } - return widget_; - } + template + auto operator[](Args&&... in_args) { + return (*widget_)[std::forward(in_args)...]; + } operator std::shared_ptr() const { return widget_; } std::shared_ptr widget_; }; #define mslot(type) type::slot_type() -#define mnew(type, ...) mwidget_decl(__VA_ARGS__) <<= mwidget_slot_guard() +#define mnew(type, ...) mwidget_decl(__VA_ARGS__) diff --git a/src/mirage_widget/src/window/mwindow_impl.cpp b/src/mirage_widget/src/window/mwindow_impl.cpp index 3d01709..980b542 100644 --- a/src/mirage_widget/src/window/mwindow_impl.cpp +++ b/src/mirage_widget/src/window/mwindow_impl.cpp @@ -288,7 +288,7 @@ public: mouse_.position = window_pos; // 执行命中测试,查找鼠标位置下的控件 - const auto& result = perform_hit_test(window_pos, [this](mwidget* widget, const Eigen::Vector2f& local_pos) { + const auto& result = perform_hit_test(window_pos, [](mwidget* widget, const Eigen::Vector2f& local_pos) { return widget->on_mouse_move(local_pos); }); @@ -330,7 +330,6 @@ public: return widget->on_mouse_button_up(local_pos, button); }); - const auto& hit_widget = hit_result.widget; const auto& widget_local_pos = hit_result.widget_space_pos; // 获取之前点击的控件