Untitled conversation
- User
# src/tests/test_manual_crop.py import flet as ft from configs.path_config import EXAMPLE_IMAGE def main(page: ft.Page): # 初期サイズや位置 rect_left = 50 rect_top = 50 rect_width = 200 rect_height = 150 # 再描画用 rect_container = ft.Ref[ft.Container]() # ドラッグで矩形サイズを変更する def on_pan_update(e: ft.DragUpdateEvent): nonlocal rect_width, rect_height # 右下の角をドラッグしてサイズ変更 rect_width += e.delta_x rect_height += e.delta_y # 最小サイズ制限 if rect_width < 20: rect_width = 20 if rect_height < 20: rect_height = 20 rect_container.current.width = rect_width rect_container.current.height = rect_height page.update() # Stackで画像と矩形を重ねる stack = ft.Stack( [ # 背景画像 ft.Image( src=EXAMPLE_IMAGE, width=400, height=300, fit=ft.ImageFit.CONTAIN, ), # 矩形(白抜き) ft.Container( ref=rect_container, left=rect_left, top=rect_top, width=rect_width, height=rect_height, border=ft.border.all(3, ft.Colors.WHITE), bgcolor=None, # 右下角でドラッグ可能にする content=ft.GestureDetector( mouse_cursor=ft.MouseCursor.RESIZE_UP, drag_interval=1, on_pan_update=on_pan_update, # 右下角にだけ配置 content=ft.Container( width=16, height=16, right=0, bottom=0, alignment=ft.alignment.bottom_right, bgcolor=ft.Colors.WHITE54, border_radius=8, ), ), ) ], width=400, height=300, ) page.add(stack) ft.app(target=main)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.