1 2 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870
/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ //! Types dealing with the dimensions of widgets. //! //! The coordinate system in Suzy sets the origin at the lower-left //! of the screen, with positive X (+X) to the right, and +Y up. //! //! Types `Dim` and `Padding` represent single-dimension quantities of their //! mesurements: Position+Size for `Dim`, and padding before and after for //! `Padding`. //! //! `Rect` and `Padding2d` are traits which describe the 2-dimensional //! versions of `Dim` and `Padding` respectively. //! //! As a trait, `Rect` is implemented by Widgets and most Graphics. //! //! This module provides the types `SimpleRect` and `SimplePadding2d`, which //! are simple value types that implement their respective traits. /// Representation of a single dimension of padding. #[derive(Debug, Default, PartialEq, Copy, Clone)] pub struct Padding { /// The amount of padding "before" the content in a dimension. pub before: f32, /// The amount of padding "after" the content in a dimension. pub after: f32, } impl Padding { /// Create a new padding struct with the provided amounts pub fn new(before: f32, after: f32) -> Padding { Padding { before, after } } /// Create a new padding struct with zero amount pub fn zero() -> Padding { Padding::new(0.0, 0.0) } /// Create a padding struct with the same amount before and after pub fn uniform(value: f32) -> Padding { Padding::new(value, value) } } /// Methods associated with retrieving and changing values of two dimensions /// of padding. pub trait Padding2d { /// Get the padding on the left and right fn x(&self) -> Padding; /// Get the padding on the bottom and top fn y(&self) -> Padding; /// Get mutable reference to padding on left and right fn x_mut(&mut self) -> &mut Padding; /// Get mutable reference to padding on bottom and top fn y_mut(&mut self) -> &mut Padding; /// Get the amount of top padding fn top(&self) -> f32 { self.y().after } /// Set the amount of top padding fn set_top(&mut self, amount: f32) { self.y_mut().after = amount } /// Get the amount of right padding fn right(&self) -> f32 { self.x().after } /// Set the amount of right padding fn set_right(&mut self, amount: f32) { self.x_mut().after = amount } /// Get the amount of bottom padding fn bottom(&self) -> f32 { self.y().before } /// Set the amount of bottom padding fn set_bottom(&mut self, amount: f32) { self.y_mut().before = amount } /// Get the amount of left padding fn left(&self) -> f32 { self.x().before } /// Set the amount of left padding fn set_left(&mut self, amount: f32) { self.x_mut().before = amount } } /// Representation of two dimensions of padding #[derive(Copy, Clone, Debug, Default, PartialEq)] pub struct SimplePadding2d { x: Padding, y: Padding, } impl SimplePadding2d { /// Create a new 2D padding with the specified values. pub fn new(top: f32, right: f32, bottom: f32, left: f32) -> Self { Self { x: Padding::new(left, right), y: Padding::new(bottom, top), } } /// Create a new 2D padding with zero amount pub fn zero() -> Self { Self::uniform(0.0) } /// Create a new 2D padding with the same amount on all edges pub fn uniform(value: f32) -> Self { Self::new(value, value, value, value) } /// Create a new 2D padding with the same amount on left and right, and /// zero on top and bottom pub fn pillarbox(value: f32) -> Self { Self::new(0.0, value, 0.0, value) } /// Create a new 2D padding with the same amount on top and bottom, and /// zero on left and right pub fn letterbox(value: f32) -> Self { Self::new(value, 0.0, value, 0.0) } /// Create a new 2D padding with the same amount on top as on bottom, and /// the same amount on left as on right pub fn windowbox(y: f32, x: f32) -> Self { Self::new(y, x, y, x) } } impl Padding2d for SimplePadding2d { fn x(&self) -> Padding { self.x } fn y(&self) -> Padding { self.y } fn x_mut(&mut self) -> &mut Padding { &mut self.x } fn y_mut(&mut self) -> &mut Padding { &mut self.y } } impl<P: Padding2d> From<&P> for SimplePadding2d { fn from(padding: &P) -> Self { Self { x: padding.x(), y: padding.y(), } } } /// A struct representing span of a single dimension. /// /// The authoritative representation of a Dim is based on three values: /// a position, a length, and a pivot. The position describes a point on the /// the screen. The pivot is a ratio, generally from 0 (start) to 1 (end), /// which indicates how much of the length is distributed on each side of /// the position. /// /// For example, a pivot of 0.1 indicates that 10% of the length is 'before' /// the position point, and 90% is after. Changing the length will maintain /// this distribution. /// /// Methods like `set_start` and `set_end` update the pivot to 0 and 1 /// respectively. /// /// # Examples /// ```rust /// use suzy::dims::Dim; /// let assert_feq = |a: f32, b: f32| { /// # assert!( /// # a.is_finite(), "assert_feq: argument `a` was NaN or infinite"); /// # assert!( /// # b.is_finite(), "assert_feq: argument `b` was NaN or infinite"); /// assert!( /// (a-b).abs() < 0.0001, /// "assert_feq: greater than threshold: {} != {}", a, b); /// }; /// let mut span = Dim::with_length(5.0); /// span.set_start(10.0); /// assert_feq(span.start(), 10.0); /// assert_feq(span.end(), 15.0); /// // since we called set_start, changing the length will not effect the /// // start position (the span grows outward from start) /// span.set_length(13.0); /// assert_feq(span.start(), 10.0); /// assert_feq(span.end(), 23.0); /// ``` /// /// ```rust /// use suzy::dims::Dim; /// # let assert_feq = |a: f32, b: f32| { /// # assert!( /// # a.is_finite(), "assert_feq: argument `a` was NaN or infinite"); /// # assert!( /// # b.is_finite(), "assert_feq: argument `b` was NaN or infinite"); /// # assert!( /// # (a-b).abs() < 0.0001, /// # "assert_feq: greater than threshold: {} != {}", a, b); /// # }; /// let mut span = Dim::with_length(5.0); /// span.set_end(10.0); /// assert_feq(span.start(), 5.0); /// assert_feq(span.end(), 10.0); /// // since we called set_end, changing the length will not effect the /// // end position (the span grows backward from end) /// span.set_length(7.0); /// assert_feq(span.start(), 3.0); /// assert_feq(span.end(), 10.0); /// ``` #[derive(Copy, Clone, Debug)] pub struct Dim { pivot: f32, pos: f32, length: f32, } impl Default for Dim { fn default() -> Self { Dim::with_length(100.0) } } impl Dim { /// Create a Dim with a set length that starts at zero pub fn with_length(length: f32) -> Self { Dim { pivot: 0.5, pos: 0.5 * length, length, } } /// Get the pivot. A pivot of 0 indicates that the changing the length /// of the span will keep the start fixed and move the end. Likewise, a /// pivot of 1 will keep the end of the span fixed while adjusting the /// start to fit the length. Default: 0.5 pub fn pivot(&self) -> f32 { self.pivot } /// Set the pivot. A pivot of 0 indicates that the changing the length /// of the span will keep the start fixed and move the end. Likewise, a /// pivot of 1 will keep the end of the span fixed while adjusting the /// start to fit the length. pub fn set_pivot(&mut self, value: f32) { self.pivot = value } /// Get the length of the span pub fn length(&self) -> f32 { self.length } /// Grow or shrink the span pub fn set_length(&mut self, value: f32) { self.length = value } /// Get the global position of the pivot of the span pub fn pivot_pos(&self) -> f32 { self.pos } /// Set the position of the pivot of the wid pub fn set_pivot_pos(&mut self, value: f32) { self.pos = value } /// Get the beginning of the span pub fn start(&self) -> f32 { let distance_before_pivot = self.pivot * self.length; self.pos - distance_before_pivot } /// Set the position of the beginning of the span, and set it to grow /// from that point pub fn set_start(&mut self, value: f32) { self.pivot = 0.0; self.pos = value; } /// Get the end of the span pub fn end(&self) -> f32 { let percent_after_pivot = 1.0 - self.pivot; let distance_after_pivot = percent_after_pivot * self.length; self.pos + distance_after_pivot } /// Set the position of the end of the span, and set it to grow /// from that point pub fn set_end(&mut self, value: f32) { self.pivot = 1.0; self.pos = value; } /// Get the center of the span pub fn center(&self) -> f32 { let half_length = 0.5 * self.length; let distance_before_pivot = self.pivot * self.length; let distance_to_pivot = half_length - distance_before_pivot; self.pos + distance_to_pivot } /// Set the position of the center of the span, and set it to grow /// from that point pub fn set_center(&mut self, value: f32) { self.pivot = 0.5; self.pos = value; } /// Calculate and set the length and position based on a start and end /// value. Set to grow from center. pub fn set_stretch(&mut self, start: f32, end: f32) { self.length = end - start; self.pivot = 0.5; self.pos = 0.5 * (start + end); } /// Calculate and set the length and position based on another dim and /// provided padding. Set to grow from center. pub fn set_fill(&mut self, other: Dim, padding: Padding) { let start = other.start() + padding.before; let end = other.end() - padding.after; self.set_stretch(start, end); } /// Check if the given value is within the span pub fn contains(&self, value: f32) -> bool { (self.start() <= value) && (self.end() >= value) } /// Check if another span is completely contained within this one pub fn surrounds(&self, other: Dim) -> bool { (self.start() <= other.start()) && (self.end() >= other.end()) } /// Check if this span overlaps another one pub fn overlaps(&self, other: Dim) -> bool { other.start() < self.end() || other.end() > self.start() } } /// Methods associated with controlling the dimensions of a Rectangular /// visual element. pub trait Rect { /// Get the x dimension of the rectangle. fn x(&self) -> Dim; /// Get the y dimension of the rectangle. fn y(&self) -> Dim; /// Apply a transfomation to the x dimension of the rectangle. fn x_mut<F, R>(&mut self, f: F) -> R where F: FnOnce(&mut Dim) -> R; /// Apply a transfomation to the y dimension of the rectangle. fn y_mut<F, R>(&mut self, f: F) -> R where F: FnOnce(&mut Dim) -> R; /// Get the left edge of the rectangle fn left(&self) -> f32 { self.x().start() } /// Set the left edge of the rect and for it to grow to the right fn set_left(&mut self, value: f32) { self.x_mut(|x| x.set_start(value)) } /// Get the right edge of the rectangle fn right(&self) -> f32 { self.x().end() } /// Set the right edge of the rect and for it to grow to the left fn set_right(&mut self, value: f32) { self.x_mut(|x| x.set_end(value)) } /// Get the bottom edge of the rectangle fn bottom(&self) -> f32 { self.y().start() } /// Set the bottom edge of the rect and for it to grow upwards fn set_bottom(&mut self, value: f32) { self.y_mut(|y| y.set_start(value)); } /// Get the top edge of the rectangle fn top(&self) -> f32 { self.y().end() } /// Set the top edge of the rect and for it to grow downwards fn set_top(&mut self, value: f32) { self.y_mut(|y| y.set_end(value)) } /// Get the horizontal center of the rect fn center_x(&self) -> f32 { self.x().center() } /// Set the horizontal center of the rect and for it to grow evenly wider fn set_center_x(&mut self, value: f32) { self.x_mut(|x| x.set_center(value)); } /// Get the vertical center of the rect fn center_y(&self) -> f32 { self.y().center() } /// Set the vertical center of the rect and for it to grow evenly taller fn set_center_y(&mut self, value: f32) { self.y_mut(|y| y.set_center(value)); } /// Get the center of the rect fn center(&self) -> (f32, f32) { (self.x().center(), self.y().center()) } /// Set the center of the rect and for it to grow evenly outwards fn set_center(&mut self, value: (f32, f32)) { self.x_mut(|x| x.set_center(value.0)); self.y_mut(|y| y.set_center(value.1)); } /// Get the width of the rectangle fn width(&self) -> f32 { self.x().length } /// Set the width of the rectangle fn set_width(&mut self, value: f32) { self.x_mut(|x| x.length = value) } /// Get the height of the rectangle fn height(&self) -> f32 { self.y().length } /// Set the height of the rectangle fn set_height(&mut self, value: f32) { self.y_mut(|y| y.length = value) } /// Set the pivot. A pivot of (0.5, 0.5) indicates that a rect will /// grow from it's center, whereas a pivot of (0, 0) indicates that a /// rect will grow from it's bottom left corner. fn pivot(&self) -> (f32, f32) { (self.x().pivot(), self.y().pivot()) } /// Set the pivot. A pivot of (0.5, 0.5) indicates that a rect will /// grow from it's center, whereas a pivot of (0, 0) indicates that a /// rect will grow from it's bottom left corner. fn set_pivot(&mut self, value: (f32, f32)) { self.x_mut(|x| x.set_pivot(value.0)); self.y_mut(|y| y.set_pivot(value.1)); } /// Get the global position of the pivot of the rectangle fn pivot_pos(&self) -> (f32, f32) { (self.x().pivot_pos(), self.y().pivot_pos()) } /// Set the global position of the pivot of the rectangle fn set_pivot_pos(&mut self, value: (f32, f32)) { self.x_mut(|x| x.set_pivot_pos(value.0)); self.y_mut(|y| y.set_pivot_pos(value.1)); } /// Get the area of the rectangle fn area(&self) -> f32 { self.x().length * self.y().length } /// Get the aspect ratio of this rectangle (width / height) /// Note: this may be a non-normal number fn aspect(&self) -> f32 { self.x().length / self.y().length } /// Check if a point is inside the rectangle fn contains(&self, point: (f32, f32)) -> bool { self.x().contains(point.0) && self.y().contains(point.1) } /// Calculate the width and horizontal position of this rect based on /// another rect and some padding fn set_fill_width<R>(&mut self, other: &R, padding: Padding) where R: Rect + ?Sized, { self.x_mut(|x| x.set_fill(other.x(), padding)); } /// Calculate the height and vertical position of this rect based on /// another rect and some padding fn set_fill_height<R>(&mut self, other: &R, padding: Padding) where R: Rect + ?Sized, { self.y_mut(|y| y.set_fill(other.y(), padding)); } /// Calculate the size and position of this rect based on another rect /// and some padding fn set_fill<R, P>(&mut self, other: &R, padding: &P) where R: Rect + ?Sized, P: Padding2d + ?Sized, { self.x_mut(|x| x.set_fill(other.x(), padding.x())); self.y_mut(|y| y.set_fill(other.y(), padding.y())); } /// Shink one of the lengths of this rect so that the rect's aspect ratio /// becomes the one provided fn shrink_to_aspect(&mut self, aspect: f32) { let self_aspect = self.aspect(); if self_aspect < aspect { // we are relatively taller let new = self.x().length / aspect; self.set_height(new); } else if self_aspect > aspect { // we're relatively wider let new = self.y().length * aspect; self.set_width(new); } } /// Expand one of the lengths of this rect so that the rect's aspect ratio /// becomes the one provided fn grow_to_aspect(&mut self, aspect: f32) { let self_aspect = self.aspect(); if self_aspect < aspect { // we are relatively taller let new = self.y().length * aspect; self.set_width(new); } else if self_aspect > aspect { // we're relatively wider let new = self.x().length / aspect; self.set_height(new) } } /// Check if another rect is completely contained within this one fn surrounds<R: Rect + ?Sized>(&self, other: &R) -> bool { self.x().surrounds(other.x()) && self.y().surrounds(other.y()) } /// Check if this rect overlaps at all with another fn overlaps<R: Rect + ?Sized>(&self, other: &R) -> bool { self.x().overlaps(other.x()) && self.y().overlaps(other.y()) } } /// A struct representing a rectangular region #[derive(Copy, Clone, Debug, Default)] pub struct SimpleRect { x: Dim, y: Dim, } impl SimpleRect { /// Create a new SimpleRect with the specified dimensions. pub fn new(x: Dim, y: Dim) -> Self { Self { x, y } } /// Create a new SimpleRect with the specified sizes, positioned at the /// bottom left. pub fn with_size(width: f32, height: f32) -> Self { let xdim = Dim::with_length(width); let ydim = Dim::with_length(height); Self::new(xdim, ydim) } } impl<'a> Rect for SimpleRect { fn x(&self) -> Dim { self.x } fn y(&self) -> Dim { self.y } fn x_mut<F, R>(&mut self, f: F) -> R where F: FnOnce(&mut Dim) -> R, { (f)(&mut self.x) } fn y_mut<F, R>(&mut self, f: F) -> R where F: FnOnce(&mut Dim) -> R, { (f)(&mut self.y) } } impl<R: Rect> From<&R> for SimpleRect { fn from(rect: &R) -> Self { Self { x: rect.x(), y: rect.y(), } } } /// A rectangular region which will ignore changes to size #[derive(Copy, Clone)] pub struct FixedSizeRect { x: Dim, y: Dim, } impl FixedSizeRect { /// Create a new FixedSizeRect with the specified dimensions. pub fn new(x: Dim, y: Dim) -> Self { Self { x, y } } /// Create a new FixedSizeRect with the specified size, positioned at the /// bottom left. pub fn default_pos(width: f32, height: f32) -> Self { let x = Dim::with_length(width); let y = Dim::with_length(height); Self { x, y } } } impl<'a> Rect for FixedSizeRect { fn x(&self) -> Dim { self.x } fn y(&self) -> Dim { self.y } fn x_mut<F, R>(&mut self, f: F) -> R where F: FnOnce(&mut Dim) -> R, { let width = self.x.length; let res = (f)(&mut self.x); self.x.length = width; res } fn y_mut<F, R>(&mut self, f: F) -> R where F: FnOnce(&mut Dim) -> R, { let height = self.y.length; let res = (f)(&mut self.y); self.y.length = height; res } } impl From<SimpleRect> for FixedSizeRect { fn from(rect: SimpleRect) -> Self { Self { x: rect.x, y: rect.y, } } } /// An object-safe version of the Rect trait pub trait DynRect { /// Get the x dimension of the rectangle. fn x(&self) -> Dim; /// Get the y dimension of the rectangle. fn y(&self) -> Dim; /// Apply a transfomation to the x dimension of the rectangle. fn x_mut<'a>(&mut self, f: Box<dyn FnOnce(&mut Dim) + 'a>); /// Apply a transfomation to the y dimension of the rectangle. fn y_mut<'a>(&mut self, f: Box<dyn FnOnce(&mut Dim) + 'a>); /// Set the left edge of the rect and for it to grow to the right fn set_left(&mut self, value: f32); /// Set the right edge of the rect and for it to grow to the left fn set_right(&mut self, value: f32); /// Set the bottom edge of the rect and for it to grow upwards fn set_bottom(&mut self, value: f32); /// Set the top edge of the rect and for it to grow downwards fn set_top(&mut self, value: f32); /// Set the horizontal center of the rect and for it to grow evenly wider fn set_center_x(&mut self, value: f32); /// Set the vertical center of the rect and for it to grow evenly taller fn set_center_y(&mut self, value: f32); /// Set the center of the rect and for it to grow evenly outwards fn set_center(&mut self, value: (f32, f32)); /// Set the width of the rectangle fn set_width(&mut self, value: f32); /// Set the height of the rectangle fn set_height(&mut self, value: f32); /// Set the pivot. A pivot of (0.5, 0.5) indicates that a rect will /// grow from it's center, whereas a pivot of (0, 0) indicates that a /// rect will grow from it's bottom left corner. fn set_pivot(&mut self, value: (f32, f32)); /// Set the global position of the pivot of the rectangle fn set_pivot_pos(&mut self, value: (f32, f32)); /// Shink one of the lengths of this rect so that the rect's aspect ratio /// becomes the one provided fn shrink_to_aspect(&mut self, aspect: f32); /// Expand one of the lengths of this rect so that the rect's aspect ratio /// becomes the one provided fn grow_to_aspect(&mut self, aspect: f32); } impl<T: Rect> DynRect for T { fn x(&self) -> Dim { Rect::x(self) } fn y(&self) -> Dim { Rect::y(self) } fn x_mut<'a>(&mut self, f: Box<dyn FnOnce(&mut Dim) + 'a>) { Rect::x_mut(self, |dim| f(dim)) } fn y_mut<'a>(&mut self, f: Box<dyn FnOnce(&mut Dim) + 'a>) { Rect::y_mut(self, |dim| f(dim)) } fn set_left(&mut self, value: f32) { Rect::set_left(self, value) } fn set_right(&mut self, value: f32) { Rect::set_right(self, value) } fn set_bottom(&mut self, value: f32) { Rect::set_bottom(self, value) } fn set_top(&mut self, value: f32) { Rect::set_top(self, value) } fn set_center_x(&mut self, value: f32) { Rect::set_center_x(self, value) } fn set_center_y(&mut self, value: f32) { Rect::set_center_y(self, value) } fn set_center(&mut self, value: (f32, f32)) { Rect::set_center(self, value) } fn set_width(&mut self, value: f32) { Rect::set_width(self, value) } fn set_height(&mut self, value: f32) { Rect::set_height(self, value) } fn set_pivot(&mut self, value: (f32, f32)) { Rect::set_pivot(self, value) } fn set_pivot_pos(&mut self, value: (f32, f32)) { Rect::set_pivot_pos(self, value) } fn shrink_to_aspect(&mut self, aspect: f32) { Rect::shrink_to_aspect(self, aspect) } fn grow_to_aspect(&mut self, aspect: f32) { Rect::grow_to_aspect(self, aspect) } } impl Rect for dyn DynRect { fn x(&self) -> Dim { (*self).x() } fn y(&self) -> Dim { (*self).y() } fn x_mut<F, R>(&mut self, f: F) -> R where F: FnOnce(&mut Dim) -> R, { let mut res = None; (*self).x_mut(Box::new(|dim| { res = Some(f(dim)); })); res.expect( "DynRect implementation did not call the closure passed to x_mut", ) } fn y_mut<F, R>(&mut self, f: F) -> R where F: FnOnce(&mut Dim) -> R, { let mut res = None; (*self).y_mut(Box::new(|dim| { res = Some(f(dim)); })); res.expect( "DynRect implementation did not call the closure passed to y_mut", ) } fn set_left(&mut self, value: f32) { (*self).set_left(value) } fn set_right(&mut self, value: f32) { (*self).set_right(value) } fn set_bottom(&mut self, value: f32) { (*self).set_bottom(value) } fn set_top(&mut self, value: f32) { (*self).set_top(value) } fn set_center_x(&mut self, value: f32) { (*self).set_center_x(value) } fn set_center_y(&mut self, value: f32) { (*self).set_center_y(value) } fn set_center(&mut self, value: (f32, f32)) { (*self).set_center(value) } fn set_width(&mut self, value: f32) { (*self).set_width(value) } fn set_height(&mut self, value: f32) { (*self).set_height(value) } fn set_pivot(&mut self, value: (f32, f32)) { (*self).set_pivot(value) } fn set_pivot_pos(&mut self, value: (f32, f32)) { (*self).set_pivot_pos(value) } fn shrink_to_aspect(&mut self, aspect: f32) { (*self).shrink_to_aspect(aspect) } fn grow_to_aspect(&mut self, aspect: f32) { (*self).grow_to_aspect(aspect) } }