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 4449-4452)
4215fn showcase_window_descriptors(
4216    state: &ShowcaseState,
4217    desktop_state: &ext_widgets::FloatingDesktopState,
4218    desktop_size: UiSize,
4219) -> Vec<ext_widgets::FloatingWindowDescriptor> {
4220    let wide = (desktop_size.width - 36.0).clamp(320.0, 720.0);
4221    let medium = (desktop_size.width - 36.0).clamp(300.0, 604.0);
4222    let buttons_width = medium.min(620.0);
4223    let mut windows = Vec::new();
4224    push_window(
4225        &mut windows,
4226        state.windows.labels,
4227        "labels",
4228        "Labels",
4229        UiSize::new(380.0, 460.0),
4230    );
4231    push_window(
4232        &mut windows,
4233        state.windows.buttons,
4234        "buttons",
4235        "Buttons",
4236        UiSize::new(buttons_width, 220.0),
4237    );
4238    push_window(
4239        &mut windows,
4240        state.windows.checkbox,
4241        "checkbox",
4242        "Checkbox",
4243        UiSize::new(250.0, 72.0),
4244    );
4245    push_window(
4246        &mut windows,
4247        state.windows.toggles,
4248        "toggles",
4249        "Radio and toggles",
4250        UiSize::new(360.0, 320.0),
4251    );
4252    push_window(
4253        &mut windows,
4254        state.windows.slider,
4255        "slider",
4256        "Slider",
4257        UiSize::new(430.0, 560.0),
4258    );
4259    push_window(
4260        &mut windows,
4261        state.windows.numeric,
4262        "numeric",
4263        "Numeric input",
4264        UiSize::new(360.0, 180.0),
4265    );
4266    push_window(
4267        &mut windows,
4268        state.windows.text_input,
4269        "text_input",
4270        "Text input",
4271        UiSize::new(520.0, 560.0),
4272    );
4273    push_window(
4274        &mut windows,
4275        state.windows.selection,
4276        "selection",
4277        "Select controls",
4278        UiSize::new(300.0, 430.0),
4279    );
4280    push_window(
4281        &mut windows,
4282        state.windows.menus,
4283        "menus",
4284        "Menu controls",
4285        UiSize::new(wide, 520.0),
4286    );
4287    push_window(
4288        &mut windows,
4289        state.windows.command_palette,
4290        "command_palette",
4291        "Command palette",
4292        UiSize::new(280.0, 130.0),
4293    );
4294    push_window(
4295        &mut windows,
4296        state.windows.date_picker,
4297        "date_picker",
4298        "Date picker",
4299        UiSize::new(430.0, 390.0),
4300    );
4301    push_window(
4302        &mut windows,
4303        state.windows.color_picker,
4304        "color_picker",
4305        "Color picker",
4306        UiSize::new(340.0, 390.0),
4307    );
4308    push_window(
4309        &mut windows,
4310        state.windows.progress,
4311        "progress",
4312        "Progress indicator",
4313        UiSize::new(500.0, 168.0),
4314    );
4315    push_window(
4316        &mut windows,
4317        state.windows.animation,
4318        "animation",
4319        "Animation",
4320        UiSize::new(520.0, 430.0),
4321    );
4322    push_window(
4323        &mut windows,
4324        state.windows.easing,
4325        "easing",
4326        "Easing",
4327        UiSize::new(520.0, 450.0),
4328    );
4329    push_window(
4330        &mut windows,
4331        state.windows.lists_tables,
4332        "lists_tables",
4333        "Lists and tables",
4334        UiSize::new(600.0, 500.0),
4335    );
4336    push_window(
4337        &mut windows,
4338        state.windows.property_inspector,
4339        "property_inspector",
4340        "Property inspector",
4341        UiSize::new(330.0, 250.0),
4342    );
4343    push_window(
4344        &mut windows,
4345        state.windows.diagnostics,
4346        "diagnostics",
4347        "Diagnostics",
4348        UiSize::new(640.0, 760.0),
4349    );
4350    push_window(
4351        &mut windows,
4352        state.windows.trees,
4353        "trees",
4354        "Trees",
4355        UiSize::new(430.0, 390.0),
4356    );
4357    push_window(
4358        &mut windows,
4359        state.windows.layout_widgets,
4360        "layout_widgets",
4361        "Layout widgets",
4362        UiSize::new(wide.min(700.0), 430.0),
4363    );
4364    push_window(
4365        &mut windows,
4366        state.windows.containers,
4367        "containers",
4368        "Containers",
4369        UiSize::new(380.0, 520.0),
4370    );
4371    push_window(
4372        &mut windows,
4373        state.windows.panels,
4374        "panels",
4375        "Panels",
4376        UiSize::new(460.0, 280.0),
4377    );
4378    push_window(
4379        &mut windows,
4380        state.windows.forms,
4381        "forms",
4382        "Forms",
4383        UiSize::new(520.0, 620.0),
4384    );
4385    push_window(
4386        &mut windows,
4387        state.windows.overlays,
4388        "overlays",
4389        "Overlays",
4390        UiSize::new(620.0, 680.0),
4391    );
4392    push_window(
4393        &mut windows,
4394        state.windows.drag_drop,
4395        "drag_drop",
4396        "Drag and drop",
4397        UiSize::new(500.0, 460.0),
4398    );
4399    push_window(
4400        &mut windows,
4401        state.windows.media,
4402        "media",
4403        "Media",
4404        UiSize::new(520.0, 430.0),
4405    );
4406    push_window(
4407        &mut windows,
4408        state.windows.shaders,
4409        "shaders",
4410        "Shader effects",
4411        UiSize::new(500.0, 410.0),
4412    );
4413    push_window(
4414        &mut windows,
4415        state.windows.shader_lab,
4416        "shader_lab",
4417        "Shader lab",
4418        UiSize::new(1000.0, 700.0),
4419    );
4420    push_window(
4421        &mut windows,
4422        state.windows.timeline,
4423        "timeline",
4424        "Timeline",
4425        UiSize::new(600.0, 120.0),
4426    );
4427    push_window(
4428        &mut windows,
4429        state.windows.canvas,
4430        "canvas",
4431        "Canvas",
4432        UiSize::new(760.0, 500.0),
4433    );
4434    push_window(
4435        &mut windows,
4436        state.windows.theme,
4437        "theme",
4438        "Theme",
4439        UiSize::new(430.0, 360.0),
4440    );
4441    push_window(
4442        &mut windows,
4443        state.windows.styling,
4444        "styling",
4445        "Styling",
4446        UiSize::new(540.0, 440.0),
4447    );
4448    for window in &mut windows {
4449        window.drag_action = Some(WidgetActionBinding::action(format!(
4450            "window.drag.{}",
4451            window.id
4452        )));
4453        window.collapse_action = Some(WidgetActionBinding::action(format!(
4454            "window.collapse.{}",
4455            window.id
4456        )));
4457        window.resize_action = Some(WidgetActionBinding::action(format!(
4458            "window.resize.{}",
4459            window.id
4460        )));
4461        desktop_state.apply_to_descriptor(window, window_defaults(window.id.as_str()));
4462    }
4463    windows
4464}
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 Eq for WidgetActionBinding

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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 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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

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

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> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

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

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