Modifiers

Trait Modifiers 

Source
pub trait Modifiers: View + Sized {
Show 21 methods // Provided methods fn anim<F: Fn(&mut Context, f32) + 'static + Clone>( self, func: F, ) -> AnimView<Self, F> { ... } fn background<BG: View>(self, background: BG) -> Background<Self, BG> { ... } fn command<F: Fn(&mut Context) + 'static>( self, name: &str, key: Option<HotKey>, f: F, ) -> Command<Self, F> { ... } fn command_group<T: CommandTuple>(self, cmds: T) -> CommandGroup<Self, T> { ... } fn drag<F: Fn(&mut Context, LocalOffset, GestureState, Option<MouseButton>) + 'static>( self, f: F, ) -> Drag<Self, F> { ... } fn drag_s<T: 'static, B: Binding<T>, F: Fn(&mut T, LocalOffset, GestureState, Option<MouseButton>) + 'static>( self, s: B, f: F, ) -> DragS<Self, F, B, T> { ... } fn hover<F: Fn(&mut Context, bool) + 'static>(self, f: F) -> Hover<Self, F> { ... } fn env<E: Clone + 'static>(self, value: E) -> SetenvView<Self, E> { ... } fn flex(self) -> Flex<Self> { ... } fn fullscreen(self) -> FullscreenView<Self> { ... } fn geom<F: Fn(&mut Context, LocalSize, LocalToWorld) + 'static>( self, f: F, ) -> Geom<Self, F> { ... } fn key<F: Fn(&mut Context, Key) + 'static>(self, f: F) -> KeyView<Self, F> { ... } fn offset<Off: Into<LocalOffset>>(self, offset: Off) -> Offset<Self> { ... } fn padding(self, param: impl Into<PaddingParam>) -> Padding<Self> { ... } fn role(self, role: Role) -> RoleView<Self> { ... } fn size<Sz: Into<LocalSize>>(self, size: Sz) -> Size<Self> { ... } fn tap<A: 'static, F: Fn(&mut Context) -> A + 'static>( self, f: F, ) -> Tap<Self, F> { ... } fn tap_a<A: 'static>(self, action: A) -> TapA<Self, A> { ... } fn window_title(self, title: &str) -> TitleView<Self> { ... } fn handle<A: 'static, F: Fn(&mut Context, &A) + 'static>( self, handler: F, ) -> Handle<Self, F, A> { ... } fn clip(self) -> Clip<Self> { ... }
}
Expand description

Modifiers common to all views.

Provided Methods§

Source

fn anim<F: Fn(&mut Context, f32) + 'static + Clone>( self, func: F, ) -> AnimView<Self, F>

Calls a closure after rendering with context and delta time.

Examples found in repository?
examples/gestures.rs (lines 37-42)
16fn main() {
17    rui(hstack((
18        circle()
19            .color(RED_HIGHLIGHT.alpha(0.8))
20            .tap(|_cx| println!("tapped circle"))
21            .padding(Auto),
22        state(LocalOffset::zero, move |off, _| {
23            // target offset
24            state(LocalOffset::zero, move |anim_off, cx| {
25                // animated offset
26                rectangle()
27                    .corner_radius(5.0)
28                    .color(AZURE_HIGHLIGHT.alpha(0.8))
29                    .offset(cx[anim_off])
30                    .drag(move |cx, delta, state, _| {
31                        cx[off] += delta;
32                        cx[anim_off] = cx[off];
33                        if state == GestureState::Ended {
34                            cx[off] = LocalOffset::zero();
35                        }
36                    })
37                    .anim(move |cx, _dt| {
38                        let mut v = cx[anim_off];
39                        if anim_to(&mut v, cx[off]) {
40                            cx[anim_off] = v;
41                        }
42                    })
43                    .padding(Auto)
44            })
45        }),
46    )));
47}
Source

fn background<BG: View>(self, background: BG) -> Background<Self, BG>

Puts a view behind another. The background view inherits the size of the view.

