mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-08-09 16:26:38 +08:00
Add Box::IsEmpty()
This commit is contained in:
parent
3d6c48e800
commit
0279bed8c4
@ -29,6 +29,9 @@ current (development)
|
|||||||
reflecting the current scroll position. Proposed by @ibrahimnasson in
|
reflecting the current scroll position. Proposed by @ibrahimnasson in
|
||||||
[issue 752](https://github.com/ArthurSonzogni/FTXUI/issues/752)
|
[issue 752](https://github.com/ArthurSonzogni/FTXUI/issues/752)
|
||||||
|
|
||||||
|
### Screen
|
||||||
|
- Feature: Add `Box::IsEmpty()`.
|
||||||
|
|
||||||
### Build
|
### Build
|
||||||
- Support for cmake's "unity/jumbo" builds. Fixed by @ClausKlein.
|
- Support for cmake's "unity/jumbo" builds. Fixed by @ClausKlein.
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ struct Box {
|
|||||||
static auto Intersection(Box a, Box b) -> Box;
|
static auto Intersection(Box a, Box b) -> Box;
|
||||||
static auto Union(Box a, Box b) -> Box;
|
static auto Union(Box a, Box b) -> Box;
|
||||||
bool Contain(int x, int y) const;
|
bool Contain(int x, int y) const;
|
||||||
int Area() const noexcept;
|
bool IsEmpty();
|
||||||
bool operator==(const Box& other) const;
|
bool operator==(const Box& other) const;
|
||||||
bool operator!=(const Box& other) const;
|
bool operator!=(const Box& other) const;
|
||||||
};
|
};
|
||||||
|
@ -850,8 +850,9 @@ void Canvas::DrawImage(int x,
|
|||||||
y = 0;
|
y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (crop.Area() == 0)
|
if (crop.IsEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto xend = x + crop.x_max - crop.x_min;
|
const auto xend = x + crop.x_max - crop.x_min;
|
||||||
const auto yend = y + crop.y_max - crop.y_min;
|
const auto yend = y + crop.y_max - crop.y_min;
|
||||||
|
@ -39,11 +39,10 @@ bool Box::Contain(int x, int y) const {
|
|||||||
y_max >= y;
|
y_max >= y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @return the are of the box
|
/// @return whether the box is empty.
|
||||||
/// @ingroup screen
|
/// @ingroup screen
|
||||||
int Box::Area() const noexcept {
|
bool Box::IsEmpty() {
|
||||||
const auto area = (x_max - x_min) * (y_max - y_min);
|
return x_min > x_max || y_min > y_max;
|
||||||
return area < 0 ? 0 : area;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @return whether |other| is the same as |this|
|
/// @return whether |other| is the same as |this|
|
||||||
|
Loading…
Reference in New Issue
Block a user