Files
mirage/example/src/main.cpp
2025-07-01 21:04:44 +08:00

149 lines
3.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <iostream>
#include "mirage.h"
#include "font/font_system.h"
#include "style/mirage_style.h"
#include "widget/compound_widget/mbutton.h"
#include "widget/leaf_widget/mtext_block.h"
#include "widget/panel_widget/mbox.h"
#include "widget/widget_new.h"
#include "window/mwindow.h"
#include "utf8.h"
#include "misc/log_util.h"
#include "widget/leaf_widget/meditable_text_box.h"
#include "widget/panel_widget/moverlay.h"
void test_color() {
const char* test_cases[] = {
"#FFF", // hex rgb
"#ff0000", // hex RRGGBB
"#00ff0080", // hex RRGGBBAA
"#1234", // hex RGBA
"rgb(255,0,0)", // rgb int
"rgba(0,255,0,128)", // rgba int
"rgba(0, 0, 255, 255)", // rgba int with spaces
"rgb(1.0, 0.0, 0.0)", // rgb float
"rgba(0.0, 1.0, 0.0, 0.5)", // rgba float
" rgb(0.0, 0.0, 1.0) ", // rgb float with spaces
"rgba(1, 0.5, 0, 1.0)", // rgba mixed - should parse as float
"invalid",
"#12345",
"rgb(300,0,0)",
"rgba(1.1, 0, 0, 1)",
"rgba(100,100,100)" // missing alpha
};
for (const char* test_str: test_cases) {
std::optional<linear_color> color = linear_color::from_string(test_str);
log_info("Parsing '{}': ", test_str);
if (color) {
log_info("Success -> r:{}, g:{}, b:{}, a:{}", color->r, color->g, color->b, color->a);
}
else { log_info("Failed to parse color string: {}", test_str); }
}
}
int main(int argc, char* argv[]) {
mirage_app::get().init();
font_manager::instance().load_default_font();
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";
ss << "version: " << version << "\n";
ss << "author: " << author << "\n";
ss << "description: " << description << "\n";
ss << "license: " << license;
// const char*转换为std::u32string
const auto& config_info_str = utf8::utf8to32(ss.str());
const auto& window = mwindow::create({ 800, 600 }, L"Hello, World!");
window->show();
window->set_content(
mnew(mv_box)
[
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(mv_box)
.horizontal_alignment(horizontal_alignment_t::right)
+ mnew(mbutton)
[
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)
)
]
],
mslot(mv_box)
.horizontal_alignment(horizontal_alignment_t::stretch)
+ mnew(meditable_text_box)
]
);
const auto& window2 = mwindow::create({800, 600}, L"Hello, World!");
window2->show();
window2->set_content(
mnew(moverlay)
[
mslot(moverlay)
.h_alignment(horizontal_alignment_t::center)
.v_alignment(vertical_alignment_t::center)
+ mnew(mbutton)
[
mslot(mbutton)
.margin({10})
[
mnew(mtext_block,
.text(U"测试测试")
.font_size(24))
]
],
mslot(moverlay)
.h_alignment(horizontal_alignment_t::center)
.v_alignment(vertical_alignment_t::center)
+ mnew(mbutton)
[
mslot(mbutton)
.margin({10})
[
mnew(mtext_block,
.text(U"测试测试21111")
.font_size(15))
]
]
]
);
mirage_app::get().run();
return 0;
}