diff --git a/.gitmodules b/.gitmodules index fcc36fd..411d442 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "src/mirage_widget/third_party/tomlplusplus"] path = src/mirage_widget/third_party/tomlplusplus url = https://github.com/marzer/tomlplusplus.git +[submodule "src/mirage_core/third_party/utfcpp"] + path = src/mirage_core/third_party/utfcpp + url = https://github.com/nemtrif/utfcpp.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 01b07fb..bb83cd3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,13 +4,18 @@ cmake_minimum_required(VERSION 3.21) project(mirage) -set(CMAKE_CXX_STANDARD 26) +# 指定需要的 C++ 标准 +set(CMAKE_CXX_STANDARD 23) +# 强制要求此标准,如果编译器不支持则配置时报错 +set(CMAKE_CXX_STANDARD_REQUIRED ON) +# 可选:禁用编译器特定的扩展,使用纯粹的标准 +set(CMAKE_CXX_EXTENSIONS OFF) if (MSVC) - # MSVC编译器设置C++标准 - add_compile_options(/std:c++latest) # 设置utf-8编码 add_compile_options(/utf-8) + # 强制 MSVC 正确设置 __cplusplus 宏 + add_compile_options(/Zc:__cplusplus) endif () if (WIN32) # 定义Windows版本宏 diff --git a/example/src/main.cpp b/example/src/main.cpp index 7201781..f2583e7 100644 --- a/example/src/main.cpp +++ b/example/src/main.cpp @@ -3,17 +3,23 @@ #include "mirage.h" #include "window/mwindow.h" #include "font/font_system.h" +#include "style/mirage_style.h" #include "widget/widget_new.h" #include "widget/compound_widget/mbutton.h" #include "widget/leaf_widget/mtext_block.h" #include "widget/panel_widget/mbox.h" +#include "utf8.h" + int main(int argc, char* argv[]) { mirage_app::get().init(); - auto c1 = linear_color::from_string("#FF0000"); - auto c2 = linear_color::from_string("rgb(255, 0, 0)"); - auto c3 = linear_color::from_string("rgba(255, 0, 0, 255)"); + 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(); + auto& manager = font_manager::instance(); manager.add_font(L"C:/Users/46944/AppData/Local/Microsoft/Windows/Fonts/MapleMono-NF-CN-Regular.ttf"); @@ -22,7 +28,18 @@ int main(int argc, char* argv[]) { manager.add_font(L"C:/Windows/Fonts/seguiemj.ttf"); const auto& text_block = std::make_shared(); - text_block->set_text(U"Hello, World! 你好,世界!\n换行测试1111,测试测试测试测试,测试测试😀🐵🙏 😃🐵🙏"); + std::stringstream ss; + ss << "name: " << name << "\n"; + ss << "version: " << version << "\n"; + ss << "author: " << author << "\n"; + ss << "description: " << description << "\n"; + ss << "license: " << license << "\n"; + // text_block->set_text(U"Hello, World! 你好,世界!\n换行测试1111,测试测试测试测试,测试测试😀🐵🙏 😃🐵🙏"); + + const auto& utf32 = utf8::utf8to32(ss.str()); + + // const char*转换为std::u32string + text_block->set_text(utf32); const auto& text_block2 = std::make_shared(); text_block2->set_text(U"Hello, World!"); diff --git a/src/mirage_core/CMakeLists.txt b/src/mirage_core/CMakeLists.txt index 2734971..8cf996c 100644 --- a/src/mirage_core/CMakeLists.txt +++ b/src/mirage_core/CMakeLists.txt @@ -4,11 +4,13 @@ project(mirage_core LANGUAGES C CXX) find_package(Eigen3 REQUIRED) +add_subdirectory(third_party/utfcpp) + set(SRC_FILES) -retrieve_files(${CMAKE_CURRENT_SOURCE_DIR} SRC_FILES) +retrieve_files(${CMAKE_CURRENT_SOURCE_DIR}/src SRC_FILES) add_library(${PROJECT_NAME} STATIC ${SRC_FILES}) -target_link_libraries(${PROJECT_NAME} PUBLIC Eigen3::Eigen mirage_image) -target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_link_libraries(${PROJECT_NAME} PUBLIC Eigen3::Eigen mirage_image utf8cpp) +target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src) add_os_definitions(${PROJECT_NAME}) target_compile_definitions(${PROJECT_NAME} PUBLIC -DNOMINMAX) diff --git a/src/mirage_core/geometry/dpi_helper.h b/src/mirage_core/src/geometry/dpi_helper.h similarity index 100% rename from src/mirage_core/geometry/dpi_helper.h rename to src/mirage_core/src/geometry/dpi_helper.h diff --git a/src/mirage_core/geometry/geometry.h b/src/mirage_core/src/geometry/geometry.h similarity index 100% rename from src/mirage_core/geometry/geometry.h rename to src/mirage_core/src/geometry/geometry.h diff --git a/src/mirage_core/geometry/layout_transform.cpp b/src/mirage_core/src/geometry/layout_transform.cpp similarity index 100% rename from src/mirage_core/geometry/layout_transform.cpp rename to src/mirage_core/src/geometry/layout_transform.cpp diff --git a/src/mirage_core/geometry/layout_transform.h b/src/mirage_core/src/geometry/layout_transform.h similarity index 100% rename from src/mirage_core/geometry/layout_transform.h rename to src/mirage_core/src/geometry/layout_transform.h diff --git a/src/mirage_core/geometry/margin.h b/src/mirage_core/src/geometry/margin.h similarity index 100% rename from src/mirage_core/geometry/margin.h rename to src/mirage_core/src/geometry/margin.h diff --git a/src/mirage_core/geometry/rect.h b/src/mirage_core/src/geometry/rect.h similarity index 100% rename from src/mirage_core/geometry/rect.h rename to src/mirage_core/src/geometry/rect.h diff --git a/src/mirage_core/misc/angle_literals.h b/src/mirage_core/src/misc/angle_literals.h similarity index 100% rename from src/mirage_core/misc/angle_literals.h rename to src/mirage_core/src/misc/angle_literals.h diff --git a/src/mirage_core/misc/delegates.h b/src/mirage_core/src/misc/delegates.h similarity index 100% rename from src/mirage_core/misc/delegates.h rename to src/mirage_core/src/misc/delegates.h diff --git a/src/mirage_core/misc/enum_flags.h b/src/mirage_core/src/misc/enum_flags.h similarity index 100% rename from src/mirage_core/misc/enum_flags.h rename to src/mirage_core/src/misc/enum_flags.h diff --git a/src/mirage_core/misc/invalidate_reason.h b/src/mirage_core/src/misc/invalidate_reason.h similarity index 100% rename from src/mirage_core/misc/invalidate_reason.h rename to src/mirage_core/src/misc/invalidate_reason.h diff --git a/src/mirage_core/misc/key_type/key_type.h b/src/mirage_core/src/misc/key_type/key_type.h similarity index 100% rename from src/mirage_core/misc/key_type/key_type.h rename to src/mirage_core/src/misc/key_type/key_type.h diff --git a/src/mirage_core/misc/key_type/windows/key_type.cpp b/src/mirage_core/src/misc/key_type/windows/key_type.cpp similarity index 100% rename from src/mirage_core/misc/key_type/windows/key_type.cpp rename to src/mirage_core/src/misc/key_type/windows/key_type.cpp diff --git a/src/mirage_core/misc/mapped_file/mapped_file.h b/src/mirage_core/src/misc/mapped_file/mapped_file.h similarity index 100% rename from src/mirage_core/misc/mapped_file/mapped_file.h rename to src/mirage_core/src/misc/mapped_file/mapped_file.h diff --git a/src/mirage_core/misc/mapped_file/unix/mapped_file.cpp b/src/mirage_core/src/misc/mapped_file/unix/mapped_file.cpp similarity index 100% rename from src/mirage_core/misc/mapped_file/unix/mapped_file.cpp rename to src/mirage_core/src/misc/mapped_file/unix/mapped_file.cpp diff --git a/src/mirage_core/misc/mapped_file/windows/mapped_file.cpp b/src/mirage_core/src/misc/mapped_file/windows/mapped_file.cpp similarity index 100% rename from src/mirage_core/misc/mapped_file/windows/mapped_file.cpp rename to src/mirage_core/src/misc/mapped_file/windows/mapped_file.cpp diff --git a/src/mirage_core/misc/mirage_scoped_duration_timer.h b/src/mirage_core/src/misc/mirage_scoped_duration_timer.h similarity index 100% rename from src/mirage_core/misc/mirage_scoped_duration_timer.h rename to src/mirage_core/src/misc/mirage_scoped_duration_timer.h diff --git a/src/mirage_core/misc/mirage_type.h b/src/mirage_core/src/misc/mirage_type.h similarity index 100% rename from src/mirage_core/misc/mirage_type.h rename to src/mirage_core/src/misc/mirage_type.h diff --git a/src/mirage_core/misc/name.h b/src/mirage_core/src/misc/name.h similarity index 100% rename from src/mirage_core/misc/name.h rename to src/mirage_core/src/misc/name.h diff --git a/src/mirage_core/misc/scope_exit.h b/src/mirage_core/src/misc/scope_exit.h similarity index 100% rename from src/mirage_core/misc/scope_exit.h rename to src/mirage_core/src/misc/scope_exit.h diff --git a/src/mirage_core/third_party/utfcpp b/src/mirage_core/third_party/utfcpp new file mode 160000 index 0000000..65701fe --- /dev/null +++ b/src/mirage_core/third_party/utfcpp @@ -0,0 +1 @@ +Subproject commit 65701fe00700577f9f4e9b96d682bd7cfcc0b76e