Experimental support for MenuBar

Introduces `MenuBar{ ... }` that can be put in a Window
This commit is contained in:
Olivier Goffart 2024-10-08 18:24:52 +02:00
parent 20443ec0df
commit 5bd20def0e
38 changed files with 1023 additions and 69 deletions

View file

@ -221,6 +221,10 @@ fn default_config() -> cbindgen::Config {
("PointArg".into(), "slint::LogicalPosition".into()),
("FloatArg".into(), "float".into()),
("IntArg".into(), "int".into()),
("MenuEntryArg".into(), "MenuEntry".into()),
// Note: these types are not the same, but they are only used in callback return types that are only used in C++ (set and called)
// therefore it is ok to reinterpret_cast
("MenuEntryModel".into(), "std::shared_ptr<slint::Model<MenuEntry>>".into()),
("Coord".into(), "float".into()),
]
.iter()
@ -293,6 +297,7 @@ fn gen_corelib(
"Rotate",
"Opacity",
"Layer",
"ContextMenu",
];
config.export.include = [
@ -370,6 +375,8 @@ fn gen_corelib(
"PointerScrollEventArg",
"PointArg",
"Point",
"MenuEntryModel",
"MenuEntryArg",
"slint_color_brighter",
"slint_color_darker",
"slint_color_transparentize",
@ -500,7 +507,7 @@ fn gen_corelib(
"slint_image_set_nine_slice_edges",
"slint_image_to_rgb8",
"slint_image_to_rgba8",
"slint_image_to_rgba8_premultiplied",
"slint_image_to_rgba8_premultiplied",
"SharedPixelBuffer",
"SharedImageBuffer",
"StaticTextures",
@ -590,7 +597,7 @@ fn gen_corelib(
"slint_image_set_nine_slice_edges",
"slint_image_to_rgb8",
"slint_image_to_rgba8",
"slint_image_to_rgba8_premultiplied",
"slint_image_to_rgba8_premultiplied",
"slint_image_from_embedded_textures",
"slint_image_compare_equal",
]
@ -644,7 +651,7 @@ fn gen_corelib(
public_config.export.item_types = vec![cbindgen::ItemType::Enums, cbindgen::ItemType::Structs];
// Previously included types are now excluded (to avoid duplicates)
public_config.export.exclude = private_exported_types.into_iter().collect();
public_config.export.exclude.push("Point".into());
public_config.export.exclude.push("LogicalPosition".into());
public_config.export.include = public_exported_types.into_iter().map(str::to_string).collect();
public_config.export.body.insert(
"Rgb8Pixel".to_owned(),
@ -760,6 +767,7 @@ namespace slint {
struct ItemVTable;
using types::IntRect;
}
template<typename ModelData> class Model;
}",
)
.with_trailer(gen_item_declarations(&items))

View file

@ -43,6 +43,7 @@ inline void assert_main_thread()
}
using ItemTreeRc = vtable::VRc<cbindgen_private::ItemTreeVTable>;
using slint::LogicalPosition;
class WindowAdapterRc
{
@ -111,7 +112,7 @@ public:
cbindgen_private::ItemRc parent_item) const
{
auto popup = Component::create(parent_component);
cbindgen_private::Point p = pos(popup);
auto p = pos(popup);
auto popup_dyn = popup.into_dyn();
return cbindgen_private::slint_windowrc_show_popup(&inner, &popup_dyn, p, close_policy,
&parent_item);
@ -124,6 +125,20 @@ public:
}
}
template<typename Component, typename SharedGlobals, typename InitFn>
uint32_t show_popup_menu(SharedGlobals *globals, LogicalPosition pos,
cbindgen_private::ItemRc context_menu_rc, InitFn init) const
{
// if (cbindgen_private::slint_windowrc_show_native_context_menu(....)) { return }
auto popup = Component::create(globals);
init(&*popup);
auto popup_dyn = popup.into_dyn();
return cbindgen_private::slint_windowrc_show_popup(
&inner, &popup_dyn, pos, cbindgen_private::PopupClosePolicy::CloseOnClickOutside,
&context_menu_rc);
}
template<std::invocable<RenderingState, GraphicsAPI> F>
std::optional<SetRenderingNotifierError> set_rendering_notifier(F callback) const
{