mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 10:50:00 +00:00
MenuItem with for
and if
This commit is contained in:
parent
e75415554a
commit
010126992e
24 changed files with 889 additions and 258 deletions
|
@ -298,6 +298,7 @@ fn gen_corelib(
|
|||
"Opacity",
|
||||
"Layer",
|
||||
"ContextMenu",
|
||||
"MenuItem",
|
||||
];
|
||||
|
||||
config.export.include = [
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
#endif
|
||||
|
||||
#include "slint_internal.h"
|
||||
#include "slint_size.h"
|
||||
#include "slint_point.h"
|
||||
#include "slint_platform_internal.h"
|
||||
#include "slint_qt_internal.h"
|
||||
#include "slint_window.h"
|
||||
|
@ -1260,6 +1258,35 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
inline void setup_popup_menu_from_menu_item_tree(
|
||||
const ItemTreeRc &menu_item_tree,
|
||||
Property<std::shared_ptr<Model<cbindgen_private::MenuEntry>>> &entries,
|
||||
Callback<std::shared_ptr<Model<cbindgen_private::MenuEntry>>(cbindgen_private::MenuEntry)>
|
||||
&sub_menu,
|
||||
Callback<void(cbindgen_private::MenuEntry)> &activated)
|
||||
{
|
||||
using cbindgen_private::MenuEntry;
|
||||
using cbindgen_private::MenuVTable;
|
||||
auto shared = std::make_shared<vtable::VBox<MenuVTable>>(nullptr, nullptr);
|
||||
cbindgen_private::slint_menus_create_wrapper(&menu_item_tree, &*shared);
|
||||
SharedVector<MenuEntry> entries_sv;
|
||||
vtable::VRefMut<MenuVTable> ref { shared->vtable, shared->instance };
|
||||
shared->vtable->sub_menu(ref, nullptr, &entries_sv);
|
||||
std::vector<MenuEntry> entries_vec(entries_sv.begin(), entries_sv.end());
|
||||
entries.set(std::make_shared<VectorModel<MenuEntry>>(std::move(entries_vec)));
|
||||
sub_menu.set_handler([shared](const auto &entry) {
|
||||
vtable::VRefMut<MenuVTable> ref { shared->vtable, shared->instance };
|
||||
SharedVector<MenuEntry> entries_sv;
|
||||
shared->vtable->sub_menu(ref, &entry, &entries_sv);
|
||||
std::vector<MenuEntry> entries_vec(entries_sv.begin(), entries_sv.end());
|
||||
return std::make_shared<VectorModel<MenuEntry>>(std::move(entries_vec));
|
||||
});
|
||||
activated.set_handler([shared](const auto &entry) {
|
||||
vtable::VRefMut<MenuVTable> ref { shared->vtable, shared->instance };
|
||||
shared->vtable->activate(ref, &entry);
|
||||
});
|
||||
}
|
||||
|
||||
inline SharedString translate(const SharedString &original, const SharedString &context,
|
||||
const SharedString &domain,
|
||||
cbindgen_private::Slice<SharedString> arguments, int n,
|
||||
|
|
|
@ -40,6 +40,7 @@ struct VBox
|
|||
{
|
||||
const T *vtable = nullptr;
|
||||
void *instance = nullptr;
|
||||
explicit VBox(const T *vtable, void *instance) : vtable(vtable), instance(instance) { }
|
||||
VBox(const VBox &) = delete;
|
||||
VBox() = default;
|
||||
VBox &operator=(const VBox &) = delete;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue