Trait rui::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)
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
fn main() {
    rui(hstack((
        circle()
            .color(RED_HIGHLIGHT.alpha(0.8))
            .tap(|_cx| println!("tapped circle"))
            .padding(Auto),
        state(LocalOffset::zero, move |off, _| {
            // target offset
            state(LocalOffset::zero, move |anim_off, cx| {
                // animated offset
                rectangle()
                    .corner_radius(5.0)
                    .color(AZURE_HIGHLIGHT.alpha(0.8))
                    .offset(cx[anim_off])
                    .drag(move |cx, delta, state, _| {
                        cx[off] += delta;
                        cx[anim_off] = cx[off];
                        if state == GestureState::Ended {
                            cx[off] = LocalOffset::zero();
                        }
                    })
                    .anim(move |cx, _dt| {
                        let mut v = cx[anim_off];
                        if anim_to(&mut v, cx[off]) {
                            cx[anim_off] = v;
                        }
                    })
                    .padding(Auto)
            })
        }),
    )));
}
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)
3
4
5
6
7
fn main() {
    rui("this is a test"
        .padding(Auto)
        .background(rectangle().corner_radius(5.0).color(AZURE_HIGHLIGHT)));
}
More examples
Hide additional examples
examples/text_editor.rs (lines 10-14)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
fn main() {
    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.";
    rui(vstack((
        state(
            move || lorem.to_string(),
            |state, _| text_editor(state).padding(Auto),
        )
        .background(
            rectangle()
                .color(BUTTON_BACKGROUND_COLOR)
                .corner_radius(5.0),
        )
        .padding(Auto),
        state(
            move || lorem.to_string(),
            |state, _| text_editor(state).padding(Auto),
        )
        .background(
            rectangle()
                .color(BUTTON_BACKGROUND_COLOR)
                .corner_radius(5.0),
        )
        .padding(Auto),
    )));
}
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)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
fn main() {
    rui(hstack((
        circle()
            .color(RED_HIGHLIGHT)
            .padding(Auto)
            .command("File:New", Some(HotKey::KeyN), |_| println!("new")),
        rectangle()
            .corner_radius(5.0)
            .color(AZURE_HIGHLIGHT)
            .padding(Auto)
            .command("Edit:Two", None, |_| println!("two"))
            .command("Edit:Three", None, |_| println!("three"))
            .command("Custom:Submenu:One", None, |_| println!("submenu one"))
            .command("Custom:Submenu:Two", None, |_| println!("submenu two"))
            .command_group((command("Custom 2:Four")
                .action(|| println!("four"))
                .hotkey(HotKey::KeyF),)),
    )));
}
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)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
fn main() {
    rui(hstack((
        circle()
            .color(RED_HIGHLIGHT)
            .padding(Auto)
            .command("File:New", Some(HotKey::KeyN), |_| println!("new")),
        rectangle()
            .corner_radius(5.0)
            .color(AZURE_HIGHLIGHT)
            .padding(Auto)
            .command("Edit:Two", None, |_| println!("two"))
            .command("Edit:Three", None, |_| println!("three"))
            .command("Custom:Submenu:One", None, |_| println!("submenu one"))
            .command("Custom:Submenu:Two", None, |_| println!("submenu two"))
            .command_group((command("Custom 2:Four")
                .action(|| println!("four"))
                .hotkey(HotKey::KeyF),)),
    )));
}
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)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
fn main() {
    rui(hstack((
        zstack((
            circle()
                .color(RED_HIGHLIGHT.alpha(0.8))
                .tap(|cx| println!("tapped circle, key modifiers state: {:?}", cx.key_mods))
                .padding(Auto),
            "Tap (inside circle)",
        )),
        zstack((
            rectangle()
                .corner_radius(5.0)
                .color(AZURE_HIGHLIGHT_BACKGROUND)
                .drag(|cx, delta, _state, _mouse_button| {
                    println!(
                        "dragging: {:?}, key modifiers state: {:?}",
                        delta, cx.key_mods
                    )
                })
                .padding(Auto),
            "Drag (inside rectangle)".padding(Auto),
        )),
        "Handle key pressed"
            .key(|cx, key| println!("key: {:?}, key modifiers state: {:?}", key, cx.key_mods))
            .padding(Auto),
    )));
}
More examples
Hide additional examples
examples/gestures.rs (lines 30-36)
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
fn main() {
    rui(hstack((
        circle()
            .color(RED_HIGHLIGHT.alpha(0.8))
            .tap(|_cx| println!("tapped circle"))
            .padding(Auto),
        state(LocalOffset::zero, move |off, _| {
            // target offset
            state(LocalOffset::zero, move |anim_off, cx| {
                // animated offset
                rectangle()
                    .corner_radius(5.0)
                    .color(AZURE_HIGHLIGHT.alpha(0.8))
                    .offset(cx[anim_off])
                    .drag(move |cx, delta, state, _| {
                        cx[off] += delta;
                        cx[anim_off] = cx[off];
                        if state == GestureState::Ended {
                            cx[off] = LocalOffset::zero();
                        }
                    })
                    .anim(move |cx, _dt| {
                        let mut v = cx[anim_off];
                        if anim_to(&mut v, cx[off]) {
                            cx[anim_off] = v;
                        }
                    })
                    .padding(Auto)
            })
        }),
    )));
}
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)
24
25
26
27
28
29
fn main() {
    rui(vstack((
        my_control(),
        my_control().env(MyControlType::Agro),
    )))
}
source

fn flex(self) -> Flex<Self>

Indicates that this item can expand within a stack.

Examples found in repository?
examples/basic.rs (line 6)
3
4
5
6
7
8
9
10
fn main() {
    rui(vstack((
        "This is a test.",
        rectangle().flex(),
        "This is another test.",
        rectangle().flex(),
    )));
}
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)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
fn main() {
    rui(hstack((
        zstack((
            circle()
                .color(RED_HIGHLIGHT.alpha(0.8))
                .tap(|cx| println!("tapped circle, key modifiers state: {:?}", cx.key_mods))
                .padding(Auto),
            "Tap (inside circle)",
        )),
        zstack((
            rectangle()
                .corner_radius(5.0)
                .color(AZURE_HIGHLIGHT_BACKGROUND)
                .drag(|cx, delta, _state, _mouse_button| {
                    println!(
                        "dragging: {:?}, key modifiers state: {:?}",
                        delta, cx.key_mods
                    )
                })
                .padding(Auto),
            "Drag (inside rectangle)".padding(Auto),
        )),
        "Handle key pressed"
            .key(|cx, key| println!("key: {:?}, key modifiers state: {:?}", key, cx.key_mods))
            .padding(Auto),
    )));
}
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)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
fn digit_button(title: &str, state: StateHandle<String>) -> impl View {
    let t = String::from(title);
    zstack((
        rectangle()
            .corner_radius(10.0)
            .color(RED_HIGHLIGHT)
            .tap(move |cx| cx[state].push_str(&t)),
        text(title).color(BLACK).offset([10.0, 10.0]),
    ))
    .padding(Auto)
}

fn calc_button(title: &str, callback: impl Fn(&mut Context) + 'static) -> impl View {
    zstack((
        rectangle()
            .corner_radius(10.0)
            .color(GREEN_HIGHLIGHT)
            .tap(callback),
        text(title).color(BLACK).offset([10.0, 10.0]),
    ))
    .padding(Auto)
}
More examples
Hide additional examples
examples/gestures.rs (line 29)
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
fn main() {
    rui(hstack((
        circle()
            .color(RED_HIGHLIGHT.alpha(0.8))
            .tap(|_cx| println!("tapped circle"))
            .padding(Auto),
        state(LocalOffset::zero, move |off, _| {
            // target offset
            state(LocalOffset::zero, move |anim_off, cx| {
                // animated offset
                rectangle()
                    .corner_radius(5.0)
                    .color(AZURE_HIGHLIGHT.alpha(0.8))
                    .offset(cx[anim_off])
                    .drag(move |cx, delta, state, _| {
                        cx[off] += delta;
                        cx[anim_off] = cx[off];
                        if state == GestureState::Ended {
                            cx[off] = LocalOffset::zero();
                        }
                    })
                    .anim(move |cx, _dt| {
                        let mut v = cx[anim_off];
                        if anim_to(&mut v, cx[off]) {
                            cx[anim_off] = v;
                        }
                    })
                    .padding(Auto)
            })
        }),
    )));
}
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)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
fn caption(s: &'static str) -> impl View {
    s.font_size(12).padding(Auto)
}

