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§
Sourcefn anim<F: Fn(&mut Context, f32) + 'static + Clone>(
self,
func: F,
) -> AnimView<Self, F>
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?
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}Sourcefn background<BG: View>(self, background: BG) -> Background<Self, BG>
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?
More examples
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}Sourcefn command<F: Fn(&mut Context) + 'static>(
self,
name: &str,
key: Option<HotKey>,
f: F,
) -> Command<Self, F>
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?
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}Sourcefn command_group<T: CommandTuple>(self, cmds: T) -> CommandGroup<Self, T>
fn command_group<T: CommandTuple>(self, cmds: T) -> CommandGroup<Self, T>
Adds a group of menu commands.
Examples found in repository?
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}Sourcefn drag<F: Fn(&mut Context, LocalOffset, GestureState, Option<MouseButton>) + 'static>(
self,
f: F,
) -> Drag<Self, F>
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?
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
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}Sourcefn 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 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.
Sourcefn hover<F: Fn(&mut Context, bool) + 'static>(self, f: F) -> Hover<Self, F>
fn hover<F: Fn(&mut Context, bool) + 'static>(self, f: F) -> Hover<Self, F>
Calls a function in response to a mouse hovering.
Sourcefn env<E: Clone + 'static>(self, value: E) -> SetenvView<Self, E>
fn env<E: Clone + 'static>(self, value: E) -> SetenvView<Self, E>
Add an environment value.
Sourcefn fullscreen(self) -> FullscreenView<Self>
fn fullscreen(self) -> FullscreenView<Self>
Make the window full screen.
Sourcefn geom<F: Fn(&mut Context, LocalSize, LocalToWorld) + 'static>(
self,
f: F,
) -> Geom<Self, F>
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.
Sourcefn key<F: Fn(&mut Context, Key) + 'static>(self, f: F) -> KeyView<Self, F>
fn key<F: Fn(&mut Context, Key) + 'static>(self, f: F) -> KeyView<Self, F>
Responds to keyboard events
Examples found in repository?
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}Sourcefn offset<Off: Into<LocalOffset>>(self, offset: Off) -> Offset<Self>
fn offset<Off: Into<LocalOffset>>(self, offset: Off) -> Offset<Self>
Applies an offset to the view in local space.
Examples found in repository?
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
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}Sourcefn padding(self, param: impl Into<PaddingParam>) -> Padding<Self>
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?
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
Sourcefn size<Sz: Into<LocalSize>>(self, size: Sz) -> Size<Self>
fn size<Sz: Into<LocalSize>>(self, size: Sz) -> Size<Self>
Constrains the size of a view.
Examples found in repository?
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}Sourcefn tap<A: 'static, F: Fn(&mut Context) -> A + 'static>(
self,
f: F,
) -> Tap<Self, F>
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?
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
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}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}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}Sourcefn tap_a<A: 'static>(self, action: A) -> TapA<Self, A>
fn tap_a<A: 'static>(self, action: A) -> TapA<Self, A>
Version of tap which takes an action type instead
of a function.
Sourcefn window_title(self, title: &str) -> TitleView<Self>
fn window_title(self, title: &str) -> TitleView<Self>
Specify the title of the window.
Examples found in repository?
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}Sourcefn handle<A: 'static, F: Fn(&mut Context, &A) + 'static>(
self,
handler: F,
) -> Handle<Self, F, A>
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?
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}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.