Skip to content

bug: The on_interaction_update event of the InteractiveViewer component has an error in the data returned #6469

@Qye-Leisure

Description

@Qye-Leisure

Duplicate Check

Describe the bug

In the ft.InteractiveViewer() component, if interaction_update_interval is set to 200 milliseconds, the returned data should include all events that occurred within that interval. For example, if I trigger three scroll wheel events within 200 milliseconds, it should return the cumulative result of those three scroll events. However, Flet actually returns the data for only one event. To get correct data, you need to set interaction_update_interval to 0, but this causes significant performance overhead.

Code sample

Code
import flet as ft
from typing import  cast


@ft.control
class BaseCanvas(ft.GestureDetector):
    max_scale: float = 3
    scale_step: float = 0.25
    min_scale: float = 0.25

    def init(self):
        self.cumulative_offset_x = self.cumulative_offset_y = 0
        self.current_scale = 1

        self.window_container_size = ()
        self.canvas_size=()
        
        
        self.scaled_canvas_size = ()
        self.scale_offset_x = 0
        self.scale_offset_y = 0

        self.canvas_container = ft.Container(
            bgcolor=ft.Colors.BLUE_100,
            content=ft.Stack(
                controls=[
                    self.module_container((50, 50)),
                    self.module_container((50, 600)),
                    self.module_container((1000, 50)),
                    self.module_container((1000, 600)),
                ],
            ),
        )

        self.content = ft.InteractiveViewer(
            expand=True,
            clip_behavior= ft.ClipBehavior.HARD_EDGE,
            content=self.canvas_container,
            on_size_change = lambda e: self.get_window_container_size(e),
            constrained = False,
            on_interaction_update=lambda e:  print(e),

        )


        self.on_hover = self.mouse_hover_event

    def module_container(self, pos):
        module = ft.Container(
            bgcolor=ft.Colors.GREEN,
            width=70,
            content=ft.Column(
                [
                    ft.Container(width=70, content=ft.Text(f"module {j}"))
                    for j in range(10)
                ]
            ),
        )

        return ft.GestureDetector(
            mouse_cursor=ft.MouseCursor.MOVE,
            drag_interval=5,
            left=pos[0],
            top=pos[1],
            content=module,
        )

    def get_window_container_size(self, e):

        self.window_container_size = (e.width, e.height)
        if not self.canvas_size or self.canvas_size<self.window_container_size:
            self.canvas_size=self.window_container_size


            self.canvas_container.width,self.canvas_container.height=self.window_container_size
            self.canvas_container=cast(ft.Container,self.canvas_container)
            self.canvas_container.update()
        print(self.window_container_size)

    def mouse_hover_event(self, e: ft.HoverEvent[ft.GestureDetector]) -> None:
        """Handle mouse hover, compute canvas coordinates"""
        if e.local_delta is None:
            return







if __name__ == "__main__":

    def main(page: ft.Page):
        canvas = BaseCanvas()
        page.add(
            ft.Container(expand=True,bgcolor=ft.Colors.AMBER, content=canvas),
        )

    ft.run(main)

To reproduce

  1. Run the code
  2. Scale to the maximum size
  3. Observe the scale data returned by the on_interaction_update event.

Expected behavior

No response

Screenshots / Videos

Captures

[Upload media here]

Operating System

Windows

Operating system details

11

Flet version

0.85

Regression

No, it isn't

Suggestions

No response

Logs

Logs
[Paste your logs here]

Additional details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions