分离config使其作为单独的模块
This commit is contained in:
parent
791fca9282
commit
57c65892db
6
.gitmodules
vendored
6
.gitmodules
vendored
@ -4,9 +4,9 @@
|
||||
[submodule "src/mirage_render/font/freetype_font/harfbuzz"]
|
||||
path = src/mirage_render/font/freetype_font/harfbuzz
|
||||
url = https://github.com/harfbuzz/harfbuzz
|
||||
[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
|
||||
[submodule "src/mirage_config/third_party/tomlplusplus"]
|
||||
path = src/mirage_config/third_party/tomlplusplus
|
||||
url = https://github.com/marzer/tomlplusplus.git
|
||||
|
@ -43,6 +43,7 @@ else ()
|
||||
endif ()
|
||||
|
||||
add_subdirectory(src/sokol)
|
||||
add_subdirectory(src/mirage_config)
|
||||
add_subdirectory(src/mirage_render)
|
||||
add_subdirectory(src/mirage_image)
|
||||
add_subdirectory(src/mirage_core)
|
||||
|
@ -11,15 +11,7 @@
|
||||
|
||||
#include "utf8.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
mirage_app::get().init();
|
||||
|
||||
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();
|
||||
|
||||
void test_color() {
|
||||
const char* test_cases[] = {
|
||||
"#FFF", // hex rgb
|
||||
"#ff0000", // hex RRGGBB
|
||||
@ -48,24 +40,30 @@ int main(int argc, char* argv[]) {
|
||||
std::println(std::cerr, "Failed to parse color string: {}", test_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto& manager = font_manager::instance();
|
||||
manager.add_font(L"C:/Users/46944/AppData/Local/Microsoft/Windows/Fonts/MapleMono-NF-CN-Regular.ttf");
|
||||
manager.add_font(L"C:/Windows/Fonts/msyh.ttc");
|
||||
// manager.add_font(L"D:/Projects/noto-emoji-2.047/fonts/Noto-COLRv1.ttf");
|
||||
manager.add_font(L"C:/Windows/Fonts/seguiemj.ttf");
|
||||
int main(int argc, char* argv[]) {
|
||||
mirage_app::get().init();
|
||||
|
||||
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& text_block = std::make_shared<mtext_block>();
|
||||
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 char*转换为std::u32string
|
||||
text_block->set_text(utf8::utf8to32(ss.str()));
|
||||
const auto& config_info_str = utf8::utf8to32(ss.str());
|
||||
const auto& text_block = std::make_shared<mtext_block>();
|
||||
text_block->set_text(config_info_str);
|
||||
// text_block->set_text(U"Hello, World! 你好,世界!\n换行测试1111,测试测试测试测试,测试测试😀🐵🙏 😃🐵🙏");
|
||||
|
||||
const auto& text_block2 = std::make_shared<mtext_block>();
|
||||
text_block2->set_text(U"Hello, World!");
|
||||
|
@ -63,13 +63,12 @@ void mirage_app::init() {
|
||||
}
|
||||
render_context = mirage_create_render_context();
|
||||
render_context->init();
|
||||
const sg_desc desc = {
|
||||
.logger = {
|
||||
.func = mirage_log,
|
||||
.user_data = nullptr
|
||||
},
|
||||
.environment = render_context->get_environment(),
|
||||
sg_desc desc = {};
|
||||
desc.logger = {
|
||||
.func = mirage_log,
|
||||
.user_data = nullptr
|
||||
};
|
||||
desc.environment = render_context->get_environment();
|
||||
sg_setup(desc);
|
||||
render_context->end_init();
|
||||
}
|
||||
|
10
src/mirage_config/CMakeLists.txt
Normal file
10
src/mirage_config/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
project(mirage_config)
|
||||
|
||||
add_subdirectory(third_party/tomlplusplus)
|
||||
|
||||
set(SRC_FILES)
|
||||
retrieve_files(${CMAKE_CURRENT_SOURCE_DIR}/src SRC_FILES)
|
||||
|
||||
add_library(${PROJECT_NAME} STATIC ${SRC_FILES})
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC tomlplusplus::tomlplusplus)
|
14
src/mirage_config/src/config.cpp
Normal file
14
src/mirage_config/src/config.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
bool config_t::load_config(const std::filesystem::path& in_filename) {
|
||||
try {
|
||||
tbl = toml::parse_file(in_filename.string());
|
||||
}
|
||||
catch (const toml::parse_error& err) {
|
||||
std::println(std::cerr, "{}", err.what());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
14
src/mirage_config/src/config.h
Normal file
14
src/mirage_config/src/config.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include <toml++/toml.hpp>
|
||||
#include <filesystem>
|
||||
|
||||
class config_t {
|
||||
public:
|
||||
bool load_config(const std::filesystem::path& in_filename);
|
||||
|
||||
[[nodiscard]] const auto& get_config() const {
|
||||
return tbl;
|
||||
}
|
||||
protected:
|
||||
toml::table tbl{};
|
||||
};
|
@ -11,6 +11,15 @@ void font_manager::destroy() {
|
||||
destroy_font_system();
|
||||
}
|
||||
|
||||
void font_manager::load_default_font() {
|
||||
#if MIRAGE_PLATFORM_WINDOWS
|
||||
add_font(L"C:/Windows/Fonts/msyh.ttc");
|
||||
add_font(L"C:/Windows/Fonts/seguiemj.ttf");
|
||||
#else
|
||||
static_assert(false, "暂时不支持当前平台的默认字体加载");
|
||||
#endif
|
||||
}
|
||||
|
||||
int font_manager::add_font(const std::filesystem::path& in_font_path, const std::string& in_font_type) {
|
||||
auto font = create_font_face(in_font_path);
|
||||
if (!font) {
|
||||
|
@ -38,6 +38,11 @@ public:
|
||||
*/
|
||||
void destroy();
|
||||
|
||||
/**
|
||||
* @brief 加载操作系统默认字体
|
||||
*/
|
||||
void load_default_font();
|
||||
|
||||
/**
|
||||
* @brief 添加字体
|
||||
*
|
||||
|
@ -3,11 +3,9 @@ project(mirage_widget)
|
||||
set(SRC_FILES)
|
||||
retrieve_files(${CMAKE_CURRENT_SOURCE_DIR}/src SRC_FILES)
|
||||
|
||||
add_subdirectory(third_party/tomlplusplus)
|
||||
|
||||
add_library(${PROJECT_NAME} STATIC ${SRC_FILES})
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC mirage_core mirage_render tomlplusplus::tomlplusplus)
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC mirage_core mirage_render mirage_config)
|
||||
|
||||
add_resource_file(
|
||||
TARGET_NAME ${PROJECT_NAME}
|
||||
|
@ -1,12 +1,2 @@
|
||||
#include "mirage_style.h"
|
||||
|
||||
bool mirage_style::load_config(const std::filesystem::path& in_filename) {
|
||||
try {
|
||||
tbl = toml::parse_file(in_filename.string());
|
||||
}
|
||||
catch (const toml::parse_error& err) {
|
||||
fprintf(stderr, "%s\n", err.what());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1,21 +1,13 @@
|
||||
#pragma once
|
||||
#include "misc/name.h"
|
||||
#include <toml++/toml.hpp>
|
||||
#include <filesystem>
|
||||
#include "config.h"
|
||||
|
||||
class mirage_style {
|
||||
class mirage_style : public config_t {
|
||||
public:
|
||||
static auto& get() {
|
||||
static mirage_style instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool load_config(const std::filesystem::path& in_filename);
|
||||
|
||||
[[nodiscard]] const auto& get_config() const {
|
||||
return tbl;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto name() const {
|
||||
return tbl["info"]["name"].value_or("unknown");
|
||||
}
|
||||
@ -37,5 +29,4 @@ public:
|
||||
}
|
||||
private:
|
||||
mirage_style() = default;
|
||||
toml::table tbl{};
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user