pub enum WidgetActionBinding {
Action(WidgetActionId),
Command(CommandId),
}Variants§
Action(WidgetActionId)
Command(CommandId)
Implementations§
Source§impl WidgetActionBinding
impl WidgetActionBinding
Sourcepub fn action(id: impl Into<WidgetActionId>) -> Self
pub fn action(id: impl Into<WidgetActionId>) -> Self
Examples found in repository?
examples/showcase.rs (lines 2799-2802)
2580fn showcase_window_descriptors(
2581 state: &ShowcaseState,
2582 desktop_size: UiSize,
2583) -> Vec<ext_widgets::FloatingWindowDescriptor> {
2584 let wide = (desktop_size.width - 36.0).clamp(320.0, 720.0);
2585 let medium = (desktop_size.width - 36.0).clamp(300.0, 604.0);
2586 let buttons_width = medium.min(620.0);
2587 let mut windows = Vec::new();
2588 push_window(
2589 &mut windows,
2590 state.windows.labels,
2591 "labels",
2592 "Labels",
2593 UiSize::new(380.0, 460.0),
2594 );
2595 push_window(
2596 &mut windows,
2597 state.windows.buttons,
2598 "buttons",
2599 "Buttons",
2600 UiSize::new(buttons_width, 220.0),
2601 );
2602 push_window(
2603 &mut windows,
2604 state.windows.checkbox,
2605 "checkbox",
2606 "Checkbox",
2607 UiSize::new(250.0, 72.0),
2608 );
2609 push_window(
2610 &mut windows,
2611 state.windows.toggles,
2612 "toggles",
2613 "Radio and toggles",
2614 UiSize::new(360.0, 320.0),
2615 );
2616 push_window(
2617 &mut windows,
2618 state.windows.slider,
2619 "slider",
2620 "Slider",
2621 UiSize::new(430.0, 560.0),
2622 );
2623 push_window(
2624 &mut windows,
2625 state.windows.numeric,
2626 "numeric",
2627 "Numeric input",
2628 UiSize::new(360.0, 180.0),
2629 );
2630 push_window(
2631 &mut windows,
2632 state.windows.text_input,
2633 "text_input",
2634 "Text input",
2635 UiSize::new(520.0, 560.0),
2636 );
2637 push_window(
2638 &mut windows,
2639 state.windows.selection,
2640 "selection",
2641 "Select controls",
2642 UiSize::new(360.0, 360.0),
2643 );
2644 push_window(
2645 &mut windows,
2646 state.windows.menus,
2647 "menus",
2648 "Menus",
2649 UiSize::new(wide, 520.0),
2650 );
2651 push_window(
2652 &mut windows,
2653 state.windows.command_palette,
2654 "command_palette",
2655 "Command palette",
2656 UiSize::new(520.0, 320.0),
2657 );
2658 push_window(
2659 &mut windows,
2660 state.windows.date_picker,
2661 "date_picker",
2662 "Date picker",
2663 UiSize::new(430.0, 390.0),
2664 );
2665 push_window(
2666 &mut windows,
2667 state.windows.color_picker,
2668 "color_picker",
2669 "Color picker",
2670 UiSize::new(340.0, 390.0),
2671 );
2672 push_window(
2673 &mut windows,
2674 state.windows.color_buttons,
2675 "color_buttons",
2676 "Color buttons",
2677 UiSize::new(430.0, 360.0),
2678 );
2679 push_window(
2680 &mut windows,
2681 state.windows.progress,
2682 "progress",
2683 "Progress indicator",
2684 UiSize::new(500.0, 168.0),
2685 );
2686 push_window(
2687 &mut windows,
2688 state.windows.animation,
2689 "animation",
2690 "Animation",
2691 UiSize::new(520.0, 430.0),
2692 );
2693 push_window(
2694 &mut windows,
2695 state.windows.lists_tables,
2696 "lists_tables",
2697 "Lists and tables",
2698 UiSize::new(wide, 620.0),
2699 );
2700 push_window(
2701 &mut windows,
2702 state.windows.property_inspector,
2703 "property_inspector",
2704 "Property inspector",
2705 UiSize::new(330.0, 250.0),
2706 );
2707 push_window(
2708 &mut windows,
2709 state.windows.diagnostics,
2710 "diagnostics",
2711 "Diagnostics",
2712 UiSize::new(640.0, 760.0),
2713 );
2714 push_window(
2715 &mut windows,
2716 state.windows.trees,
2717 "trees",
2718 "Trees",
2719 UiSize::new(430.0, 390.0),
2720 );
2721 push_window(
2722 &mut windows,
2723 state.windows.layout_widgets,
2724 "layout_widgets",
2725 "Layout widgets",
2726 UiSize::new(wide.min(560.0), 400.0),
2727 );
2728 push_window(
2729 &mut windows,
2730 state.windows.containers,
2731 "containers",
2732 "Containers",
2733 UiSize::new(560.0, 640.0),
2734 );
2735 push_window(
2736 &mut windows,
2737 state.windows.forms,
2738 "forms",
2739 "Forms",
2740 UiSize::new(520.0, 620.0),
2741 );
2742 push_window(
2743 &mut windows,
2744 state.windows.overlays,
2745 "overlays",
2746 "Overlays",
2747 UiSize::new(560.0, 560.0),
2748 );
2749 push_window(
2750 &mut windows,
2751 state.windows.drag_drop,
2752 "drag_drop",
2753 "Drag and drop",
2754 UiSize::new(500.0, 460.0),
2755 );
2756 push_window(
2757 &mut windows,
2758 state.windows.media,
2759 "media",
2760 "Media",
2761 UiSize::new(520.0, 430.0),
2762 );
2763 push_window(
2764 &mut windows,
2765 state.windows.timeline,
2766 "timeline",
2767 "Timeline",
2768 UiSize::new(600.0, 120.0),
2769 );
2770 push_window(
2771 &mut windows,
2772 state.windows.toasts,
2773 "toasts",
2774 "Toasts",
2775 UiSize::new(320.0, 270.0),
2776 );
2777 push_window(
2778 &mut windows,
2779 state.windows.popup_panel,
2780 "popup_panel",
2781 "Popup panel",
2782 UiSize::new(360.0, 200.0),
2783 );
2784 push_window(
2785 &mut windows,
2786 state.windows.canvas,
2787 "canvas",
2788 "Canvas",
2789 UiSize::new(560.0, 390.0),
2790 );
2791 push_window(
2792 &mut windows,
2793 state.windows.styling,
2794 "styling",
2795 "Styling",
2796 UiSize::new(540.0, 440.0),
2797 );
2798 for window in &mut windows {
2799 window.drag_action = Some(WidgetActionBinding::action(format!(
2800 "window.drag.{}",
2801 window.id
2802 )));
2803 window.collapse_action = Some(WidgetActionBinding::action(format!(
2804 "window.collapse.{}",
2805 window.id
2806 )));
2807 window.resize_action = Some(WidgetActionBinding::action(format!(
2808 "window.resize.{}",
2809 window.id
2810 )));
2811 state
2812 .desktop
2813 .apply_to_descriptor(window, window_defaults(window.id.as_str()));
2814 }
2815 windows
2816}pub fn command(id: impl Into<CommandId>) -> Self
Sourcepub const fn action_id(&self) -> Option<&WidgetActionId>
pub const fn action_id(&self) -> Option<&WidgetActionId>
Examples found in repository?
More examples
examples/simple_form.rs (line 35)
34 fn update(&mut self, action: WidgetAction) {
35 let Some(action_id) = action.binding.action_id().map(|id| id.as_str()) else {
36 return;
37 };
38 match action_id {
39 "form.name.edit" => apply_text_edit(&mut self.name, &action.kind),
40 "form.email.edit" => apply_text_edit(&mut self.email, &action.kind),
41 "form.submit" => {
42 self.submitted = format!("Submitted {} <{}>", self.name.text(), self.email.text());
43 }
44 _ => {}
45 }
46 }examples/command_palette_hotkeys.rs (line 35)
34 fn update(&mut self, action: WidgetAction) {
35 let Some(action_id) = action.binding.action_id().map(|id| id.as_str()) else {
36 return;
37 };
38 let items = command_items();
39 if action_id == "commands.search" {
40 if let WidgetActionKind::TextEdit(edit) = &action.kind {
41 if edit.local_position.is_none() {
42 if let Some(selection) = self.palette.handle_event(&items, &edit.event).selected
43 {
44 self.last_command = selection.id;
45 }
46 }
47 }
48 } else if let Some(command) = action_id.strip_prefix("commands.item.") {
49 self.last_command = command.to_string();
50 }
51 }pub const fn command_id(&self) -> Option<&CommandId>
Trait Implementations§
Source§impl Clone for WidgetActionBinding
impl Clone for WidgetActionBinding
Source§fn clone(&self) -> WidgetActionBinding
fn clone(&self) -> WidgetActionBinding
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for WidgetActionBinding
impl Debug for WidgetActionBinding
Source§impl From<&str> for WidgetActionBinding
impl From<&str> for WidgetActionBinding
Source§impl From<CommandId> for WidgetActionBinding
impl From<CommandId> for WidgetActionBinding
Source§impl From<String> for WidgetActionBinding
impl From<String> for WidgetActionBinding
Source§impl From<WidgetActionId> for WidgetActionBinding
impl From<WidgetActionId> for WidgetActionBinding
Source§fn from(value: WidgetActionId) -> Self
fn from(value: WidgetActionId) -> Self
Converts to this type from the input type.
Source§impl Hash for WidgetActionBinding
impl Hash for WidgetActionBinding
Source§impl PartialEq for WidgetActionBinding
impl PartialEq for WidgetActionBinding
Source§fn eq(&self, other: &WidgetActionBinding) -> bool
fn eq(&self, other: &WidgetActionBinding) -> bool
Tests for
self and other values to be equal, and is used by ==.impl Eq for WidgetActionBinding
impl StructuralPartialEq for WidgetActionBinding
Auto Trait Implementations§
impl Freeze for WidgetActionBinding
impl RefUnwindSafe for WidgetActionBinding
impl Send for WidgetActionBinding
impl Sync for WidgetActionBinding
impl Unpin for WidgetActionBinding
impl UnsafeUnpin for WidgetActionBinding
impl UnwindSafe for WidgetActionBinding
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.