Handles touch input integration for Canvas. More...
#include <canvas_touch_handler.h>

Classes | |
| struct | Config |
| Configuration for canvas touch behavior. More... | |
Public Member Functions | |
| CanvasTouchHandler ()=default | |
| void | Initialize (const std::string &canvas_id="") |
| Initialize the touch handler. | |
| void | Update () |
| Update touch state each frame. | |
| bool | IsTouchActive () const |
| Check if touch input is currently active. | |
| bool | IsTouchMode () const |
| Check if we're in touch mode (vs mouse) | |
| ImVec2 | GetScrollOffset () const |
| Get the current scroll/pan offset for the canvas. | |
| float | GetScale () const |
| Get the current zoom scale. | |
| ImVec2 | GetZoomCenter () const |
| Get the zoom center point (for pivot-based zooming) | |
| void | SetScrollOffset (ImVec2 offset) |
| Set the scroll offset (e.g., from Canvas state) | |
| void | SetScale (float scale) |
| Set the zoom scale. | |
| void | ApplyScrollDelta (ImVec2 delta) |
| Apply a scroll delta (add to current offset) | |
| void | ApplyZoomDelta (float delta, ImVec2 center) |
| Apply a zoom delta around a center point. | |
| void | Reset () |
| Reset to default state (no pan, 1.0 scale) | |
| Config & | GetConfig () |
| Get configuration reference for modification. | |
| const Config & | GetConfig () const |
| bool | WasTapped () const |
| Check if a tap gesture occurred this frame. | |
| bool | WasDoubleTapped () const |
| Check if a double-tap gesture occurred this frame. | |
| bool | WasLongPressed () const |
| Check if a long-press gesture occurred this frame. | |
| ImVec2 | GetGesturePosition () const |
| Get the position of the last tap/gesture. | |
| void | ProcessForCanvas (ImVec2 canvas_p0, ImVec2 canvas_sz, bool is_hovered) |
| Process touch gestures for the current canvas bounds. | |
Private Member Functions | |
| void | ProcessGesture (const GestureState &gesture) |
| void | ProcessInertia () |
| void | ClampPanToBounds () |
Private Attributes | |
| std::string | canvas_id_ |
| Config | config_ |
| ImVec2 | scroll_offset_ = ImVec2(0, 0) |
| float | current_scale_ = 1.0f |
| float | target_scale_ = 1.0f |
| ImVec2 | zoom_center_ = ImVec2(0, 0) |
| ImVec2 | inertia_velocity_ = ImVec2(0, 0) |
| bool | inertia_active_ = false |
| bool | was_tapped_ = false |
| bool | was_double_tapped_ = false |
| bool | was_long_pressed_ = false |
| ImVec2 | gesture_position_ = ImVec2(0, 0) |
| ImVec2 | canvas_p0_ = ImVec2(0, 0) |
| ImVec2 | canvas_sz_ = ImVec2(0, 0) |
| bool | canvas_hovered_ = false |
| ImVec2 | prev_pan_offset_ = ImVec2(0, 0) |
| float | prev_scale_ = 1.0f |
Handles touch input integration for Canvas.
Bridges the TouchInput system with Canvas pan/zoom/interaction. Translates touch gestures into canvas operations and maintains smooth integration with mouse-based controls.
Usage:
Definition at line 32 of file canvas_touch_handler.h.
|
default |
| void yaze::gui::CanvasTouchHandler::Initialize | ( | const std::string & | canvas_id = "" | ) |
Initialize the touch handler.
| canvas_id | Canvas identifier for unique state tracking |
Definition at line 9 of file canvas_touch_handler.cc.
References canvas_id_, yaze::gui::TouchInput::Initialize(), and Reset().

| void yaze::gui::CanvasTouchHandler::Update | ( | ) |
Update touch state each frame.
Call this once per frame before accessing touch state. Processes touch events and updates pan/zoom values.
Definition at line 17 of file canvas_touch_handler.cc.
References canvas_hovered_, ClampPanToBounds(), config_, current_scale_, yaze::gui::CanvasTouchHandler::Config::enable_smooth_zoom, yaze::gui::TouchInput::GetCurrentGesture(), inertia_active_, yaze::gui::TouchInput::IsTouchActive(), yaze::gui::kNone, yaze::gui::CanvasTouchHandler::Config::max_pan_x, yaze::gui::CanvasTouchHandler::Config::max_pan_y, prev_pan_offset_, prev_scale_, ProcessGesture(), ProcessInertia(), scroll_offset_, target_scale_, was_double_tapped_, was_long_pressed_, was_tapped_, and yaze::gui::CanvasTouchHandler::Config::zoom_smoothing.
| bool yaze::gui::CanvasTouchHandler::IsTouchActive | ( | ) | const |
Check if touch input is currently active.
Definition at line 53 of file canvas_touch_handler.cc.
References yaze::gui::TouchInput::IsTouchActive().

