将 C++ 标准更新到 26 并改进资源清理

在构建配置中将 C++ 标准提高到 26,并在应用程序关闭之前添加资源清理消息。为了 UI 代码的一致性,对格式进行了细微的调整。
This commit is contained in:
daiqingshuang
2025-05-07 17:23:33 +08:00
parent 0b5487f69d
commit 607d0a43a1
4 changed files with 49 additions and 46 deletions

View File

@@ -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")

View File

@@ -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}")

View File

@@ -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;
}

View File

@@ -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();