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?
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)
})
}),
)));
}
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
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),
)));
}
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?
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),)),
)));
}
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?
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),)),
)));
}
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?
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
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)
})
}),
)));
}
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?
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),
)));
}
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?
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
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)
})
}),
)));
}
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?
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
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?
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)),
))
}
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?
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
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)
}
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),
)));
}
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)
})
}),
)));
}
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?
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"))
}
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?
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")));
}