xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Go to the documentation of this file.
1 #pragma once
5 #include <ostream>
6 #include <xtd/object.h>
7 #include <xtd/ustring.h>
8 #include "../drawing_export.h"
9 #include "size_f.h"
12 namespace xtd {
14  namespace drawing {
16  class point;
25  class drawing_export_ size : public object {
26  public:
28  static const xtd::drawing::size empty;
31  size() = default;
35  explicit size(const xtd::drawing::point& point);
40  size(int32_t width, int32_t height) : width_(width), height_(height) {}
43  size(const xtd::drawing::size&) = default;
44  bool operator==(const xtd::drawing::size& value) const {return width_ == value.width_ && height_ == value.height_;}
45  bool operator!=(const xtd::drawing::size& value) const {return !operator==(value);}
46  size& operator=(const xtd::drawing::size& size) = default;
47  size operator+(const xtd::drawing::size& size) const;
48  size operator-(const xtd::drawing::size& size) const;
49  size& operator+=(const xtd::drawing::size& size);
50  size& operator-=(const xtd::drawing::size& size);
51  operator size_f() {return size_f(static_cast<float>(width_), static_cast<float>(height_));}
57  int32_t height() const {return height_;}
62  void height(int32_t height) {height_ = height;}
67  int32_t width() const {return width_;}
72  void width(int32_t width) {width_ = width;}
78  static size add(const size& size1, const size& size2);
83  static size ceiling(const size_f& value);
87  bool is_empty() const {return *this == size::empty;}
92  static size round(const size_f& value);
103  xtd::ustring to_string() const noexcept override {return "{width=" + std::to_string(width_) + ", height=" + std::to_string(height_) + "}";}
108  static size truncate(const size_f& value);
111  friend std::ostream& operator<<(std::ostream& os, const xtd::drawing::size& size) noexcept {
112  return os << size.to_string();
113  }
116  private:
117  int32_t width_ = 0;
118  int32_t height_ = 0;
119  };
120  }
122  template<>
123  inline drawing::size parse<drawing::size>(const std::string& str) {
124  auto values = xtd::ustring(str).replace("}", "").replace(" height=", "").replace("{width=", "").split({','});
125  return {xtd::parse<int32_t>(values[0]), xtd::parse<int32_t>(values[1])};
126  }
127 }
void width(int32_t width)
Sets the horizontal component of this Size class.
Definition: size.h:72
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition: point.h:48
void height(int32_t height)
Sets the vertical component of this Size Class.
Definition: size.h:62
Stores an ordered pair of integers, which specify a height and width.
Definition: size.h:25
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
ustring replace(value_type old_char, value_type new_char) const noexcept
Replaces all occurrences of a specified char_t in this string with another specified char_t...
int32_t width() const
Gets the horizontal component of this Size class.
Definition: size.h:67
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
int32_t height() const
Gets he vertical component of this Size Class.
Definition: size.h:57
Stores an ordered pair of floating-point, which specify a height and width.
Definition: size_f.h:24
size(int32_t width, int32_t height)
Initializes a new instance of the Size class from the specified dimensions.
Definition: size.h:40
std::vector< ustring > split(const std::vector< value_type > &separators, size_t count, string_split_options options) const noexcept
Splits this string into a maximum number of substrings based on the characters in an array...
Contains xtd::ustring class.
xtd::ustring to_string() const noexcept override
Creates a human-readable string that represents this size class.
Definition: size.h:103
Contains xtd::object class.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:26
Contains xtd::drawing::size_f class.
Specifies a printer&#39;s point (1/72 inch) as the unit of measure.
static const xtd::drawing::size empty
Gets a Size class that has a Height and Width value of 0. This field is constant. ...
Definition: size.h:28
bool is_empty() const
Tests whether this Size class has width and height of 0.
Definition: size.h:87
The Subtract key.
std::string to_string(const value_t &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition: to_string.h:37