Thanks to visit codestin.com
Credit goes to github.com

Skip to content

v1: improve events#5516

Merged
FeodorFitsner merged 7 commits intomainfrom
improve-events
Aug 4, 2025
Merged

v1: improve events#5516
FeodorFitsner merged 7 commits intomainfrom
improve-events

Conversation

@ndonkoHenri
Copy link
Contributor

@ndonkoHenri ndonkoHenri commented Aug 3, 2025

Closes #825

Test code

def main(page: ft.Page):
    def on_pan_update(e: ft.DragUpdateEvent):
        page.window.left += e.global_delta.x
        page.window.top += e.global_delta.y
        page.update()

    page.add(
        ft.Stack(
            width=1000,
            height=500,
            controls=[
                ft.GestureDetector(
                    mouse_cursor=ft.MouseCursor.MOVE,
                    on_pan_update=on_pan_update,
                    left=200,
                    top=200,
                    content=ft.Container(bgcolor=ft.Colors.PINK, width=50, height=50),
                ),
            ],
        )
    )

Summary by Sourcery

Refactor event handling to unify positional, delta, and velocity data into composite Offset structures across Python and Dart, simplify serialization to nested x/y maps, and update gesture detector to track state using Offset.

Enhancements:

  • Replace individual x/y numeric fields in Python event classes with unified local_position, global_position, velocity, and delta Offset fields and enrich with docstrings
  • Restructure Dart extension toMap methods to emit nested x/y maps (keys l, g, v, ld, gd, sd, etc) instead of flat fields
  • Refactor GestureDetectorControl state in Dart to use Offset objects for pan, drag, and hover tracking and pass previous offsets to toMap calls

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Aug 3, 2025

Deploying flet-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5caecdb
Status: ✅  Deploy successful!
Preview URL: https://37737696.flet-docs.pages.dev
Branch Preview URL: https://improve-events.flet-docs.pages.dev

View logs

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the event handling system to improve the structure and consistency of position and delta data across Python and Dart implementations. The changes replace individual x/y coordinate fields with unified Offset objects and restructure serialization to use nested coordinate maps.

  • Unifies positional data into Offset objects with proper type annotations and comprehensive docstrings
  • Changes Dart serialization from flat coordinate fields to nested x/y maps for better structure
  • Updates GestureDetector state tracking to use Offset objects instead of separate x/y variables

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
sdk/python/packages/flet/tests/test_events.py Updates test assertions to use new Offset-based event structure and nested coordinate maps
sdk/python/packages/flet/src/flet/controls/events.py Replaces individual x/y fields with Offset objects and adds comprehensive docstrings for all event classes
packages/flet/lib/src/utils/events.dart Converts flat coordinate serialization to nested x/y maps and updates method signatures
packages/flet/lib/src/controls/gesture_detector.dart Refactors state variables from separate x/y coordinates to Offset objects
Comments suppressed due to low confidence (2)

sdk/python/packages/flet/src/flet/controls/events.py:193

  • The field name 'global_focal_point_x' suggests it contains only x-coordinate data, but it's typed as Offset which contains both x and y coordinates. It should be named 'global_focal_point' to match its type and usage.
    global_focal_point_x: Offset = field(metadata={"data_field": "gfp"})

packages/flet/lib/src/utils/events.dart:119

  • The _globalPan variable is being assigned details.localPosition instead of details.globalPosition. This will result in incorrect global position tracking.
      "l": {"x": localPosition.dx, "y": localPosition.dy},


local_delta: Optional[Offset] = field(default=None, metadata={"data_field": "ld"})
"""

Copy link

Copilot AI Aug 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring for local_delta is empty. It should describe what this field represents, similar to other documented fields in the class.

Suggested change
The amount the pointer has moved in the local coordinate space of the event receiver
since the previous update. May be `None` if not provided by the event source.

Copilot uses AI. Check for mistakes.

local_delta: Optional[Offset] = field(default=None, metadata={"data_field": "ld"})
"""

Copy link

Copilot AI Aug 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring for local_delta in PointerEvent is empty. It should describe what this field represents, similar to other documented fields in the class.

Suggested change
The change in the pointer's position in the local coordinate space since the last event,
in logical pixels. May be None if not applicable.

Copilot uses AI. Check for mistakes.
Co-authored-by: Feodor Fitsner <[email protected]>
@FeodorFitsner FeodorFitsner merged commit 3be9b20 into main Aug 4, 2025
3 checks passed
@FeodorFitsner FeodorFitsner deleted the improve-events branch August 4, 2025 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants