xtd - Reference Guide  0.1.1
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
padding.h
Go to the documentation of this file.
1 #pragma once
5 #include <cstdint>
6 #include <xtd/object.h>
7 #include <xtd/ustring.h>
8 #include "../forms_export.h"
9 
11 namespace xtd {
13  namespace forms {
20  class forms_export_ padding : public object {
21  public:
23  padding() = default;
24 
28  padding(int all) : all_(true), left_(all), top_(all), right_(all), bottom_(all) {}
29 
36  padding(int left, int top, int right, int bottom) : all_(left == top && left == right && left == bottom), left_(left), top_(top), right_(right), bottom_(bottom) {}
37 
39  padding(const padding&) = default;
40  padding& operator=(const padding&) = default;
41  bool operator==(const padding& value) {return all_ == value.all_ && left_ == value.left_ && top_ == value.top_ && right_ == value.right_ && bottom_ == value.bottom_;}
42  bool operator!=(const padding& value) {return !operator==(value);}
44 
48  int all() const {return all_ ? top_ : -1;}
52  void all(int all) {
53  if (!all_ || left_ != all) {
54  all_ = true;
55  left_ = top_ = right_ = bottom_ = all;
56  }
57  }
58 
62  int bottom() const {return bottom_;}
66  void bottom(int bottom) {
67  if (all_ || bottom_ != bottom) {
68  all_ = false;
69  bottom_ = bottom;
70  }
71  }
72 
75  int horizontal() const {return left_ + right_;}
76 
80  int left() const {return left_;}
84  void left(int left) {
85  if (all_ || left_ != left) {
86  all_ = false;
87  left_ = left;
88  }
89  }
90 
94  int right() const {return right_;}
98  void right(int right) {
99  if (all_ || right_ != right) {
100  all_ = false;
101  right_ = right;
102  }
103  }
104 
108  int top() const {return top_;}
112  void top(int top) {
113  if (all_ || top_ != top) {
114  all_ = false;
115  top_ = top;
116  }
117  }
118 
123  int vertical() const {return top_ + bottom_;}
124 
127  static padding add(const padding& p1, const padding& p2) {
128  if (p1.all_ && p2.all_) return {p1.left_ + p2.left_};
129  return {p1.left_ + p2.left_, p1.top_ + p2.top_, p1.right_ + p2.right_, p1.bottom_ + p2.bottom_};
130  }
131 
136  static padding subtract(const padding& p1, const padding& p2) {
137  if (p1.all_ && p2.all_) return {p1.left_ - p2.left_};
138  return {p1.left_ - p2.left_, p1.top_ - p2.top_, p1.right_ - p2.right_, p1.bottom_ - p2.bottom_};
139  }
140 
144  xtd::ustring to_string() const noexcept override {return xtd::ustring::format("padding [all={}, left={}, top={}, right={}, bottom={}]", all_, left_, top_, right_, bottom_);}
145 
147  bool operator==(const padding& p) const {return all_ == p.all_ && left_ == p.left_ && top_ == p.top_ && right_ == p.right_ && bottom_ == p.bottom_;}
148  friend std::ostream& operator<<(std::ostream& os, const xtd::forms::padding& padding) noexcept {return os << padding.to_string();}
150 
152  static const padding empty;
153 
154  private:
155  bool all_ = true;
156  int left_ = 0;
157  int top_ = 0;
158  int right_ = 0;
159  int bottom_ = 0;
160  };
161  }
162 }
Represents a display device or multiple display devices on a single system.
Definition: padding.h:20
int right() const
Gets the padding value for the right edge.
Definition: padding.h:94
static padding subtract(const padding &p1, const padding &p2)
Subtracts one specified Padding value from another.
Definition: padding.h:136
int left() const
Gets the padding value for the left edge.
Definition: padding.h:80
void top(int top)
Sets the padding value for the top edge.
Definition: padding.h:112
void left(int left)
Sets the padding value for the left edge.
Definition: padding.h:84
padding(int left, int top, int right, int bottom)
Initializes a new instance of the padding class using a separate padding size for each edge.
Definition: padding.h:36
xtd::ustring to_string() const noexcept override
Returns a string that represents the current padding.
Definition: padding.h:144
void bottom(int bottom)
Sets the padding value for the bottom edge.
Definition: padding.h:66
static const padding empty
Provides a Padding object with no padding.
Definition: padding.h:152
padding(int all)
Initializes a new instance of the padding class using the supplied padding size for all edges.
Definition: padding.h:28
int top() const
Gets the padding value for the top edge.
Definition: padding.h:108
int all() const
Gets the padding value for all the edges.
Definition: padding.h:48
padding()=default
Initializes a new instance of the padding class.
int horizontal() const
Gets the combined padding for the right and left edges.
Definition: padding.h:75
int vertical() const
Gets the combined padding for the bottom and top edges.
Definition: padding.h:123
void right(int right)
Sets the padding value for the right edge.
Definition: padding.h:98
void all(int all)
Sets the padding value for all the edges.
Definition: padding.h:52
int bottom() const
Gets the padding value for the bottom edge.
Definition: padding.h:62
static padding add(const padding &p1, const padding &p2)
Computes the sum of the two specified padding values.
Definition: padding.h:127
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition: object.h:26
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition: ustring.h:689
#define forms_export_
Define shared library export.
Definition: forms_export.h:13
@ p
The P key.
@ bottom
The parent form of this multiple document interface (MDI) form is closing.
@ top
The operating system is closing all applications before shutting down.
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17
Contains xtd::object class.
Contains xtd::ustring class.