Emulate touch events as mouse button events in layoutelement

This commit is contained in:
Yousef Khadadeh 2026-04-28 20:28:21 +03:00
parent 973014cb5f
commit 4c30939882
6 changed files with 33 additions and 11 deletions

View file

@ -13,6 +13,7 @@ void LayoutElement::layout(const Clay_ElementId& id, const std::function<void(La
void LayoutElement::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) {
if(c.mouseButton) c.mouseButton(this, button);
if(c.onClick) c.onClick(this, button);
}
void LayoutElement::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) {
@ -23,6 +24,23 @@ void LayoutElement::input_mouse_wheel_callback(const InputManager::MouseWheelCal
if(c.mouseWheel) c.mouseWheel(this, wheel);
}
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);
}
void LayoutElement::input_key_callback(const InputManager::KeyCallbackArgs& key) {
if(c.key) c.key(this, key);
}

View file

@ -10,12 +10,17 @@ class LayoutElement : public Element {
std::function<void(LayoutElement* l, const InputManager::MouseButtonCallbackArgs& button)> mouseButton;
std::function<void(LayoutElement* l, const InputManager::MouseMotionCallbackArgs& motion)> mouseMotion;
std::function<void(LayoutElement* l, const InputManager::MouseWheelCallbackArgs& wheel)> mouseWheel;
std::function<void(LayoutElement* l, const InputManager::FingerTouchCallbackArgs& touch)> fingerTouch;
std::function<void(LayoutElement* l, const InputManager::FingerMotionCallbackArgs& motion)> fingerMotion;
std::function<void(LayoutElement* l, const InputManager::MouseButtonCallbackArgs& button)> onClick;
std::function<void(LayoutElement* l, const InputManager::KeyCallbackArgs& key)> key;
};
void layout(const Clay_ElementId& id, const std::function<void(LayoutElement*, const Clay_ElementId&)>& layout, const Callbacks& c = {});
virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) override;
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) override;
virtual void input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel) override;
virtual void input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch) override;
virtual void input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion) override;
virtual void input_key_callback(const InputManager::KeyCallbackArgs& key) override;
private:
Callbacks c;