Skip to main content

WidgetActionBinding

Enum WidgetActionBinding 

Source
pub enum WidgetActionBinding {
    Action(WidgetActionId),
    Command(CommandId),
}

Variants§

Implementations§

Source§

impl WidgetActionBinding

Source

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}
Source

pub fn command(id: impl Into<CommandId>) -> Self

Source

pub const fn action_id(&self) -> Option<&WidgetActionId>

Examples found in repository?
examples/animation_state_machine.rs (line 30)
27    fn update(&mut self, action: WidgetAction) {
28        if action
29            .binding
30            .action_id()
31            .is_some_and(|id| id.as_str() == "animation.toggle")
32        {
33            self.open = !self.open;
34        }
35    }
More examples
Hide additional examples
examples/canvas_app.rs (line 28)
25    fn update(&mut self, action: WidgetAction) {
26        if action
27            .binding
28            .action_id()
29            .is_some_and(|id| id.as_str() == "runtime.tick")
30        {
31            self.phase = (self.phase + 0.01) % 1.0;
32        }
33    }
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    }
Source

pub const fn command_id(&self) -> Option<&CommandId>

Trait Implementations§

Source§

impl Clone for WidgetActionBinding

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl Debug for WidgetActionBinding

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&str> for WidgetActionBinding

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<CommandId> for WidgetActionBinding

Source§

fn from(value: CommandId) -> Self

Converts to this type from the input type.
Source§

impl From<String> for WidgetActionBinding

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl From<WidgetActionId> for WidgetActionBinding

Source§

fn from(value: WidgetActionId) -> Self

Converts to this type from the input type.
Source§

impl Hash for WidgetActionBinding

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for WidgetActionBinding

Source§

fn eq(&self, other: &WidgetActionBinding) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for WidgetActionBinding

Source§

impl StructuralPartialEq for WidgetActionBinding

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

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>

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)

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)

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
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,