UiUiUi
A user interface library for micro controller sketches based on U8g2
UISize.h
1// SPDX-License-Identifier: BSD-2-Clause
2// (C) 2022 Dirk Hillbrecht
3
4#pragma once
5
6#include "Arduino.h"
7
9class UISize final {
10 public:
12 static const uint16_t MAX_LEN;
13
15 static const UISize MAX_SIZE;
16
18 static const UISize EMPTY;
19
21 UISize(uint16_t width,uint16_t height);
22
24 UISize(UISize *other);
25
27 UISize();
28
30 uint16_t width;
31
33 uint16_t height;
34
36 void set(uint16_t width,uint16_t height);
37
39 void set(UISize *other);
40
42 void cumulateBoth(UISize *other);
43
46 void maxWidthCumulateHeight(UISize *other);
47
50 void cumulateWidthMaxHeight(UISize *other);
51
53 void maxBoth(UISize *other);
54
56 void shrinkTo(UISize *other);
57
59 bool isEmpty();
60
62 static uint16_t my_max(uint16_t a,uint16_t b);
63
65 static uint16_t my_min(uint16_t a,uint16_t b);
66
68 static uint16_t max_len_or(uint16_t a);
69
71 void debugPrint(const char* label);
72
73};
74
75// end of file
Representation of a size, i.e.
Definition: UISize.h:9
uint16_t width
Width.
Definition: UISize.h:30
uint16_t height
Height.
Definition: UISize.h:33
void maxWidthCumulateHeight(UISize *other)
Cumulate the heights of this and the other size and take the maximum of both widths,...
Definition: UISize.cpp:30
void cumulateBoth(UISize *other)
Cumulate width and height of this and the referenced size into this size.
Definition: UISize.cpp:25
bool isEmpty()
Return true if this size is empty, i.e.
Definition: UISize.cpp:52
UISize()
Initialize a size without width or height (both 0).
Definition: UISize.cpp:19
static const UISize MAX_SIZE
UISize representing maximal size in all directions.
Definition: UISize.h:15
static const UISize EMPTY
UISize representing an empty size (both directions 0)
Definition: UISize.h:18
void shrinkTo(UISize *other)
Shrink this so that neither width nor height is larger than the one of other.
Definition: UISize.cpp:45
static uint16_t my_max(uint16_t a, uint16_t b)
Static helper method: maximum of two given uint16_t fields.
Definition: UISize.cpp:57
void set(uint16_t width, uint16_t height)
Set height from a numeric width and height.
Definition: UISize.cpp:21
static uint16_t my_min(uint16_t a, uint16_t b)
Static helper method: maximum of two given uint16_t fields.
Definition: UISize.cpp:62
void maxBoth(UISize *other)
Take the maximum of widths and height of this and the other size and write it into this.
Definition: UISize.cpp:40
static const uint16_t MAX_LEN
Less than half of max value so that addition of two does not overflow.
Definition: UISize.h:12
void cumulateWidthMaxHeight(UISize *other)
Cumulate the widths of this and the other size and take the maximum of both heights,...
Definition: UISize.cpp:35
void debugPrint(const char *label)
Debug output of this size with some prepended label.
Definition: UISize.cpp:71
static uint16_t max_len_or(uint16_t a)
Static helper method: restrict given value to MAX_LEN at most.
Definition: UISize.cpp:67