Skip to content

Commit a3264ac

Browse files
committed
disable pan button when at min zoom
1 parent 22b47dc commit a3264ac

File tree

6 files changed

+42
-12
lines changed

6 files changed

+42
-12
lines changed

js/app/vite.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ const CDN_BASE = "https://gradio.s3-us-west-2.amazonaws.com";
3232
export default defineConfig(({ mode }) => {
3333
const production = mode === "production";
3434
const development = mode === "development";
35-
console.log(mode);
3635
return {
3736
// plugins: [],
3837
server: {

js/imageeditor/shared/Controls.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
export let current_zoom = 1;
2929
export let dimensions: Spring<{ width: number; height: number }>;
3030
export let tool: string;
31+
export let min_zoom = true;
3132
const dispatch = createEventDispatcher<{
3233
/**
3334
* Remove the current image.
@@ -87,6 +88,8 @@
8788
8889
$: formatted_zoom = Math.round(current_zoom * 100);
8990
let show_resize_popup = false;
91+
92+
$: console.log(min_zoom);
9093
</script>
9194

9295
<IconButtonWrapper>
@@ -101,6 +104,7 @@
101104
size="small"
102105
padded={false}
103106
transparent={true}
107+
disabled={min_zoom}
104108
/>
105109

106110
<IconButton

js/imageeditor/shared/ImageEditor.svelte

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
let zoom_level = 1;
180180
let ready = false;
181181
let mounted = false;
182+
let min_zoom = true;
182183
183184
onMount(() => {
184185
mounted = true;
@@ -221,6 +222,10 @@
221222
zoom_level = _scale;
222223
});
223224
225+
editor.min_zoom.subscribe((is_min_zoom) => {
226+
min_zoom = is_min_zoom;
227+
});
228+
224229
Promise.all([editor.ready, crop.ready]).then(() => {
225230
handle_tool_change({ tool: "image" });
226231
ready = true;
@@ -233,9 +238,6 @@
233238
});
234239
}
235240
236-
// $: mounted && (canvas_size, init_image_editor());
237-
// $: ready && resize_canvas(canvas_size[0], canvas_size[1]);
238-
239241
function resize_canvas(width: number, height: number): void {
240242
if (!editor) return;
241243
if (mounted && ready) {
@@ -447,6 +449,7 @@
447449
on:set_zoom={(e) => handle_zoom_change(e.detail)}
448450
on:zoom_in={() => zoom_in_out("in")}
449451
on:zoom_out={() => zoom_in_out("out")}
452+
{min_zoom}
450453
current_zoom={zoom_level}
451454
on:remove_image={() => {
452455
editor.reset_canvas();

js/imageeditor/shared/core/editor.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,10 @@ class EditorState {
900900
}
901901

902902
export class ImageEditor {
903+
public ready: Promise<void>;
904+
public background_image_present = writable(false);
905+
public min_zoom = writable(true);
906+
903907
private app!: Application;
904908
private ui_container!: Container;
905909
private image_container!: Container;
@@ -931,14 +935,13 @@ export class ImageEditor {
931935
private outline_container!: Container;
932936
private outline_graphics!: Graphics;
933937
private background_image?: Sprite;
934-
public background_image_present = writable(false);
935938
private ready_resolve!: (value: void | PromiseLike<void>) => void;
936-
public ready: Promise<void>;
937939
private event_callbacks: Map<string, (() => void)[]> = new Map();
938940
private fixed_canvas: boolean;
939941
private dark: boolean;
940942
private border_region: number;
941943
private layer_options: LayerOptions;
944+
942945
constructor(options: ImageEditorOptions) {
943946
this.dark = options.dark || false;
944947
this.target_element = options.target_element;
@@ -978,7 +981,8 @@ export class ImageEditor {
978981
this.border_region = options.border_region || 0;
979982
this.layer_options = options.layer_options || {
980983
allow_additional_layers: true,
981-
layers: ["Layer 1"]
984+
layers: ["Layer 1"],
985+
disabled: false
982986
};
983987
this.scale.subscribe((scale) => {
984988
this.state._set_scale(scale);
@@ -1050,6 +1054,13 @@ export class ImageEditor {
10501054
await tool.setup(this.context, this.current_tool, this.current_subtool);
10511055
}
10521056

1057+
const zoom = this.tools.get("zoom") as ZoomTool;
1058+
if (zoom) {
1059+
zoom.min_zoom.subscribe((is_min_zoom) => {
1060+
this.min_zoom.set(is_min_zoom);
1061+
});
1062+
}
1063+
10531064
this.target_element.appendChild(canvas);
10541065

10551066
// Ensure parent element is transparent
@@ -1350,6 +1361,15 @@ export class ImageEditor {
13501361
tool.setup(this.context, this.current_tool, this.current_subtool);
13511362
}
13521363

1364+
const zoom_tool = this.tools.get("zoom") as ZoomTool;
1365+
if (zoom_tool) {
1366+
console.log("zoom_tool", zoom_tool);
1367+
zoom_tool.min_zoom.subscribe((is_min_zoom) => {
1368+
console.log("is_min_zoom", is_min_zoom);
1369+
this.min_zoom.set(is_min_zoom);
1370+
});
1371+
}
1372+
13531373
this.notify("change");
13541374
}
13551375

js/imageeditor/shared/image/image.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,11 @@ export class AddImageCommand implements BgImageCommand {
333333
// Instead, we'll store the border region on the sprite and let the resize tool
334334
// read it when it's set up
335335

336-
this.context.layer_manager.create_layer(
337-
this.fixed_canvas ? this.current_canvas_size.width : width,
338-
this.fixed_canvas ? this.current_canvas_size.height : height
339-
);
336+
this.context.layer_manager.create_layer({
337+
width: this.fixed_canvas ? this.current_canvas_size.width : width,
338+
height: this.fixed_canvas ? this.current_canvas_size.height : height,
339+
user_created: true
340+
});
340341
this.context.reset();
341342
}
342343

js/imageeditor/shared/zoom/zoom.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import {
55
} from "pixi.js";
66
import { type ImageEditorContext, type Tool } from "../core/editor";
77
import { type Tool as ToolbarTool, type Subtool } from "../Toolbar.svelte";
8-
import { get } from "svelte/store";
8+
import { get, writable } from "svelte/store";
99

1010
/**
1111
* ZoomTool class for handling zoom and pan functionality in the image editor
1212
* Implements the Tool interface
1313
*/
1414
export class ZoomTool implements Tool {
1515
name = "zoom";
16+
min_zoom = writable(true);
17+
1618
private image_editor_context!: ImageEditorContext;
1719

1820
// Constants
@@ -596,6 +598,7 @@ export class ZoomTool implements Tool {
596598
position: new_position,
597599
animate: typeof hard === "boolean" ? !hard : new_zoom === min_zoom
598600
});
601+
this.min_zoom.set(new_zoom === min_zoom);
599602
}
600603

601604
/**

0 commit comments

Comments
 (0)