Skip to content

Commit

Permalink
Allow full screen mode in interactive gr.Image (#10054)
Browse files Browse the repository at this point in the history
* allow full screen mode in interactive image

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
  • Loading branch information
3 people authored Nov 27, 2024
1 parent 5d36c80 commit 458941c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 30 deletions.
6 changes: 6 additions & 0 deletions .changeset/dirty-cloths-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@gradio/image": minor
"gradio": minor
---

feat:Allow full screen mode in interactive gr.Image
18 changes: 0 additions & 18 deletions js/image/shared/ClearImage.svelte

This file was deleted.

55 changes: 43 additions & 12 deletions js/image/shared/ImageUploader.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { createEventDispatcher, tick } from "svelte";
import { BlockLabel } from "@gradio/atoms";
import { Image as ImageIcon } from "@gradio/icons";
import { BlockLabel, IconButtonWrapper, IconButton } from "@gradio/atoms";
import { Clear, Image as ImageIcon, Maximize, Minimize } from "@gradio/icons";
import {
type SelectData,
type I18nFormatter,
Expand All @@ -12,7 +12,6 @@
import { Upload } from "@gradio/upload";
import { FileData, type Client } from "@gradio/client";
import ClearImage from "./ClearImage.svelte";
import { SelectSource } from "@gradio/atoms";
import Image from "./Image.svelte";
import type { Base64File } from "./types";
Expand All @@ -37,6 +36,7 @@
export let modify_stream: (state: "open" | "closed" | "waiting") => void;
export let set_time_limit: (arg0: number) => void;
export let show_fullscreen_button = true;
let upload_input: Upload;
export let uploading = false;
Expand Down Expand Up @@ -119,19 +119,50 @@
break;
}
}
let is_full_screen = false;
let image_container: HTMLElement;
const toggle_full_screen = async (): Promise<void> => {
if (!is_full_screen) {
await image_container.requestFullscreen();
} else {
await document.exitFullscreen();
is_full_screen = !is_full_screen;
}
};
</script>

<BlockLabel {show_label} Icon={ImageIcon} label={label || "Image"} />

<div data-testid="image" class="image-container">
{#if value?.url && !active_streaming}
<ClearImage
on:remove_image={() => {
value = null;
dispatch("clear");
}}
/>
{/if}
<div data-testid="image" class="image-container" bind:this={image_container}>
<IconButtonWrapper>
{#if value?.url && !active_streaming}
{#if !is_full_screen && show_fullscreen_button}
<IconButton
Icon={Maximize}
label={is_full_screen ? "Exit full screen" : "View in full screen"}
on:click={toggle_full_screen}
/>
{/if}
{#if is_full_screen && show_fullscreen_button}
<IconButton
Icon={Minimize}
label={is_full_screen ? "Exit full screen" : "View in full screen"}
on:click={toggle_full_screen}
/>
{/if}
<IconButton
Icon={Clear}
label="Remove Image"
on:click={(event) => {
value = null;
dispatch("clear");
event.stopPropagation();
}}
/>
{/if}
</IconButtonWrapper>
<div
class="upload-container"
class:reduced-height={sources.length > 1}
Expand Down

0 comments on commit 458941c

Please sign in to comment.