From 3bfd1797e4b484d657ed19cf263d10c06a8829bd Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Sun, 15 Jan 2023 06:54:07 +0300 Subject: [PATCH] Added initial list of functions for geometry calculations. --- CMakeLists.txt | 1 + ui/rect.h | 107 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 ui/rect.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e60a59..034941a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -270,6 +270,7 @@ PRIVATE ui/painter.h ui/ph.cpp ui/ph.h + ui/rect.h ui/rect_part.h ui/round_rect.cpp ui/round_rect.h diff --git a/ui/rect.h b/ui/rect.h new file mode 100644 index 0000000..8564b3b --- /dev/null +++ b/ui/rect.h @@ -0,0 +1,107 @@ +// This file is part of Desktop App Toolkit, +// a set of libraries for developing nice desktop applications. +// +// For license and copyright information please follow this link: +// https://github.com/desktop-app/legal/blob/master/LEGAL +// +#pragma once + +#include + +namespace rect { + +// Margins. +namespace m { +namespace sum { + +/* + Horizontal. + rect::m::sum::h(mypadding); +*/ +[[nodiscard]] int h(const QMargins &margins) { + return margins.left() + margins.right(); +} + +[[nodiscard]] float64 h(const QMarginsF &margins) { + return margins.left() + margins.right(); +} + +/* + Vertical. + rect::m::sum::v(mypadding); +*/ +[[nodiscard]] int v(const QMargins &margins) { + return margins.top() + margins.bottom(); +} + +[[nodiscard]] float64 v(const QMarginsF &margins) { + return margins.top() + margins.bottom(); +} + +} // namespace sum +} // namespace m + +/* + rect::right(mywidget); +*/ +[[nodiscard]] int right(const QRect &r) { + return r.left() + r.width(); +} + +[[nodiscard]] float64 right(const QRectF &r) { + return r.left() + r.width(); +} + +[[nodiscard]] int right(not_null w) { + return w->x() + w->width(); +} + +/* + rect::bottom(mywidget); +*/ +[[nodiscard]] int bottom(const QRect &r) { + return r.top() + r.height(); +} + +[[nodiscard]] float64 bottom(const QRectF &r) { + return r.top() + r.height(); +} + +[[nodiscard]] int bottom(not_null w) { + return w->y() + w->height(); +} + +} // namespace rect + +/* + Rect(mysize); +*/ +[[nodiscard]] QRect Rect(const QSize &s) { + return QRect(QPoint(), s); +} + +[[nodiscard]] QRectF Rect(const QSizeF &s) { + return QRectF(QPointF(), s); +} + +/* + Size(myside); +*/ +[[nodiscard]] QSize Size(int side) { + return QSize(side, side); +} + +[[nodiscard]] QSizeF Size(float64 side) { + return QSizeF(side, side); +} + +/* + Margins(myvalue); +*/ +[[nodiscard]] QMargins Margins(int side) { + return QMargins{ side, side, side, side }; +} + +[[nodiscard]] QMarginsF Margins(float64 side) { + return QMarginsF{ side, side, side, side }; +}