Skip to main content

waft_widgets/widgets/
platform_selectable_region_context_menu.rs

1//! Flutter counterpart: `widgets/platform_selectable_region_context_menu.dart` and its
2//! `_platform_selectable_region_context_menu_io.dart` stub.
3//!
4//! A widget that provides the web's native selection context menu for its child subtree. The
5//! non-web implementation is a stub: every member throws, and nothing names it yet, since the
6//! web implementation is deferred (`## Deferred` in `PORTING.md`).
7
8use crate::framework::{BuildContext, KeyRef, StatelessWidget, WidgetRef};
9use crate::widgets::selection_container::AnySelectionContainerDelegate;
10use waft_foundation::App;
11
12/// Function signature for `ui_web.platformViewRegistry.registerViewFactory`.
13pub type RegisterViewFactory = fn(String, Box<dyn Fn(i32) -> Box<dyn std::any::Any>>, bool);
14
15/// A widget that provides native selection context menu for its child subtree.
16///
17/// This widget currently only supports Flutter web. Using this widget on non-web platforms
18/// throws [`UnimplementedError`](std::unimplemented).
19pub struct PlatformSelectableRegionContextMenu {
20    pub key: Option<KeyRef>,
21    /// The widget below this widget in the tree.
22    pub child: WidgetRef,
23}
24
25impl PlatformSelectableRegionContextMenu {
26    /// Creates a [`PlatformSelectableRegionContextMenu`].
27    #[cfg_attr(debug_assertions, track_caller)]
28    pub fn new<K>(child: impl crate::framework::IntoWidget<K>) -> Self {
29        PlatformSelectableRegionContextMenu {
30            key: None,
31            child: child.into_widget(),
32        }
33    }
34
35    /// Attaches the client to the platform-appropriate context menus.
36    pub fn attach(_client: AnySelectionContainerDelegate) {
37        unimplemented!()
38    }
39
40    /// Detaches the client from the platform-appropriate selection context menus.
41    pub fn detach(_client: AnySelectionContainerDelegate) {
42        unimplemented!()
43    }
44
45    /// The client currently attached to the platform context menu.
46    pub fn debug_active_client() -> Option<AnySelectionContainerDelegate> {
47        unimplemented!()
48    }
49
50    /// Resets the view factory registration to its initial state.
51    pub fn debug_reset_registry() {
52        unimplemented!()
53    }
54}
55
56impl std::fmt::Debug for PlatformSelectableRegionContextMenu {
57    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
58        f.debug_struct("PlatformSelectableRegionContextMenu")
59            .finish_non_exhaustive()
60    }
61}
62
63impl StatelessWidget for PlatformSelectableRegionContextMenu {
64    fn key(&self) -> Option<&KeyRef> {
65        self.key.as_ref()
66    }
67
68    fn build(&self, _app: &mut App, _context: BuildContext) -> WidgetRef {
69        unimplemented!()
70    }
71}