mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-10-17 09:23:10 +08:00
49 lines
1.1 KiB
C++
49 lines
1.1 KiB
C++
/*
|
|
* @Author: DI JUNKUN
|
|
* @Date: 2026-09-04
|
|
* Copyright (c) 2026 by DI JUNKUN, All Rights Reserved.
|
|
*/
|
|
|
|
#ifndef _WINDOW_GEOMETRY_H_
|
|
#define _WINDOW_GEOMETRY_H_
|
|
|
|
#include <algorithm>
|
|
|
|
namespace crossdesk::window_geometry {
|
|
|
|
struct PhysicalRect {
|
|
int x = 0;
|
|
int y = 0;
|
|
int width = 0;
|
|
int height = 0;
|
|
};
|
|
|
|
struct PhysicalSize {
|
|
int width = 0;
|
|
int height = 0;
|
|
};
|
|
|
|
struct PhysicalPosition {
|
|
int x = 0;
|
|
int y = 0;
|
|
};
|
|
|
|
constexpr PhysicalPosition CenteredPosition(const PhysicalRect& bounds,
|
|
const PhysicalSize& size) {
|
|
return {
|
|
bounds.x + (bounds.width - std::min(bounds.width, size.width)) / 2,
|
|
bounds.y + (bounds.height - std::min(bounds.height, size.height)) / 2,
|
|
};
|
|
}
|
|
|
|
constexpr PhysicalPosition BottomRightPosition(const PhysicalRect& bounds,
|
|
const PhysicalSize& size) {
|
|
return {
|
|
bounds.x + std::max(0, bounds.width - size.width),
|
|
bounds.y + std::max(0, bounds.height - size.height),
|
|
};
|
|
}
|
|
|
|
} // namespace crossdesk::window_geometry
|
|
|
|
#endif |