mirror of
https://github.com/slint-ui/slint.git
synced 2025-08-04 10:50:00 +00:00
Create a menus
module in i-slint-corelib
This commit is contained in:
parent
aeabfc1ca8
commit
e75415554a
7 changed files with 28 additions and 19 deletions
|
@ -208,6 +208,7 @@ pub mod re_exports {
|
|||
pub use i_slint_core::lengths::{
|
||||
logical_position_to_api, LogicalLength, LogicalPoint, LogicalRect,
|
||||
};
|
||||
pub use i_slint_core::menus::{Menu, MenuVTable};
|
||||
pub use i_slint_core::model::*;
|
||||
pub use i_slint_core::properties::{
|
||||
set_state_binding, ChangeTracker, Property, PropertyTracker, StateInfo,
|
||||
|
@ -219,7 +220,7 @@ pub mod re_exports {
|
|||
set_bundled_languages, translate_from_bundle, translate_from_bundle_with_plural,
|
||||
};
|
||||
pub use i_slint_core::window::{
|
||||
InputMethodRequest, Menu, MenuVTable, WindowAdapter, WindowAdapterRc, WindowInner,
|
||||
InputMethodRequest, WindowAdapter, WindowAdapterRc, WindowInner,
|
||||
};
|
||||
pub use i_slint_core::{Color, Coord, SharedString, SharedVector};
|
||||
pub use i_slint_core::{ItemTreeVTable_static, MenuVTable_static};
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
|
||||
|
||||
use crate::SlintUserEvent;
|
||||
use i_slint_core::window::MenuVTable;
|
||||
use i_slint_core::menus::MenuVTable;
|
||||
use winit::event_loop::EventLoopProxy;
|
||||
use winit::window::Window;
|
||||
|
||||
|
|
|
@ -1133,7 +1133,7 @@ impl WindowAdapterInternal for WinitWindowAdapter {
|
|||
}
|
||||
|
||||
#[cfg(muda)]
|
||||
fn setup_menubar(&self, menubar: vtable::VBox<i_slint_core::window::MenuVTable>) {
|
||||
fn setup_menubar(&self, menubar: vtable::VBox<i_slint_core::menus::MenuVTable>) {
|
||||
drop(self.muda_adapter.borrow_mut().take());
|
||||
self.muda_adapter.replace(Some(crate::muda::MudaAdapter::setup(
|
||||
menubar,
|
||||
|
|
|
@ -39,6 +39,7 @@ pub mod item_tree;
|
|||
pub mod items;
|
||||
pub mod layout;
|
||||
pub mod lengths;
|
||||
pub mod menus;
|
||||
pub mod model;
|
||||
pub mod platform;
|
||||
pub mod properties;
|
||||
|
|
18
internal/core/menus.rs
Normal file
18
internal/core/menus.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
||||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
|
||||
|
||||
use crate::items::MenuEntry;
|
||||
use crate::SharedVector;
|
||||
use vtable::{VRef, VRefMut};
|
||||
|
||||
/// Interface for native menu and menubar
|
||||
#[vtable::vtable]
|
||||
#[repr(C)]
|
||||
pub struct MenuVTable {
|
||||
/// destructor
|
||||
drop: fn(VRefMut<MenuVTable>),
|
||||
/// Return the list of items for the sub menu (or the main menu of parent is None)
|
||||
sub_menu: fn(VRef<MenuVTable>, Option<&MenuEntry>, &mut SharedVector<MenuEntry>),
|
||||
/// Handler when the menu entry is activated
|
||||
activate: fn(VRef<MenuVTable>, &MenuEntry),
|
||||
}
|
|
@ -15,11 +15,12 @@ use crate::input::{
|
|||
MouseInputState, TextCursorBlinker,
|
||||
};
|
||||
use crate::item_tree::{ItemRc, ItemTreeRc, ItemTreeRef, ItemTreeVTable, ItemTreeWeak, ItemWeak};
|
||||
use crate::items::{ColorScheme, InputType, ItemRef, MenuEntry, MouseCursor, PopupClosePolicy};
|
||||
use crate::items::{ColorScheme, InputType, ItemRef, MouseCursor, PopupClosePolicy};
|
||||
use crate::lengths::{LogicalLength, LogicalPoint, LogicalRect, SizeLengths};
|
||||
use crate::menus::MenuVTable;
|
||||
use crate::properties::{Property, PropertyTracker};
|
||||
use crate::renderer::Renderer;
|
||||
use crate::{Callback, Coord, SharedString, SharedVector};
|
||||
use crate::{Callback, Coord, SharedString};
|
||||
use alloc::boxed::Box;
|
||||
use alloc::rc::{Rc, Weak};
|
||||
use alloc::vec::Vec;
|
||||
|
@ -1359,18 +1360,6 @@ impl WindowInner {
|
|||
/// Internal alias for `Rc<dyn WindowAdapter>`.
|
||||
pub type WindowAdapterRc = Rc<dyn WindowAdapter>;
|
||||
|
||||
/// Interface for native menu and menubar
|
||||
#[vtable::vtable]
|
||||
#[repr(C)]
|
||||
pub struct MenuVTable {
|
||||
/// destructor
|
||||
drop: fn(VRefMut<MenuVTable>),
|
||||
/// Return the list of items for the sub menu (or the main menu of parent is None)
|
||||
sub_menu: fn(VRef<MenuVTable>, Option<&MenuEntry>, &mut SharedVector<MenuEntry>),
|
||||
/// Handler when the menu entry is activated
|
||||
activate: fn(VRef<MenuVTable>, &MenuEntry),
|
||||
}
|
||||
|
||||
/// This module contains the functions needed to interface with the event loop and window traits
|
||||
/// from outside the Rust language.
|
||||
#[cfg(feature = "ffi")]
|
||||
|
|
|
@ -6,9 +6,9 @@ use crate::dynamic_item_tree::InstanceRef;
|
|||
use core::pin::Pin;
|
||||
use corelib::graphics::{GradientStop, LinearGradientBrush, PathElement, RadialGradientBrush};
|
||||
use corelib::items::{ColorScheme, ItemRef, MenuEntry, PropertyAnimation};
|
||||
use corelib::menus::{Menu, MenuVTable};
|
||||
use corelib::model::{Model, ModelExt, ModelRc, VecModel};
|
||||
use corelib::rtti::AnimatedBindingKind;
|
||||
use corelib::window::{Menu, MenuVTable};
|
||||
use corelib::{Brush, Color, PathData, SharedString, SharedVector};
|
||||
use i_slint_compiler::expression_tree::{
|
||||
BuiltinFunction, Callable, EasingCurve, Expression, MinMaxOp, Path as ExprPath,
|
||||
|
@ -1889,7 +1889,7 @@ pub struct MenuWrapper {
|
|||
item_tree: crate::dynamic_item_tree::ErasedItemTreeBoxWeak,
|
||||
}
|
||||
i_slint_core::MenuVTable_static!(static MENU_WRAPPER_VTABLE for MenuWrapper);
|
||||
impl i_slint_core::window::Menu for MenuWrapper {
|
||||
impl Menu for MenuWrapper {
|
||||
fn sub_menu(&self, parent: Option<&MenuEntry>, result: &mut SharedVector<MenuEntry>) {
|
||||
let Some(s) = self.item_tree.upgrade() else { return };
|
||||
generativity::make_guard!(guard);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue