More region widget fixes

This commit is contained in:
space-nuko
2023-05-23 17:29:33 -05:00
parent e3c73ce18a
commit a3d4e4bca7
8 changed files with 68 additions and 23 deletions

View File

@@ -15,7 +15,6 @@
import { generateBlankCanvas, generateImageCanvas, loadImage } from "./utils";
import { clamp } from "$lib/utils";
import Row from "$lib/components/gradio/app/Row.svelte";
import Column from "$lib/components/gradio/app/Column.svelte";
// ref: https://html-color.codes/
const COLOR_MAP: [string, string][] = [
@@ -400,6 +399,10 @@ const COLOR_MAP: [string, string][] = [
displayBoxes = await recreateDisplayBoxes();
}
function updateSelectedIndex(newIndexPlusOne: number) {
selectedIndex = clamp(newIndexPlusOne - 1, 0, $nodeValue.length - 1);
}
function updateX(newX: number) {
const bbox = $nodeValue[selectedIndex]
const dbox = displayBoxes[selectedIndex]
@@ -440,7 +443,7 @@ const COLOR_MAP: [string, string][] = [
displayBoxes[selectedIndex] = displayBoundingBox(bbox, selectedIndex, imageElem, dbox);
}
function updateValue() {
async function updateValue() {
// Clamp regions
const bbox = $nodeValue[selectedIndex]
const dbox = displayBoxes[selectedIndex]
@@ -452,6 +455,8 @@ const COLOR_MAP: [string, string][] = [
displayBoxes[selectedIndex] = displayBoundingBox(bbox, selectedIndex, imageElem, dbox);
}
await updateImageAndDBoxes();
// Force reactivity after changing a bbox's internal values
$nodeValue = $nodeValue
}
@@ -504,6 +509,13 @@ const COLOR_MAP: [string, string][] = [
</div>
{#if selectedBBox}
<Block>
<Row>
<Range label="Region #" value={selectedIndex+1}
show_label={true} minimum={1} maximum={$nodeValue.length} step={1}
on:change={(e) => updateSelectedIndex(e.detail)}
on:release={updateValue}
/>
</Row>
<Row>
<Range label="X" value={selectedBBox[0]}
show_label={true} minimum={0.0} maximum={1.0} step={0.01}