pub struct Rect {
pub x: f32,
pub y: f32,
pub w: f32,
pub h: f32,
}Expand description
A rectangle: its top left corner and size, in units.
Fields§
§x: f32Left edge.
y: f32Top edge.
w: f32Width.
h: f32Height.
Implementations§
Source§impl Rect
impl Rect
Sourcepub const EVERYTHING: Rect
pub const EVERYTHING: Rect
Larger than anything ever drawn: “no clipping”.
Sourcepub fn right(&self) -> f32
pub fn right(&self) -> f32
Right edge.
Examples found in repository?
More examples
examples/report.rs (line 87)
76fn chart(paper: &mut Paper, r: taut::Rect) {
77 let (sold, back, line, dim) = (Color::rgb(0x2b6cb0), Color::rgb(0xdd6b20), Color::rgb(0xe2e8f0), Color::rgb(0x4a5568));
78 let small = Font::new(12.0);
79 let plot = rect(r.x + 48.0, r.y, r.w - 96.0, r.h - 64.0);
80 let (most, most_back) = (1000.0, 50.0);
81 for step in 0..=5 {
82 let y = plot.bottom() - plot.h * step as f32 / 5.0;
83 paper.rect(rect(plot.x, y, plot.w, 1.0), line);
84 let label = format!("{}", step * 200);
85 let wide = paper.measure(&label, small);
86 paper.text(&label, plot.x - 8.0 - wide, y - 8.0, small, dim);
87 paper.text(&format!("{}", step * 10), plot.right() + 8.0, y - 8.0, small, back);
88 }
89 let slot = plot.w / 12.0;
90 let mut path = Path::new();
91 for (month, name) in MONTHS.iter().enumerate() {
92 let x = plot.x + slot * month as f32;
93 let high = plot.h * SOLD[month] / most;
94 paper.rounded(rect(x + slot * 0.2, plot.bottom() - high, slot * 0.6, high), 3.0, sold);
95 let wide = paper.measure(name, small);
96 paper.text(name, x + (slot - wide) / 2.0, plot.bottom() + 8.0, small, dim);
97 let y = plot.bottom() - plot.h * BACK[month] / most_back;
98 match month {
99 0 => _ = path.move_to(x + slot / 2.0, y),
100 _ => _ = path.line_to(x + slot / 2.0, y),
101 }
102 }
103 paper.outline(&path, Pen::new(3.0), back);
104 for (month, came) in BACK.iter().enumerate() {
105 let mut dot = Path::new();
106 dot.circle(plot.x + slot * (month as f32 + 0.5), plot.bottom() - plot.h * came / most_back, 4.5);
107 paper.shape(&dot, back);
108 }
109 let key = plot.bottom() + 40.0;
110 paper.rounded(rect(plot.x, key, 14.0, 14.0), 3.0, sold);
111 paper.text("Sold (left)", plot.x + 22.0, key - 2.0, small, dim);
112 paper.rounded(rect(plot.x + 140.0, key + 5.0, 14.0, 4.0), 2.0, back);
113 paper.text("Came back (right)", plot.x + 162.0, key - 2.0, small, dim);
114}examples/overlay.rs (line 127)
117pub unsafe extern "C" fn overlay_frame(overlay: *mut Overlay, changed: *mut [i32; 4]) -> *const u32 {
118 let Overlay { ui, surface, settings, waiting, since } = unsafe { &mut *overlay };
119 ui.set_time(since.elapsed());
120 // Something is moving (a switch sliding over): the interface asked to be run by now.
121 let due = ui.wake_in() == Some(Duration::ZERO);
122 let mut area = [0; 4];
123 if std::mem::take(waiting) || due {
124 let part = ui.run(&mut |ui| describe(settings, ui)).snap_to_pixels(ui.scale());
125 surface.redraw(ui, part);
126 let scale = ui.scale();
127 area = [(part.x * scale) as i32, (part.y * scale) as i32, (part.right() * scale) as i32, (part.bottom() * scale) as i32];
128 }
129 unsafe { *changed = area };
130 surface.pixels.as_ptr()
131}Sourcepub fn bottom(&self) -> f32
pub fn bottom(&self) -> f32
Bottom edge.
Examples found in repository?
More examples
examples/report.rs (line 82)
76fn chart(paper: &mut Paper, r: taut::Rect) {
77 let (sold, back, line, dim) = (Color::rgb(0x2b6cb0), Color::rgb(0xdd6b20), Color::rgb(0xe2e8f0), Color::rgb(0x4a5568));
78 let small = Font::new(12.0);
79 let plot = rect(r.x + 48.0, r.y, r.w - 96.0, r.h - 64.0);
80 let (most, most_back) = (1000.0, 50.0);
81 for step in 0..=5 {
82 let y = plot.bottom() - plot.h * step as f32 / 5.0;
83 paper.rect(rect(plot.x, y, plot.w, 1.0), line);
84 let label = format!("{}", step * 200);
85 let wide = paper.measure(&label, small);
86 paper.text(&label, plot.x - 8.0 - wide, y - 8.0, small, dim);
87 paper.text(&format!("{}", step * 10), plot.right() + 8.0, y - 8.0, small, back);
88 }
89 let slot = plot.w / 12.0;
90 let mut path = Path::new();
91 for (month, name) in MONTHS.iter().enumerate() {
92 let x = plot.x + slot * month as f32;
93 let high = plot.h * SOLD[month] / most;
94 paper.rounded(rect(x + slot * 0.2, plot.bottom() - high, slot * 0.6, high), 3.0, sold);
95 let wide = paper.measure(name, small);
96 paper.text(name, x + (slot - wide) / 2.0, plot.bottom() + 8.0, small, dim);
97 let y = plot.bottom() - plot.h * BACK[month] / most_back;
98 match month {
99 0 => _ = path.move_to(x + slot / 2.0, y),
100 _ => _ = path.line_to(x + slot / 2.0, y),
101 }
102 }
103 paper.outline(&path, Pen::new(3.0), back);
104 for (month, came) in BACK.iter().enumerate() {
105 let mut dot = Path::new();
106 dot.circle(plot.x + slot * (month as f32 + 0.5), plot.bottom() - plot.h * came / most_back, 4.5);
107 paper.shape(&dot, back);
108 }
109 let key = plot.bottom() + 40.0;
110 paper.rounded(rect(plot.x, key, 14.0, 14.0), 3.0, sold);
111 paper.text("Sold (left)", plot.x + 22.0, key - 2.0, small, dim);
112 paper.rounded(rect(plot.x + 140.0, key + 5.0, 14.0, 4.0), 2.0, back);
113 paper.text("Came back (right)", plot.x + 162.0, key - 2.0, small, dim);
114}examples/overlay.rs (line 127)
117pub unsafe extern "C" fn overlay_frame(overlay: *mut Overlay, changed: *mut [i32; 4]) -> *const u32 {
118 let Overlay { ui, surface, settings, waiting, since } = unsafe { &mut *overlay };
119 ui.set_time(since.elapsed());
120 // Something is moving (a switch sliding over): the interface asked to be run by now.
121 let due = ui.wake_in() == Some(Duration::ZERO);
122 let mut area = [0; 4];
123 if std::mem::take(waiting) || due {
124 let part = ui.run(&mut |ui| describe(settings, ui)).snap_to_pixels(ui.scale());
125 surface.redraw(ui, part);
126 let scale = ui.scale();
127 area = [(part.x * scale) as i32, (part.y * scale) as i32, (part.right() * scale) as i32, (part.bottom() * scale) as i32];
128 }
129 unsafe { *changed = area };
130 surface.pixels.as_ptr()
131}Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether it has no width or no height.
Examples found in repository?
examples/gallery.rs (line 408)
390fn tool_bar(app: &mut App, ui: &mut Ui) {
391 let bar = ui.tool_bar();
392 if ui.tool(PLUS, "Add an item\tCtrl+N").clicked {
393 ui.notice("An item was added");
394 }
395 let tint = ui.tool(DROP, "The colour that stands out");
396 ui.tool_toggle(&mut app.starred, STAR, "Starred\tCtrl+D");
397 ui.tool_group();
398 if ui.tool(COPY, "Copy the notes").clicked {
399 ui.copy(&app.notes);
400 }
401 if ui.tool(SYNC, "Start over").clicked {
402 app.presses = 0;
403 }
404 ui.tool(GRID, "A tool that does nothing");
405 ui.close();
406 // (Opened from the overflow menu, it points at the bar.)
407 if tint.clicked {
408 ui.open_popup(tint.id, if tint.rect.is_empty() { bar.rect } else { tint.rect });
409 }
410 if ui.popover(tint.id) {
411 ui.label("The colour that stands out");
412 ui.color_picker(&mut app.tint);
413 ui.close();
414 }
415}Sourcepub fn contains(&self, p: Point) -> bool
pub fn contains(&self, p: Point) -> bool
Whether the point is inside. All four sides are tested at once, without branches: this runs for every box the pointer could be over, on every move.
Sourcepub fn union(&self, o: Rect) -> Rect
pub fn union(&self, o: Rect) -> Rect
The smallest rectangle holding both. An empty one adds nothing.
Examples found in repository?
examples/book.rs (line 100)
88fn take(ui: &mut Ui, describe: &mut dyn FnMut(&mut Ui), screen: &mut Surface, step: Step) -> Rect {
89 let events = match step {
90 Step::Click(name) => vec![Event::Move(middle(find(ui, name))), Event::Press(Button::Left, Mods::NONE), Event::Release(Button::Left)],
91 Step::ClickAt(x, y) => vec![Event::Move(pt(x, y)), Event::Press(Button::Left, Mods::NONE), Event::Release(Button::Left)],
92 Step::RightClick(name) => vec![Event::Move(middle(find(ui, name))), Event::Press(Button::Right, Mods::NONE), Event::Release(Button::Right)],
93 Step::Hover(name) => vec![Event::Move(middle(find(ui, name)))],
94 Step::Type(text) => vec![Event::Text(text.into())],
95 Step::Press(key, mods) => vec![Event::Key(key, mods)],
96 Step::Wheel(name, down) => vec![Event::Move(middle(find(ui, name))), Event::Wheel(0.0, down)],
97 };
98 let mut changed = Rect::EMPTY;
99 for event in events {
100 changed = changed.union(happens(ui, describe, screen, event));
101 }
102 changed
103}Sourcepub fn snap_to_pixels(&self, scale: f32) -> Rect
pub fn snap_to_pixels(&self, scale: f32) -> Rect
Grown just enough for its edges to lie on whole pixels at scale pixels per unit: the
area to redraw.
Examples found in repository?
examples/book.rs (line 123)
107fn shoot(folder: &Path, mut shot: Shot) {
108 let mut ui = Ui::new(taut::platform::system_text(), Box::new(LocalClipboard::default()));
109 ui.resize(Size { w: shot.size[0], h: shot.size[1] }, shot.scale);
110 ui.set_screen_reader(true);
111 ui.run(&mut shot.describe);
112 ui.run(&mut shot.describe);
113 let mut screen = Surface::draw(&mut ui, 64);
114 let mut changed = Rect::EMPTY;
115 for (at, step) in shot.steps.iter().enumerate() {
116 ui.set_time(Duration::from_secs(at as u64 + 1));
117 changed = take(&mut ui, &mut shot.describe, &mut screen, *step);
118 }
119 ui.set_time(Duration::from_secs(shot.steps.len() as u64 + 2));
120 let rest = ui.run(&mut shot.describe);
121 screen.redraw(&mut ui, rest);
122 if shot.marked {
123 mark(&mut screen, changed.snap_to_pixels(shot.scale));
124 }
125 if shot.over_a_game {
126 lay_over_a_game(&mut screen);
127 }
128 let file = folder.join(format!("{}.png", shot.name));
129 std::fs::write(&file, screen.to_png()).expect("the picture could not be written");
130 println!("{} ({} by {})", file.display(), screen.width, screen.height);
131}More examples
examples/overlay.rs (line 124)
117pub unsafe extern "C" fn overlay_frame(overlay: *mut Overlay, changed: *mut [i32; 4]) -> *const u32 {
118 let Overlay { ui, surface, settings, waiting, since } = unsafe { &mut *overlay };
119 ui.set_time(since.elapsed());
120 // Something is moving (a switch sliding over): the interface asked to be run by now.
121 let due = ui.wake_in() == Some(Duration::ZERO);
122 let mut area = [0; 4];
123 if std::mem::take(waiting) || due {
124 let part = ui.run(&mut |ui| describe(settings, ui)).snap_to_pixels(ui.scale());
125 surface.redraw(ui, part);
126 let scale = ui.scale();
127 area = [(part.x * scale) as i32, (part.y * scale) as i32, (part.right() * scale) as i32, (part.bottom() * scale) as i32];
128 }
129 unsafe { *changed = area };
130 surface.pixels.as_ptr()
131}Trait Implementations§
impl Copy for Rect
impl StructuralPartialEq for Rect
Auto Trait Implementations§
impl Forget for Rect
impl Freeze for Rect
impl Move for Rect
impl RefUnwindSafe for Rect
impl Send for Rect
impl Sync for Rect
impl Unpin for Rect
impl UnsafeUnpin for Rect
impl UnwindSafe for Rect
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more