Examples found in repository?
examples/background.rs (line 6)
3fn main() {
4    rui("this is a test"
5        .padding(Auto)
6        .background(rectangle().corner_radius(5.0).color(AZURE_HIGHLIGHT)));
7}
More examples
Hide additional examples
examples/text_editor.rs (lines 10-14)
3fn main() {
4    let lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
5    rui(vstack((
6        state(
7            move || lorem.to_string(),
8            |state, _| text_editor(state).padding(Auto),
9        )
10        .background(
11            rectangle()
12                .color(BUTTON_BACKGROUND_COLOR)
13                .corner_radius(5.0),
14        )
15        .padding(Auto),
16        state(
17            move || lorem.to_string(),
18            |state, _| text_editor(state).padding(Auto),
19        )
20        .background(
21            rectangle()
22                .color(BUTTON_BACKGROUND_COLOR)
23                .corner_radius(5.0),
24        )
25        .padding(Auto),
26    )));
27}
Source

fn command<F: Fn(&mut Context) + 'static>( self, name: &str, key: Option<HotKey>, f: F, ) -> Command<Self, F>

Adds a menu command.

Examples found in repository?
examples/menu.rs (line 11)
6fn main() {
7    rui(hstack((
8        circle()
9            .color(RED_HIGHLIGHT)
10            .padding(Auto)
11            .command("File:New", Some(HotKey::KeyN), |_| println!("new")),
12        rectangle()
13            .corner_radius(5.0)
14            .color(AZURE_HIGHLIGHT)
15            .padding(Auto)
16            .command("Edit:Two", None, |_| println!("two"))
17            .command("Edit:Three", None, |_| println!("three"))
18            .command("Custom:Submenu:One", None, |_| println!("submenu one"))
19            .command("Custom:Submenu:Two", None, |_| println!("submenu two"))
20            .command_group((command("Custom 2:Four")
21                .action(|| println!("four"))
22                .hotkey(HotKey::KeyF),)),
23    )));
24}
Source

fn command_group<T: CommandTuple>(self, cmds: T) -> CommandGroup<Self, T>

Adds a group of menu commands.

Examples found in repository?
examples/menu.rs (lines 20-22)
6fn main() {
7    rui(hstack((
8        circle()
9            .color(RED_HIGHLIGHT)
10            .padding(Auto)
11            .command("File:New", Some(HotKey::KeyN), |_| println!("new")),
12        rectangle()
13            .corner_radius(5.0)
14            .color(AZURE_HIGHLIGHT)
15            .padding(Auto)
16            .command("Edit:Two", None, |_| println!("two"))
17            .command("Edit:Three", None, |_| println!("three"))
18            .command("Custom:Submenu:One", None, |_| println!("submenu one"))
19            .command("Custom:Submenu:Two", None, |_| println!("submenu two"))
20            .command_group((command("Custom 2:Four")
21                .action(|| println!("four"))
22                .hotkey(HotKey::KeyF),)),
23    )));
24}
Source

fn drag<F: Fn(&mut Context, LocalOffset, GestureState, Option<MouseButton>) + 'static>( self, f: F, ) -> Drag<Self, F>

Calls a function in response to a drag.

Examples found in repository?
examples/key_mods.rs (lines 16-21)
3fn main() {
4    rui(hstack((
5        zstack((
6            circle()
7                .color(RED_HIGHLIGHT.alpha(0.8))
8                .tap(|cx| println!("tapped circle, key modifiers state: {:?}", cx.key_mods))
9                .padding(Auto),
10            "Tap (inside circle)",
11        )),
12        zstack((
13            rectangle()
14                .corner_radius(5.0)
15                .color(AZURE_HIGHLIGHT_BACKGROUND)
16                .drag(|cx, delta, _state, _mouse_button| {
17                    println!(
18                        "dragging: {:?}, key modifiers state: {:?}",
19                        delta, cx.key_mods
20                    )
21                })
22                .padding(Auto),
23            "Drag (inside rectangle)".padding(Auto),
24        )),
25        "Handle key pressed"
26            .key(|cx, key| println!("key: {:?}, key modifiers state: {:?}", key, cx.key_mods))
27            .padding(Auto),
28    )));
29}
More examples
Hide additional examples
examples/gestures.rs (lines 30-36)
16fn main() {
17    rui(hstack((
18        circle()
19            .color(RED_HIGHLIGHT.alpha(0.8))
20            .tap(|_cx| println!("tapped circle"))
21            .padding(Auto),
22        state(LocalOffset::zero, move |off, _| {
23            // target offset
24            state(LocalOffset::zero, move |anim_off, cx| {
25                // animated offset
26                rectangle()
27                    .corner_radius(5.0)
28                    .color(AZURE_HIGHLIGHT.alpha(0.8))
29                    .offset(cx[anim_off])
30                    .drag(move |cx, delta, state, _| {
31                        cx[off] += delta;
32                        cx[anim_off] = cx[off];
33                        if state == GestureState::Ended {
34                            cx[off] = LocalOffset::zero();
35                        }
36                    })
37                    .anim(move |cx, _dt| {
38                        let mut v = cx[anim_off];
39                        if anim_to(&mut v, cx[off]) {
40                            cx[anim_off] = v;
41                        }
42                    })
43                    .padding(Auto)
44            })
45        }),
46    )));
47}
Source

