Skip to content

Commit 450d83a

Browse files
feat: enhance enum handling and update breeze-ui package configuration
1 parent 9ffe52a commit 450d83a

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

dependencies/breeze-ui.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ package("breeze-glfw")
44
add_versions("latest", "master")
55

66
package("breeze-ui")
7-
add_urls("https://github.com/std-microblock/breeze-ui.git")
8-
add_versions("2025.10.09", "c880cbc29340861ba75ca512ddb190d4e2dc416c")
7+
-- add_urls("https://github.com/std-microblock/breeze-ui.git")
8+
-- add_versions("2025.10.08+9", "2a84657f33791b33059405983ea5d9d4ea52094c")
9+
set_sourcedir("E:/breeze-ui")
910
add_deps("breeze-glfw", "nanovg", "glad", "nanosvg")
1011
add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
1112

src/shell/script/binding_types_breeze_ui.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ std::string breeze_ui::js_flex_layout_widget::get_justify_content() const {
512512
auto widget = std::dynamic_pointer_cast<ui::flex_widget>($widget);
513513
if (!widget)
514514
return "";
515-
return std::string(reflect::enum_name(widget->justify_content));
515+
return std::string(mb_shell::string_from_enum(widget->justify_content));
516516
}
517517

518518
void breeze_ui::js_flex_layout_widget::set_justify_content(
@@ -531,7 +531,7 @@ std::string breeze_ui::js_flex_layout_widget::get_align_items() const {
531531
auto widget = std::dynamic_pointer_cast<ui::flex_widget>($widget);
532532
if (!widget)
533533
return "";
534-
return std::string(reflect::enum_name(widget->align_items));
534+
return std::string(mb_shell::string_from_enum(widget->align_items));
535535
}
536536

537537
void breeze_ui::js_flex_layout_widget::set_align_items(std::string align) {

src/shell/utils.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ struct perf_counter {
7676
perf_counter(std::string name);
7777
};
7878

79+
template <typename E> constexpr std::string_view string_from_enum(E e) {
80+
return reflect::enum_name(e) |
81+
std::views::transform([](char c) { return c == '_' ? '-' : c; }) |
82+
std::ranges::to<std::string>();
83+
}
84+
7985
template <typename E> constexpr auto create_enum_map() {
8086
constexpr auto min = reflect::enum_min(E{});
8187
constexpr auto max = reflect::enum_max(E{});
@@ -87,7 +93,7 @@ template <typename E> constexpr auto create_enum_map() {
8793
for (int i = min; i <= max; ++i) {
8894
E value = static_cast<E>(i);
8995
auto name = reflect::enum_name(value);
90-
if (!name.empty() && name != "") { // 过滤无效名称
96+
if (!name.empty() && name != "") {
9197
map[index++] = {name, value};
9298
}
9399
}
@@ -100,7 +106,10 @@ constexpr std::optional<E> enum_from_string(std::string_view str) {
100106
static constexpr auto enum_map = create_enum_map<E>();
101107

102108
for (const auto &[name, value] : enum_map) {
103-
if (name == str) {
109+
// accept both '-' and '_' as word separators
110+
if ((str |
111+
std::views::transform([](char c) { return c == '-' ? '_' : c; }) |
112+
std::ranges::to<std::string>()) == name) {
104113
return value;
105114
}
106115
}

0 commit comments

Comments
 (0)