@@ -27,8 +27,61 @@ impl Default for CursorKind {
28#[derive(Debug, Clone, PartialEq, Eq, Hash)]
28#[derive(Debug, Clone, PartialEq, Eq, Hash)]
29pub struct Margin {
29pub struct Margin {
37+ pub fn none() -> Self {
46+ /// Set uniform margin for all sides.
47+ pub fn all(value: u16) -> Self {
56+ /// Set the margin of left and right sides to specified value.
57+ pub fn horizontal(value: u16) -> Self {
66+ /// Set the margin of top and bottom sides to specified value.
30− pub vertical: u16,
67+ pub fn vertical(value: u16) -> Self {
31− pub horizontal: u16,
68+ Self {
76+ /// Get the total width of the margin (left + right)
77+ pub fn width(&self) -> u16 {
78+ self.left + self.right
81+ /// Get the total height of the margin (top + bottom)
82+ pub fn height(&self) -> u16 {
83+ self.top + self.bottom
34/// A simple rectangle used in the computation of the layout and to give widgets an hint about the
87/// A simple rectangle used in the computation of the layout and to give widgets an hint about the
@@ -141,14 +194,14 @@ impl Rect {
143 pub fn inner(self, margin: &Margin) -> Rect {
196 pub fn inner(self, margin: &Margin) -> Rect {
144− if self.width < 2 * margin.horizontal || self.height < 2 * margin.vertical {
197+ if self.width < margin.width() || self.height < margin.height() {
145 Rect::default()
198 Rect::default()
148− x: self.x + margin.horizontal,
201+ x: self.x + margin.left,
149− y: self.y + margin.vertical,
202+ y: self.y + margin.top,
150− width: self.width - 2 * margin.horizontal,
203+ width: self.width - margin.width(),
151− height: self.height - 2 * margin.vertical,
204+ height: self.height - margin.height(),