From 607d0a43a1cdff844923dfa071e56e9897843c81 Mon Sep 17 00:00:00 2001 From: daiqingshuang Date: Wed, 7 May 2025 17:23:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=20C++=20=E6=A0=87=E5=87=86=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=88=B0=2026=20=E5=B9=B6=E6=94=B9=E8=BF=9B=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在构建配置中将 C++ 标准提高到 26,并在应用程序关闭之前添加资源清理消息。为了 UI 代码的一致性,对格式进行了细微的调整。 --- CMakeLists.txt | 2 +- cmake/project_cpp_standard.cmake | 2 +- example/src/main.cpp | 88 ++++++++++++++++---------------- src/mirage_app/mirage.cpp | 3 ++ 4 files changed, 49 insertions(+), 46 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b1d8f3b..b26c3ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.21) project(mirage) include(cmake/project_cpp_standard.cmake) -set_cpp_standard(23) +set_cpp_standard(26) set(MIRAGE_USE_HDR OFF CACHE BOOL "Enable HDR format") set(MIRAGE_HDR_FORMAT "SG_PIXELFORMAT_RGBA16F" CACHE STRING "Enable HDR format") diff --git a/cmake/project_cpp_standard.cmake b/cmake/project_cpp_standard.cmake index b2b637c..c3a8348 100644 --- a/cmake/project_cpp_standard.cmake +++ b/cmake/project_cpp_standard.cmake @@ -2,7 +2,7 @@ # 参数 standard: 需要设置的 C++ 标准版本 (例如 11, 14, 17, 20, 23) function(set_cpp_standard standard) # --- 参数验证 --- - set(VALID_STANDARDS 11 14 17 20 23) # 定义支持的 C++ 标准列表 + set(VALID_STANDARDS 11 14 17 20 23 26) # 定义支持的 C++ 标准列表 list(FIND VALID_STANDARDS ${standard} _standard_index) # 查找 standard 是否在列表中 if(_standard_index EQUAL -1) # 如果未找到 message(WARNING "**非标准 C++ 版本**: ${standard}。支持的版本有: ${VALID_STANDARDS}") diff --git a/example/src/main.cpp b/example/src/main.cpp index df704d5..1df662b 100644 --- a/example/src/main.cpp +++ b/example/src/main.cpp @@ -47,11 +47,11 @@ int main(int argc, char* argv[]) { font_manager::instance().load_default_font(); - auto name = mirage_style::get().name(); - auto version = mirage_style::get().version(); - auto author = mirage_style::get().author(); - auto description = mirage_style::get().description(); - auto license = mirage_style::get().license(); + const auto name = mirage_style::get().name(); + const auto version = mirage_style::get().version(); + const auto author = mirage_style::get().author(); + const auto description = mirage_style::get().description(); + const auto license = mirage_style::get().license(); std::stringstream ss; ss << "name: " << name << "\n"; @@ -65,76 +65,76 @@ int main(int argc, char* argv[]) { const auto& window = mwindow::create({ 800, 600 }, L"Hello, World!"); window->set_content( - mnew(mv_box) + mnew(mv_box) + [ + mslot(mv_box) + .horizontal_alignment(horizontal_alignment_t::left) + + mnew(mbutton) [ - mslot(mv_box) - .horizontal_alignment(horizontal_alignment_t::left) - + mnew(mbutton) - [ - mslot(mbutton) - .margin({ 10 }) - .visibility(visibility_t::visible) - [ - mnew(mtext_block, - .text(config_info_str) - .font_size(15) - ) - ] - ], + mslot(mbutton) + .margin({10}) + .visibility(visibility_t::visible)[ + mnew(mtext_block, + .text(config_info_str) + .font_size(15) + ) + ] + ], - mslot(mv_box) - .horizontal_alignment(horizontal_alignment_t::right) - + mnew(mbutton) + mslot(mv_box) + .horizontal_alignment(horizontal_alignment_t::right) + + mnew(mbutton) + [ + mslot(mbutton) + .margin({10}) + .visibility(visibility_t::visible) [ - mslot(mbutton) - .margin({ 10 }) - .visibility(visibility_t::visible) - [ - mnew(mtext_block, - .text(U"Hello, World! 你好,世界!\n换行测试1111,测试测试测试测试,测试测试😀🐵🙏 😃🐵🙏") - // .text(U"😀🐵🙏😀🐵🙏") - .font_size(15) - .warp_text(true) - ) - ] + mnew(mtext_block, + .text(U"Hello, World! 你好,世界!\n换行测试1111,测试测试测试测试,测试测试😀🐵🙏 😃🐵🙏") + // .text(U"😀🐵🙏😀🐵🙏") + .font_size(15) + .warp_text(true) + ) ] ] - ); + ] + ); - const auto& window2 = mwindow::create({ 800, 600 }, L"Hello, World!"); + const auto& window2 = mwindow::create({800, 600}, L"Hello, World!"); window2->set_content( mnew(moverlay) [ mslot(moverlay) .h_alignment(horizontal_alignment_t::center) .v_alignment(vertical_alignment_t::center) - +mnew(mbutton) + + mnew(mbutton) [ mslot(mbutton) - .margin({ 10 }) + .margin({10}) [ mnew(mtext_block, - .text(U"测试测试") - .font_size(24)) + .text(U"测试测试") + .font_size(24)) ] ], mslot(moverlay) .h_alignment(horizontal_alignment_t::center) .v_alignment(vertical_alignment_t::center) - +mnew(mbutton) + + mnew(mbutton) [ mslot(mbutton) - .margin({ 10 }) + .margin({10}) [ mnew(mtext_block, - .text(U"测试测试21111") - .font_size(15)) + .text(U"测试测试21111") + .font_size(15)) ] ] ] ); + mirage_app::get().run(); return 0; } diff --git a/src/mirage_app/mirage.cpp b/src/mirage_app/mirage.cpp index 5d74bff..2cf22c5 100644 --- a/src/mirage_app/mirage.cpp +++ b/src/mirage_app/mirage.cpp @@ -88,8 +88,11 @@ void mirage_app::run() { } last_time = get_current_time(); + // TODO 不应该在任何时候都睡眠1ms, 而是应该在没有事件时睡眠 std::this_thread::sleep_for(std::chrono::milliseconds(1)); } + // 清理资源 + std::println(std::cout, "mirage: 清理资源"); running = false; texture_sampler_builder::clear(); render_context->cleanup();