/* Crafter®.Graphics Copyright (C) 2026 Catcrafts® catcrafts.net This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3.0 as published by the Free Software Foundation; This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ export module Crafter.Graphics:UILength; import std; export namespace Crafter::UI { struct Length { enum class Mode : std::uint8_t { Px, Pct, Auto, Frac }; Mode mode = Mode::Auto; float value = 0.0f; static constexpr Length Px(float v) { return {Mode::Px, v}; } static constexpr Length Pct(float v) { return {Mode::Pct, v}; } static constexpr Length Auto() { return {Mode::Auto, 0.0f}; } static constexpr Length Frac(float v) { return {Mode::Frac, v}; } }; enum class Anchor : std::uint8_t { TopLeft, Top, TopRight, Left, Center, Right, BottomLeft, Bottom, BottomRight, }; struct Edges { float top = 0, right = 0, bottom = 0, left = 0; constexpr Edges() = default; constexpr explicit Edges(float all) : top(all), right(all), bottom(all), left(all) {} constexpr Edges(float vert, float horiz) : top(vert), right(horiz), bottom(vert), left(horiz) {} constexpr Edges(float t, float r, float b, float l) : top(t), right(r), bottom(b), left(l) {} }; struct Color { float r = 0, g = 0, b = 0, a = 1; constexpr Color() = default; constexpr Color(float r, float g, float b, float a = 1.0f) : r(r), g(g), b(b), a(a) {} // 0xRRGGBB, alpha = 1.0 static constexpr Color rgb(std::uint32_t hex) { return { ((hex >> 16) & 0xFF) / 255.0f, ((hex >> 8) & 0xFF) / 255.0f, ( hex & 0xFF) / 255.0f, 1.0f }; } // 0xRRGGBBAA static constexpr Color rgba(std::uint32_t hex) { return { ((hex >> 24) & 0xFF) / 255.0f, ((hex >> 16) & 0xFF) / 255.0f, ((hex >> 8) & 0xFF) / 255.0f, ( hex & 0xFF) / 255.0f }; } }; struct Size { float w = 0, h = 0; }; struct Rect { float x = 0, y = 0, w = 0, h = 0; constexpr float Right() const { return x + w; } constexpr float Bottom() const { return y + h; } constexpr bool Contains(float px, float py) const { return px >= x && px < x + w && py >= y && py < y + h; } constexpr Rect Intersect(Rect o) const { float l = std::max(x, o.x); float t = std::max(y, o.y); float r = std::min(Right(), o.Right()); float b = std::min(Bottom(), o.Bottom()); if (r <= l || b <= t) return {0, 0, 0, 0}; return {l, t, r - l, b - t}; } }; }