Crafter.Graphics/interfaces/Crafter.Graphics-UiElement.cppm

55 lines
2.8 KiB
Text
Raw Normal View History

2025-05-07 19:21:51 +02:00
/*
Crafter®.Graphics
Copyright (C) 2025 Catcrafts®
2025-11-22 20:58:42 +01:00
catcrafts.net
2025-05-07 19:21:51 +02:00
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
2025-11-22 20:58:42 +01:00
License version 3.0 as published by the Free Software Foundation;
2025-05-07 19:21:51 +02:00
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
*/
2025-04-16 00:43:33 +02:00
export module Crafter.Graphics:UiElement;
2025-11-22 20:58:42 +01:00
import :UiElementBuffer;
import :UiElementMouse;
2025-11-16 15:32:11 +01:00
import std;
2025-04-16 00:43:33 +02:00
import Crafter.Event;
import :Types;
2025-11-22 20:58:42 +01:00
export namespace Crafter {
class Font;
class UiElementBase {
2025-04-16 00:43:33 +02:00
public:
float z;
float anchorX;
float anchorY;
bool ignoreScaling;
float relativeWidth;
float relativeHeight;
float anchorOffsetX;
float anchorOffsetY;
2025-11-22 20:58:42 +01:00
std::vector<std::unique_ptr<UiElementBase>> children;
2025-06-14 01:45:33 +02:00
2025-11-22 20:58:42 +01:00
UiElementBase(float anchorX, float anchorY, float relativeWidth, float relativeHeight, float anchorOffsetX = 0.5, float anchorOffsetY = 0.5, float z = 0, bool ignoreScaling = false);
UiElementBase(UiElementBase&&) noexcept = default;
UiElementBase& operator=(UiElementBase&&) noexcept = default;
2025-11-17 00:44:45 +01:00
};
2025-11-22 20:58:42 +01:00
template<bool Buffer, bool Mouse>
class UiElement : public UiElementBase{
2025-11-17 00:44:45 +01:00
public:
2025-11-22 20:58:42 +01:00
std::conditional_t<Buffer, UiElementBuffer, std::monostate> buffer;
std::conditional_t<Buffer, UiElementMouse, std::monostate> mouse;
UiElement(float anchorX, float anchorY, float relativeWidth, float relativeHeight, float anchorOffsetX = 0.5, float anchorOffsetY = 0.5, float z = 0, bool ignoreScaling = false) : UiElementBase(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling = false) {}
UiElement(float anchorX, float anchorY, float relativeWidth, float relativeHeight, float anchorOffsetX = 0.5, float anchorOffsetY = 0.5, float z = 0, bool ignoreScaling = false) requires (Buffer) : UiElementBase(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling), buffer(*this) {}
UiElement(std::uint_fast32_t width, std::uint_fast32_t height, float anchorX, float anchorY, float relativeWidth, float relativeHeight, float anchorOffsetX = 0.5, float anchorOffsetY = 0.5, float z = 0, bool ignoreScaling = false) requires (Buffer) : UiElementBase(anchorX, anchorY, relativeWidth, relativeHeight, anchorOffsetX, anchorOffsetY, z, ignoreScaling), buffer(*this, width, height) {}
2025-04-16 00:43:33 +02:00
};
}