fix(ui): tool preview/cursor when non-interactable layer selected

This commit is contained in:
psychedelicious 2024-04-30 12:29:35 +10:00 committed by Kent Keirsey
parent 720e16cea6
commit ace3955760
3 changed files with 26 additions and 2 deletions

View File

@ -1,5 +1,6 @@
import { Flex } from '@invoke-ai/ui-library';
import { useStore } from '@nanostores/react';
import { createSelector } from '@reduxjs/toolkit';
import { logger } from 'app/logging/logger';
import { createMemoizedSelector } from 'app/store/createMemoizedSelector';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
@ -33,6 +34,11 @@ const selectSelectedLayerColor = createMemoizedSelector(selectRegionalPromptsSli
return layer?.previewColor ?? null;
});
const selectSelectedLayerType = createSelector(selectRegionalPromptsSlice, (regionalPrompts) => {
const selectedLayer = regionalPrompts.present.layers.find((l) => l.id === regionalPrompts.present.selectedLayerId);
return selectedLayer?.type ?? null;
});
const useStageRenderer = (
stage: Konva.Stage,
container: HTMLDivElement | null,
@ -47,6 +53,7 @@ const useStageRenderer = (
const lastMouseDownPos = useStore($lastMouseDownPos);
const isMouseOver = useStore($isMouseOver);
const selectedLayerIdColor = useAppSelector(selectSelectedLayerColor);
const selectedLayerType = useAppSelector(selectSelectedLayerType);
const layerIds = useMemo(() => state.layers.map((l) => l.id), [state.layers]);
const renderers = useMemo(() => (asPreview ? debouncedRenderers : normalRenderers), [asPreview]);
const dpr = useDevicePixelRatio({ round: false });
@ -135,6 +142,7 @@ const useStageRenderer = (
stage,
tool,
selectedLayerIdColor,
selectedLayerType,
state.globalMaskLayerOpacity,
cursorPosition,
lastMouseDownPos,
@ -146,6 +154,7 @@ const useStageRenderer = (
stage,
tool,
selectedLayerIdColor,
selectedLayerType,
state.globalMaskLayerOpacity,
cursorPosition,
lastMouseDownPos,

View File

@ -1,16 +1,27 @@
import { ButtonGroup, IconButton } from '@invoke-ai/ui-library';
import { useStore } from '@nanostores/react';
import { createSelector } from '@reduxjs/toolkit';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import { $tool, selectedLayerDeleted, selectedLayerReset } from 'features/regionalPrompts/store/regionalPromptsSlice';
import {
$tool,
selectedLayerDeleted,
selectedLayerReset,
selectRegionalPromptsSlice,
} from 'features/regionalPrompts/store/regionalPromptsSlice';
import { useCallback } from 'react';
import { useHotkeys } from 'react-hotkeys-hook';
import { useTranslation } from 'react-i18next';
import { PiArrowsOutCardinalBold, PiEraserBold, PiPaintBrushBold, PiRectangleBold } from 'react-icons/pi';
const selectIsDisabled = createSelector(selectRegionalPromptsSlice, (regionalPrompts) => {
const selectedLayer = regionalPrompts.present.layers.find((l) => l.id === regionalPrompts.present.selectedLayerId);
return selectedLayer?.type !== 'masked_guidance_layer';
});
export const ToolChooser: React.FC = () => {
const { t } = useTranslation();
const dispatch = useAppDispatch();
const isDisabled = useAppSelector((s) => s.regionalPrompts.present.layers.length === 0);
const isDisabled = useAppSelector(selectIsDisabled);
const tool = useStore($tool);
const setToolToBrush = useCallback(() => {

View File

@ -133,6 +133,7 @@ const renderToolPreview = (
stage: Konva.Stage,
tool: Tool,
color: RgbColor | null,
selectedLayerType: Layer['type'] | null,
globalMaskLayerOpacity: number,
cursorPos: Vector2d | null,
lastMouseDownPos: Vector2d | null,
@ -144,6 +145,9 @@ const renderToolPreview = (
if (layerCount === 0) {
// We have no layers, so we should not render any tool
stage.container().style.cursor = 'default';
} else if (selectedLayerType !== 'masked_guidance_layer') {
// Non-mask-guidance layers don't have tools
stage.container().style.cursor = 'not-allowed';
} else if (tool === 'move') {
// Move tool gets a pointer
stage.container().style.cursor = 'default';