2026-05-11 23:06:39 +03:00
|
|
|
/*
|
|
|
|
|
* InfiniPaint
|
|
|
|
|
* Copyright (C) 2025-2026 Yousef Khadadeh
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2026-03-27 09:51:53 +03:00
|
|
|
#include "LayoutElement.hpp"
|
2026-03-31 17:33:09 +03:00
|
|
|
#include "Helpers/ConvertVec.hpp"
|
2026-04-24 10:06:45 +03:00
|
|
|
#include "../GUIManager.hpp"
|
2026-03-27 09:51:53 +03:00
|
|
|
|
|
|
|
|
namespace GUIStuff {
|
|
|
|
|
|
|
|
|
|
LayoutElement::LayoutElement(GUIManager& gui): Element(gui) {}
|
|
|
|
|
|
2026-04-02 21:57:26 +03:00
|
|
|
void LayoutElement::layout(const Clay_ElementId& id, const std::function<void(LayoutElement*, const Clay_ElementId&)>& layout, const Callbacks& c) {
|
2026-03-27 09:51:53 +03:00
|
|
|
this->c = c;
|
2026-04-02 21:57:26 +03:00
|
|
|
layout(this, id);
|
2026-03-27 09:51:53 +03:00
|
|
|
}
|
|
|
|
|
|
2026-04-02 21:57:26 +03:00
|
|
|
void LayoutElement::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
|
|
|
|
if(c.mouseButton) c.mouseButton(this, button);
|
2026-04-28 20:28:21 +03:00
|
|
|
if(c.onClick) c.onClick(this, button);
|
2026-03-27 09:51:53 +03:00
|
|
|
}
|
|
|
|
|
|
2026-04-02 21:57:26 +03:00
|
|
|
void LayoutElement::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) {
|
|
|
|
|
if(c.mouseMotion) c.mouseMotion(this, motion);
|
2026-04-29 12:38:40 +03:00
|
|
|
if(c.onMotion) c.onMotion(this, motion);
|
2026-03-27 09:51:53 +03:00
|
|
|
}
|
|
|
|
|
|
2026-04-02 21:57:26 +03:00
|
|
|
void LayoutElement::input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel) {
|
|
|
|
|
if(c.mouseWheel) c.mouseWheel(this, wheel);
|
2026-03-27 09:51:53 +03:00
|
|
|
}
|
|
|
|
|
|
2026-04-28 20:28:21 +03:00
|
|
|
void LayoutElement::input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch) {
|
|
|
|
|
if(c.fingerTouch) c.fingerTouch(this, touch);
|
|
|
|
|
if(c.onClick) {
|
|
|
|
|
c.onClick(this, {
|
|
|
|
|
.deviceType = InputManager::MouseDeviceType::TOUCH,
|
|
|
|
|
.button = InputManager::MouseButton::LEFT,
|
|
|
|
|
.down = touch.down,
|
|
|
|
|
.clicks = static_cast<uint8_t>(touch.fingerTapCount),
|
|
|
|
|
.pos = touch.pos
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LayoutElement::input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion) {
|
|
|
|
|
if(c.fingerMotion) c.fingerMotion(this, motion);
|
2026-04-29 12:38:40 +03:00
|
|
|
if(c.onMotion) {
|
|
|
|
|
c.onMotion(this, {
|
|
|
|
|
.deviceType = InputManager::MouseDeviceType::TOUCH,
|
|
|
|
|
.pos = motion.pos,
|
|
|
|
|
.move = motion.move
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-04-28 20:28:21 +03:00
|
|
|
}
|
|
|
|
|
|
2026-03-27 09:51:53 +03:00
|
|
|
void LayoutElement::input_key_callback(const InputManager::KeyCallbackArgs& key) {
|
2026-04-02 21:57:26 +03:00
|
|
|
if(c.key) c.key(this, key);
|
2026-03-27 09:51:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|