fn drag_s<T: 'static, B: Binding<T>, F: Fn(&mut T, LocalOffset, GestureState, Option<MouseButton>) + 'static>( self, s: B, f: F, ) -> DragS<Self, F, B, T>

Calls a function in response to a drag. Version which passes in a binding.

Source

fn hover<F: Fn(&mut Context, bool) + 'static>(self, f: F) -> Hover<Self, F>

Calls a function in response to a mouse hovering.

Source

fn env<E: Clone + 'static>(self, value: E) -> SetenvView<Self, E>

Add an environment value.

Examples found in repository?
examples/env.rs (line 27)
24fn main() {
25    rui(vstack((
26        my_control(),
27        my_control().env(MyControlType::Agro),
28    )))
29}
Source

fn flex(self) -> Flex<Self>

Indicates that this item can expand within a stack.

Examples found in repository?
examples/basic.rs (line 6)
3fn main() {
4    rui(vstack((
5        "This is a test.",
6        rectangle().flex(),
7        "This is another test.",
8        rectangle().flex(),
9    )));
10}
Source

fn fullscreen(self) -> FullscreenView<Self>

Make the window full screen.

Source

fn geom<F: Fn(&mut Context, LocalSize, LocalToWorld) + 'static>( self, f: F, ) -> Geom<Self, F>

Calls a function with the view’s geometry after layout runs. Currently only the view’s size is returned.

Source

fn key<F: Fn(&mut Context, Key) + 'static>(self, f: F) -> KeyView<Self, F>

Responds to keyboard events

Examples found in repository?
examples/key_mods.rs (line 26)
3fn main() {
4    rui(hstack((
5        zstack((
6            circle()
7                .color(RED_HIGHLIGHT.alpha(0.8))
8                .tap(|cx| println!("tapped circle, key modifiers state: {:?}", cx.key_mods))
9                .padding(Auto),
10            "Tap (inside circle)",
11        )),
12        zstack((
13            rectangle()
14                .corner_radius(5.0)
15                .color(AZURE_HIGHLIGHT_BACKGROUND)
16                .drag(|cx, delta, _state, _mouse_button| {
17                    println!(
18                        "dragging: {:?}, key modifiers state: {:?}",
19                        delta, cx.key_mods
20                    )
21                })
22                .padding(Auto),
23            "Drag (inside rectangle)".padding(Auto),
24        )),
25        "Handle key pressed"
26            .key(|cx, key| println!("key: {:?}, key modifiers state: {:?}", key, cx.key_mods))
27            .padding(Auto),
28    )));
29}
Source

fn offset<Off: Into<LocalOffset>>(self, offset: Off) -> Offset<Self>

Applies an offset to the view in local space.

Examples found in repository?
examples/calc.rs (line 12)
5fn digit_button(title: &str, state: StateHandle<String>) -> impl View {
6    let t = String::from(title);
7    zstack((
8        rectangle()
9            .corner_radius(10.0)
10            .color(RED_HIGHLIGHT)
11            .tap(move |cx| cx[state].push_str(&t)),
12        text(title).color(BLACK).offset([10.0, 10.0]),
13    ))
14    .padding(Auto)
15}
16
17fn calc_button(title: &str, callback: impl Fn(&mut Context) + 'static) -> impl View {
18    zstack((
19        rectangle()
20            .corner_radius(10.0)
21            .color(GREEN_HIGHLIGHT)
22            .tap(callback),
23        text(title).color(BLACK).offset([10.0, 10.0]),
24    ))
25    .padding(Auto)
26}
More examples
Hide additional examples
examples/gestures.rs (line 29)
16fn main() {
17    rui(hstack((
18        circle()
19            .color(RED_HIGHLIGHT.alpha(0.8))
20            .tap(|_cx| println!("tapped circle"))
21            .padding(Auto),
22        state(LocalOffset::zero, move |off, _| {
23            // target offset
24            state(LocalOffset::zero, move |anim_off, cx| {
25                // animated offset
26                rectangle()
27                    .corner_radius(5.0)
28                    .color(AZURE_HIGHLIGHT.alpha(0.8))
29                    .offset(cx[anim_off])
30                    .drag(move |cx, delta, state, _| {
31                        cx[off] += delta;
32                        cx[anim_off] = cx[off];
33                        if state == GestureState::Ended {
34                            cx[off] = LocalOffset::zero();
35                        }
36                    })
37                    .anim(move |cx, _dt| {
38                        let mut v = cx[anim_off];
39                        if anim_to(&mut v, cx[off]) {
40                            cx[anim_off] = v;
41                        }
42                    })
43                    .padding(Auto)
44            })
45        }),
46    )));
47}
Source

