SILICON
Loading...
Searching...
No Matches
componentResize.hpp
Go to the documentation of this file.
1/*
2 Copyright (c) 2026. Giulio Cocconi
3
4 SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7#pragma once
8
9#include <QPointF>
10#include <QRectF>
11#include <array>
12#include <core/component.hpp>
13
14namespace SILICON::ui {
15
26
31
32inline bool resizesLeft(ResizeHandle handle)
33{
34 return handle == ResizeHandle::Left || handle == ResizeHandle::TopLeft
35 || handle == ResizeHandle::BottomLeft;
36}
37
38inline bool resizesRight(ResizeHandle handle)
39{
40 return handle == ResizeHandle::Right || handle == ResizeHandle::TopRight
41 || handle == ResizeHandle::BottomRight;
42}
43
44inline bool resizesTop(ResizeHandle handle)
45{
46 return handle == ResizeHandle::Top || handle == ResizeHandle::TopLeft
47 || handle == ResizeHandle::TopRight;
48}
49
50inline bool resizesBottom(ResizeHandle handle)
51{
52 return handle == ResizeHandle::Bottom || handle == ResizeHandle::BottomLeft
53 || handle == ResizeHandle::BottomRight;
54}
55
56inline QPointF resizeHandlePoint(const QRectF& bounds, ResizeHandle handle)
57{
58 return {resizesLeft(handle) ? bounds.left()
59 : resizesRight(handle) ? bounds.right()
60 : bounds.center().x(),
61 resizesTop(handle) ? bounds.top()
62 : resizesBottom(handle) ? bounds.bottom()
63 : bounds.center().y()};
64}
65
68inline QPointF resizeAnchor(const QRectF& bounds, ResizeHandle handle)
69{
70 return {resizesLeft(handle) ? bounds.right()
71 : resizesRight(handle) ? bounds.left()
72 : bounds.center().x(),
73 resizesTop(handle) ? bounds.bottom() : bounds.top()};
74}
75
82
83} // namespace SILICON::ui
std::unordered_map< std::string, PropertyValue, TransparentStringHash, TransparentStringEqual > PropertyMap
Map from property names to their values.
bool resizesRight(ResizeHandle handle)
bool resizesLeft(ResizeHandle handle)
bool resizesBottom(ResizeHandle handle)
QPointF resizeAnchor(const QRectF &bounds, ResizeHandle handle)
constexpr std::array AllResizeHandles
bool resizesTop(ResizeHandle handle)
QPointF resizeHandlePoint(const QRectF &bounds, ResizeHandle handle)
bool operator==(const ComponentResizeState &) const =default