| bool yaze::gui::CanvasTouchHandler::IsTouchMode | ( | ) | const |
Check if we're in touch mode (vs mouse)
Definition at line 57 of file canvas_touch_handler.cc.
References yaze::gui::TouchInput::IsTouchMode().

|
inline |
Get the current scroll/pan offset for the canvas.
Definition at line 91 of file canvas_touch_handler.h.
References scroll_offset_.
|
inline |
Get the current zoom scale.
Definition at line 96 of file canvas_touch_handler.h.
References current_scale_.
|
inline |
Get the zoom center point (for pivot-based zooming)
Definition at line 101 of file canvas_touch_handler.h.
References zoom_center_.
| void yaze::gui::CanvasTouchHandler::SetScrollOffset | ( | ImVec2 | offset | ) |
Set the scroll offset (e.g., from Canvas state)
Definition at line 61 of file canvas_touch_handler.cc.
References prev_pan_offset_, and scroll_offset_.
| void yaze::gui::CanvasTouchHandler::SetScale | ( | float | scale | ) |
Set the zoom scale.
Definition at line 66 of file canvas_touch_handler.cc.
References config_, current_scale_, yaze::gui::CanvasTouchHandler::Config::max_scale, yaze::gui::CanvasTouchHandler::Config::min_scale, prev_scale_, and target_scale_.
| void yaze::gui::CanvasTouchHandler::ApplyScrollDelta | ( | ImVec2 | delta | ) |
Apply a scroll delta (add to current offset)
Definition at line 72 of file canvas_touch_handler.cc.
References scroll_offset_.
| void yaze::gui::CanvasTouchHandler::ApplyZoomDelta | ( | float | delta, |
| ImVec2 | center ) |
Apply a zoom delta around a center point.
Definition at line 77 of file canvas_touch_handler.cc.
References config_, yaze::gui::CanvasTouchHandler::Config::max_scale, yaze::gui::CanvasTouchHandler::Config::min_scale, scroll_offset_, target_scale_, and zoom_center_.
| void yaze::gui::CanvasTouchHandler::Reset | ( | ) |
Reset to default state (no pan, 1.0 scale)
Definition at line 94 of file canvas_touch_handler.cc.
References current_scale_, inertia_active_, inertia_velocity_, prev_pan_offset_, prev_scale_, yaze::gui::TouchInput::ResetCanvasState(), scroll_offset_, target_scale_, and zoom_center_.
Referenced by Initialize().

|
inline |
Get configuration reference for modification.
Definition at line 131 of file canvas_touch_handler.h.
References config_.
|
inline |
Definition at line 132 of file canvas_touch_handler.h.
References config_.
|
inline |
Check if a tap gesture occurred this frame.
Definition at line 137 of file canvas_touch_handler.h.
References was_tapped_.
|
inline |
Check if a double-tap gesture occurred this frame.
Definition at line 142 of file canvas_touch_handler.h.
References was_double_tapped_.
|
inline |
Check if a long-press gesture occurred this frame.
Definition at line 147 of file canvas_touch_handler.h.
References was_long_pressed_.
|
inline |
Get the position of the last tap/gesture.
Definition at line 152 of file canvas_touch_handler.h.
References gesture_position_.
| void yaze::gui::CanvasTouchHandler::ProcessForCanvas | ( | ImVec2 | canvas_p0, |
| ImVec2 | canvas_sz, | ||
| bool | is_hovered ) |
Process touch gestures for the current canvas bounds.
| canvas_p0 | Canvas top-left position in screen coordinates |
| canvas_sz | Canvas size |
| is_hovered | Whether mouse/touch is over the canvas |
Definition at line 108 of file canvas_touch_handler.cc.
References canvas_hovered_, canvas_p0_, and canvas_sz_.
|
private |
Definition at line 115 of file canvas_touch_handler.cc.
References canvas_p0_, config_, current_scale_, yaze::gui::CanvasTouchHandler::Config::enable_inertia, yaze::gui::CanvasTouchHandler::Config::enable_pan, yaze::gui::CanvasTouchHandler::Config::enable_zoom, yaze::gui::GestureState::gesture, gesture_position_, yaze::gui::TouchInput::GetPanOffset(), yaze::gui::TouchInput::GetZoomCenter(), yaze::gui::TouchInput::GetZoomLevel(), inertia_active_, yaze::gui::CanvasTouchHandler::Config::inertia_min_velocity, inertia_velocity_, yaze::gui::kBegan, yaze::gui::kChanged, yaze::gui::kDoubleTap, yaze::gui::kEnded, yaze::gui::kLongPress, yaze::gui::kNone, yaze::gui::kPan, yaze::gui::kPinchZoom, yaze::gui::kRotate, yaze::gui::kTap, yaze::gui::CanvasTouchHandler::Config::max_scale, yaze::gui::CanvasTouchHandler::Config::min_scale, yaze::gui::GestureState::phase, yaze::gui::GestureState::position, prev_pan_offset_, prev_scale_, scroll_offset_, target_scale_, yaze::gui::GestureState::velocity, was_double_tapped_, was_long_pressed_, was_tapped_, and zoom_center_.
Referenced by Update().