fn padding(self, param: impl Into<PaddingParam>) -> Padding<Self>

Adds space around a view. Can be either Auto or Px(number_of_pixels)

Examples found in repository?
examples/gallery.rs (line 15)
14fn caption(s: &'static str) -> impl View {
15    s.font_size(12).padding(Auto)
16}
17
18fn knob_example() -> impl View {
19    hstack((
20        caption("knob"),
21        state(|| 0.5, |s, _| knob(s).size([30.0, 30.0]).padding(Auto)),
22    ))
23}
24
25fn toggle_example() -> impl View {
26    hstack((
27        caption("toggle"),
28        state(|| false, |s, _| toggle(s).size([30.0, 30.0]).padding(Auto)),
29    ))
30}
31
32fn text_editor_example() -> impl View {
33    hstack((
34        caption("text_editor"),
35        state(
36            || "edit me".to_string(),
37            |txt, _| text_editor(txt).padding(Auto),
38        ),
39    ))
40}
41
42fn main() {
43    rui(vstack((
44        "rui widget gallery".padding(10.0),
45        button_example(),
46        slider_example(),
47        knob_example(),
48        toggle_example(),
49        text_editor_example(),
50    ))
51    .padding(Auto)
52    .window_title("rui widget gallery"))
53}
More examples
Hide additional examples
examples/custom_modifier.rs (line 42)
40fn main() {
41    rui(vstack((
42        my_control().padding(Auto),
43        my_control().agro().padding(Auto),
44    )))
45}
examples/zstack.rs (line 6)
3fn main() {
4    rui(zstack((
5        "This is a test.",
6        circle().color(RED_HIGHLIGHT).padding(Auto),
7    )));
8}
examples/nested.rs (line 7)
3fn my_rectangle() -> impl View {
4    rectangle()
5        .corner_radius(5.0)
6        .color(AZURE_HIGHLIGHT)
7        .padding(Auto)
8}
examples/background.rs (line 5)
3fn main() {
4    rui("this is a test"
5        .padding(Auto)
6        .background(rectangle().corner_radius(5.0).color(AZURE_HIGHLIGHT)));
7}
examples/any_view.rs (line 10)
3fn main() {
4    rui(list(vec![7, 42], |i| {
5        if *i == 7 {
6            any_view(circle())
7        } else {
8            any_view(rectangle())
9        }
10        .padding(Auto)
11    }));
12}
Source

fn role(self, role: Role) -> RoleView<Self>

Specify an accessiblity role.

Source

fn size<Sz: Into<LocalSize>>(self, size: Sz) -> Size<Self>

Constrains the size of a view.

Examples found in repository?
examples/gallery.rs (line 21)
18fn knob_example() -> impl View {
19    hstack((
20        caption("knob"),
21        state(|| 0.5, |s, _| knob(s).size([30.0, 30.0]).padding(Auto)),
22    ))
23}
24
25fn toggle_example() -> impl View {
26    hstack((
27        caption("toggle"),
28        state(|| false, |s, _| toggle(s).size([30.0, 30.0]).padding(Auto)),
29    ))
30}
Source

fn tap<A: 'static, F: Fn(&mut Context) -> A + 'static>( self, f: F, ) -> Tap<Self, F>

Calls a function in response to a tap.

Examples found in repository?
examples/action.rs (lines 8-11)
5fn main() {
6    rui(vstack((
7        rectangle()
8            .tap(|_| {
9                println!("rect tapped");
10                MyAction {}
11            })
12            .padding(Auto),
13        text("tap the rectangle to send an action"),
14    ))
15    .handle(|_, _: &MyAction| println!("action received")));
16}
More examples
Hide additional examples
examples/calc.rs (line 11)
5fn digit_button(title: &str, state: StateHandle<String>) -> impl View {
6    let t = String::from(title);
7    zstack((
8        rectangle()
9            .corner_radius(10.0)
10            .color(RED_HIGHLIGHT)
11            .tap(move |cx| cx[state].push_str(&t)),
12        text(title).color(BLACK).offset([10.0, 10.0]),
13    ))
14    .padding(Auto)
15}
16
17fn calc_button(title: &str, callback: impl Fn(&mut Context) + 'static) -> impl View {
18    zstack((
19        rectangle()
20            .corner_radius(10.0)
21            .color(GREEN_HIGHLIGHT)
22            .tap(callback),
23        text(title).color(BLACK).offset([10.0, 10.0]),
24    ))
25    .padding(Auto)
26}
examples/key_mods.rs (line 8)
3fn main() {
4    rui(hstack((
5        zstack((
6            circle()
7                .color(RED_HIGHLIGHT.alpha(0.8))
8                .tap(|cx| println!("tapped circle, key modifiers state: {:?}", cx.key_mods))
9                .padding(Auto),
10            "Tap (inside circle)",
11        )),
12        zstack((
13            rectangle()
14                .corner_radius(5.0)
15                .color(AZURE_HIGHLIGHT_BACKGROUND)
16                .drag(|cx, delta, _state, _mouse_button| {
17                    println!(
18                        "dragging: {:?}, key modifiers state: {:?}",
19                        delta, cx.key_mods
20                    )
21                })
22                .padding(Auto),
23            "Drag (inside rectangle)".padding(Auto),
24        )),
25        "Handle key pressed"
26            .key(|cx, key| println!("key: {:?}, key modifiers state: {:?}", key, cx.key_mods))
27            .padding(Auto),
28    )));
29}
examples/gestures.rs (line 20)
16fn main() {
17    rui(hstack((
18        circle()
19            .color(RED_HIGHLIGHT.alpha(0.8))
20            .tap(|_cx| println!("tapped circle"))
21            .padding(Auto),
22        state(LocalOffset::zero, move |off, _| {
23            // target offset
24            state(LocalOffset::zero, move |anim_off, cx| {
25                // animated offset
26                rectangle()
27                    .corner_radius(5.0)
28                    .color(AZURE_HIGHLIGHT.alpha(0.8))
29                    .offset(cx[anim_off])
30                    .drag(move |cx, delta, state, _| {
31                        cx[off] += delta;
32                        cx[anim_off] = cx[off];
33                        if state == GestureState::Ended {
34                            cx[off] = LocalOffset::zero();
35                        }
36                    })
37                    .anim(move |cx, _dt| {
38                        let mut v = cx[anim_off];
39                        if anim_to(&mut v, cx[off]) {
40                            cx[anim_off] = v;
41                        }
42                    })
43                    .padding(Auto)
44            })
45        }),
46    )));
47}
Source

fn tap_a<A: 'static>(self, action: A) -> TapA<Self, A>

Version of tap which takes an action type instead of a function.

Source

fn window_title(self, title: &str) -> TitleView<Self>

Specify the title of the window.

Examples found in repository?
examples/gallery.rs (line 52)
42fn main() {
43    rui(vstack((
44        "rui widget gallery".padding(10.0),
45        button_example(),
46        slider_example(),
47        knob_example(),
48        toggle_example(),
49        text_editor_example(),
50    ))
51    .padding(Auto)
52    .window_title("rui widget gallery"))
53}
Source

fn handle<A: 'static, F: Fn(&mut Context, &A) + 'static>( self, handler: F, ) -> Handle<Self, F, A>

Handle an action from a child view.

Examples found in repository?
examples/action.rs (line 15)
5fn main() {
6    rui(vstack((
7        rectangle()
8            .tap(|_| {
9                println!("rect tapped");
10                MyAction {}
11            })
12            .padding(Auto),
13        text("tap the rectangle to send an action"),
14    ))
15    .handle(|_, _: &MyAction| println!("action received")));
16}
Source

fn clip(self) -> Clip<Self>

Clip to bounds.

Examples found in repository?
examples/clip.rs (line 7)
3fn main() {
4    rui(hstack((
5        text("This text is clipped.")
6            // .offset([0.0, 0.0])
7            .clip(),
8        text("This text isn't clipped."),
9    )))
10}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<V: View> Modifiers for V