pub struct Rectangle { /* private fields */ }
Expand description
Struct for rectangle
.
Implementations§
source§impl Rectangle
impl Rectangle
sourcepub fn color(self, color: Color) -> Rectangle
pub fn color(self, color: Color) -> Rectangle
Sets the fill color for the rectangle.
Examples found in repository?
More examples
examples/calc.rs (line 10)
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/menu.rs (line 14)
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),)),
)));
}
examples/key_mods.rs (line 15)
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),
)));
}
Additional examples can be found in:
sourcepub fn corner_radius(self, radius: f32) -> Rectangle
pub fn corner_radius(self, radius: f32) -> Rectangle
Sets the rectangle’s corner radius.
Examples found in repository?
More examples
examples/calc.rs (line 9)
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/menu.rs (line 13)
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),)),
)));
}
examples/key_mods.rs (line 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 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),
)));
}
Additional examples can be found in:
Trait Implementations§
source§impl View for Rectangle
impl View for Rectangle
source§fn layout(&self, id: ViewId, args: &mut LayoutArgs<'_>) -> LocalSize
fn layout(&self, id: ViewId, args: &mut LayoutArgs<'_>) -> LocalSize
Lays out subviews and return the size of the view. Read more
source§fn hittest(
&self,
id: ViewId,
pt: LocalPoint,
cx: &mut Context
) -> Option<ViewId>
fn hittest( &self, id: ViewId, pt: LocalPoint, cx: &mut Context ) -> Option<ViewId>
Returns the topmost view which the point intersects.
source§fn access(
&self,
_id: ViewId,
_cx: &mut Context,
_nodes: &mut Vec<(NodeId, Node)>
) -> Option<NodeId>
fn access( &self, _id: ViewId, _cx: &mut Context, _nodes: &mut Vec<(NodeId, Node)> ) -> Option<NodeId>
Builds an AccessKit tree. The node ID for the subtree is returned. All generated nodes are accumulated.
source§fn commands(&self, _id: ViewId, _cx: &mut Context, _cmds: &mut Vec<CommandInfo>)
fn commands(&self, _id: ViewId, _cx: &mut Context, _cmds: &mut Vec<CommandInfo>)
Accumulates information about menu bar commands.
source§fn dirty(&self, _id: ViewId, _xform: LocalToWorld, _cx: &mut Context)
fn dirty(&self, _id: ViewId, _xform: LocalToWorld, _cx: &mut Context)
Determines dirty regions which need repainting.
source§fn gc(&self, _id: ViewId, _cx: &mut Context, _map: &mut Vec<ViewId>)
fn gc(&self, _id: ViewId, _cx: &mut Context, _map: &mut Vec<ViewId>)
Gets IDs for state currently in use.
source§fn is_flexible(&self) -> bool
fn is_flexible(&self) -> bool
For detecting flexible sized things in stacks.