|
private |
Definition at line 218 of file canvas_touch_handler.cc.
References config_, inertia_active_, yaze::gui::CanvasTouchHandler::Config::inertia_deceleration, yaze::gui::CanvasTouchHandler::Config::inertia_min_velocity, inertia_velocity_, and scroll_offset_.
Referenced by Update().
|
private |
Definition at line 238 of file canvas_touch_handler.cc.
References config_, yaze::gui::CanvasTouchHandler::Config::max_pan_x, yaze::gui::CanvasTouchHandler::Config::max_pan_y, yaze::gui::CanvasTouchHandler::Config::min_pan_x, yaze::gui::CanvasTouchHandler::Config::min_pan_y, and scroll_offset_.
Referenced by Update().
|
private |
Definition at line 168 of file canvas_touch_handler.h.
Referenced by Initialize().
|
private |
Definition at line 169 of file canvas_touch_handler.h.
Referenced by ApplyZoomDelta(), ClampPanToBounds(), GetConfig(), GetConfig(), ProcessGesture(), ProcessInertia(), SetScale(), and Update().
|
private |
Definition at line 172 of file canvas_touch_handler.h.
Referenced by ApplyScrollDelta(), ApplyZoomDelta(), ClampPanToBounds(), GetScrollOffset(), ProcessGesture(), ProcessInertia(), Reset(), SetScrollOffset(), and Update().
|
private |
Definition at line 173 of file canvas_touch_handler.h.
Referenced by GetScale(), ProcessGesture(), Reset(), SetScale(), and Update().
|
private |
Definition at line 174 of file canvas_touch_handler.h.
Referenced by ApplyZoomDelta(), ProcessGesture(), Reset(), SetScale(), and Update().
|
private |
Definition at line 175 of file canvas_touch_handler.h.
Referenced by ApplyZoomDelta(), GetZoomCenter(), ProcessGesture(), and Reset().
|
private |
Definition at line 178 of file canvas_touch_handler.h.
Referenced by ProcessGesture(), ProcessInertia(), and Reset().
|
private |
Definition at line 179 of file canvas_touch_handler.h.
Referenced by ProcessGesture(), ProcessInertia(), Reset(), and Update().
|
private |
Definition at line 182 of file canvas_touch_handler.h.
Referenced by ProcessGesture(), Update(), and WasTapped().
|
private |
Definition at line 183 of file canvas_touch_handler.h.
Referenced by ProcessGesture(), Update(), and WasDoubleTapped().
|
private |
Definition at line 184 of file canvas_touch_handler.h.
Referenced by ProcessGesture(), Update(), and WasLongPressed().
|
private |
Definition at line 185 of file canvas_touch_handler.h.
Referenced by GetGesturePosition(), and ProcessGesture().
|
private |
Definition at line 188 of file canvas_touch_handler.h.
Referenced by ProcessForCanvas(), and ProcessGesture().
|
private |
Definition at line 189 of file canvas_touch_handler.h.
Referenced by ProcessForCanvas().
|
private |
Definition at line 190 of file canvas_touch_handler.h.
Referenced by ProcessForCanvas(), and Update().
|
private |
Definition at line 193 of file canvas_touch_handler.h.
Referenced by ProcessGesture(), Reset(), SetScrollOffset(), and Update().
|
private |
Definition at line 194 of file canvas_touch_handler.h.
Referenced by ProcessGesture(), Reset(), SetScale(), and Update().