From f32146b3f3607b32092df8372043174887f95eda Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 26 Mar 2026 21:28:04 +0800 Subject: [PATCH] compact resize ratio picker --- components/image-annotator.tsx | 64 ++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/components/image-annotator.tsx b/components/image-annotator.tsx index 94dac75e7..715542b09 100644 --- a/components/image-annotator.tsx +++ b/components/image-annotator.tsx @@ -5,7 +5,7 @@ import { createPortal } from "react-dom"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useTheme } from "next-themes"; -import { X, Check, Undo, Trash2, Scissors, Sparkles, Download, Expand, Move, Maximize2, ZoomIn, ZoomOut, Loader2, Move3D, Layers, Upload as UploadIcon, Image as ImageIcon, Droplet, Redo, MousePointer2 } from "lucide-react"; +import { X, Check, Undo, Trash2, Scissors, Sparkles, Download, Expand, Move, Maximize2, ZoomIn, ZoomOut, Loader2, Move3D, Layers, Upload as UploadIcon, Image as ImageIcon, Droplet, Redo, MousePointer2, ChevronDown } from "lucide-react"; import { Button } from "./ui/button"; import { Input } from "./ui/input"; import { Slider } from "./ui/slider"; @@ -20,6 +20,7 @@ import { DialogDescription, } from "@/components/ui/dialog"; import { cn } from "@/lib/utils"; +import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { Tooltip, TooltipContent, @@ -327,6 +328,7 @@ export function ImageAnnotator({ const [dragStart, setDragStart] = useState<{ x: number; y: number } | null>(null); const [selectedAspectRatio, setSelectedAspectRatio] = useState(null); // 选中的比例,null表示自定义 const [isResizing, setIsResizing] = useState(false); // 尺寸调整处理中状态 + const [resizeRatioPickerOpen, setResizeRatioPickerOpen] = useState(false); const resizeCanvasRef = useRef(null); const resizeContainerRef = useRef(null); @@ -400,6 +402,10 @@ export function ImageAnnotator({ } }; + const currentAspectRatioLabel = + aspectRatios.find((ratio) => ratio.value === selectedAspectRatio)?.label || + (selectedAspectRatio ? selectedAspectRatio : "自定义"); + const handleResizeQuickPresetSelect = ( preset: (typeof resizeQuickPresets)[number] ) => { @@ -1737,26 +1743,48 @@ export function ImageAnnotator({
-
- {aspectRatios.map((ratio) => ( + + - ))} -
+ + +
+ 选择画布比例 +
+
+ {aspectRatios.map((ratio) => ( + + ))} +
+
+