fn knob_example() -> impl View {
    hstack((
        caption("knob"),
        state(|| 0.5, |s, _| knob(s).size([30.0, 30.0]).padding(Auto)),
    ))
}

fn toggle_example() -> impl View {
    hstack((
        caption("toggle"),
        state(|| false, |s, _| toggle(s).size([30.0, 30.0]).padding(Auto)),
    ))
}

fn text_editor_example() -> impl View {
    hstack((
        caption("text_editor"),
        state(
            || "edit me".to_string(),
            |txt, _| text_editor(txt).padding(Auto),
        ),
    ))
}

fn main() {
    rui(vstack((
        "rui widget gallery".padding(10.0),
        button_example(),
        slider_example(),
        knob_example(),
        toggle_example(),
        text_editor_example(),
    ))
    .padding(Auto)
    .window_title("rui widget gallery"))
}
More examples
Hide additional examples
examples/custom_modifier.rs (line 42)
40
41
42
43
44
45
fn main() {
    rui(vstack((
        my_control().padding(Auto),
        my_control().agro().padding(Auto),
    )))
}
examples/zstack.rs (line 6)
3
4
5
6
7
8
fn main() {
    rui(zstack((
        "This is a test.",
        circle().color(RED_HIGHLIGHT).padding(Auto),
    )));
}
examples/nested.rs (line 7)
3
4
5
6
7
8
fn my_rectangle() -> impl View {
    rectangle()
        .corner_radius(5.0)
        .color(AZURE_HIGHLIGHT)
        .padding(Auto)
}
examples/background.rs (line 5)
3
4
5
6
7
fn main() {
    rui("this is a test"
        .padding(Auto)
        .background(rectangle().corner_radius(5.0).color(AZURE_HIGHLIGHT)));
}
examples/any_view.rs (line 10)
3
4
5
6
7
8
9
10
11
12
fn main() {
    rui(list(vec![7, 42], |i| {
        if *i == 7 {
            any_view(circle())
        } else {
            any_view(rectangle())
        }
        .padding(Auto)
    }));
}
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)
18
19
20
21
22
23
24
25
26
27
28
29
30
fn knob_example() -> impl View {
    hstack((
        caption("knob"),
        state(|| 0.5, |s, _| knob(s).size([30.0, 30.0]).padding(Auto)),
    ))
}

fn toggle_example() -> impl View {
    hstack((
        caption("toggle"),
        state(|| false, |s, _| toggle(s).size([30.0, 30.0]).padding(Auto)),
    ))
}
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)
5
6
7
8
9
10
11
12
13
14
15
16
fn main() {
    rui(vstack((
        rectangle()
            .tap(|_| {
                println!("rect tapped");
                MyAction {}
            })
            .padding(Auto),
        text("tap the rectangle to send an action"),
    ))
    .handle(|_, _: &MyAction| println!("action received")));
}
More examples
Hide additional examples
examples/calc.rs (line 11)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
fn digit_button(title: &str, state: StateHandle<String>) -> impl View {
    let t = String::from(title);
    zstack((
        rectangle()
            .corner_radius(10.0)
            .color(RED_HIGHLIGHT)
            .tap(move |cx| cx[state].push_str(&t)),
        text(title).color(BLACK).offset([10.0, 10.0]),
    ))
    .padding(Auto)
}

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

fn clip(self) -> Clip<Self>

Clip to bounds.

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

Implementors§

source§

impl<V: View> Modifiers for V