Rearrange some canvas toolbar icons

Put brush stuff together and canvas movement stuff together
This commit is contained in:
blessedcoolant 2022-11-20 23:03:31 +13:00
parent e1e978b423
commit 088fd97418
2 changed files with 45 additions and 38 deletions

View File

@ -8,12 +8,7 @@ import {
import { useAppDispatch, useAppSelector } from 'app/store'; import { useAppDispatch, useAppSelector } from 'app/store';
import _ from 'lodash'; import _ from 'lodash';
import IAIIconButton from 'common/components/IAIIconButton'; import IAIIconButton from 'common/components/IAIIconButton';
import { import { FaEraser, FaPaintBrush, FaSlidersH } from 'react-icons/fa';
FaArrowsAlt,
FaEraser,
FaPaintBrush,
FaSlidersH,
} from 'react-icons/fa';
import { import {
canvasSelector, canvasSelector,
isStagingSelector, isStagingSelector,
@ -52,18 +47,6 @@ const IAICanvasToolChooserOptions = () => {
const { tool, brushColor, brushSize, brushColorString, isStaging } = const { tool, brushColor, brushSize, brushColorString, isStaging } =
useAppSelector(selector); useAppSelector(selector);
useHotkeys(
['v'],
() => {
handleSelectMoveTool();
},
{
enabled: () => true,
preventDefault: true,
},
[]
);
useHotkeys( useHotkeys(
['b'], ['b'],
() => { () => {
@ -114,7 +97,6 @@ const IAICanvasToolChooserOptions = () => {
const handleSelectBrushTool = () => dispatch(setTool('brush')); const handleSelectBrushTool = () => dispatch(setTool('brush'));
const handleSelectEraserTool = () => dispatch(setTool('eraser')); const handleSelectEraserTool = () => dispatch(setTool('eraser'));
const handleSelectMoveTool = () => dispatch(setTool('move'));
return ( return (
<ButtonGroup isAttached> <ButtonGroup isAttached>
@ -134,20 +116,12 @@ const IAICanvasToolChooserOptions = () => {
isDisabled={isStaging} isDisabled={isStaging}
onClick={() => dispatch(setTool('eraser'))} onClick={() => dispatch(setTool('eraser'))}
/> />
<IAIIconButton
aria-label="Move Tool (V)"
tooltip="Move Tool (V)"
icon={<FaArrowsAlt />}
data-selected={tool === 'move' || isStaging}
onClick={handleSelectMoveTool}
/>
<IAIPopover <IAIPopover
trigger="hover" trigger="hover"
triggerComponent={ triggerComponent={
<IAIIconButton <IAIIconButton
aria-label="Tool Options" aria-label="Brush Options"
tooltip="Tool Options" tooltip="Brush Options"
icon={<FaSlidersH />} icon={<FaSlidersH />}
/> />
} }

View File

@ -4,11 +4,13 @@ import {
resetCanvas, resetCanvas,
resetCanvasView, resetCanvasView,
resizeAndScaleCanvas, resizeAndScaleCanvas,
setTool,
} from 'features/canvas/store/canvasSlice'; } from 'features/canvas/store/canvasSlice';
import { useAppDispatch, useAppSelector } from 'app/store'; import { useAppDispatch, useAppSelector } from 'app/store';
import _ from 'lodash'; import _ from 'lodash';
import IAIIconButton from 'common/components/IAIIconButton'; import IAIIconButton from 'common/components/IAIIconButton';
import { import {
FaArrowsAlt,
FaCopy, FaCopy,
FaCrosshairs, FaCrosshairs,
FaDownload, FaDownload,
@ -27,14 +29,21 @@ import { getCanvasBaseLayer } from 'features/canvas/util/konvaInstanceProvider';
import { systemSelector } from 'features/system/store/systemSelectors'; import { systemSelector } from 'features/system/store/systemSelectors';
import IAICanvasToolChooserOptions from './IAICanvasToolChooserOptions'; import IAICanvasToolChooserOptions from './IAICanvasToolChooserOptions';
import useImageUploader from 'common/hooks/useImageUploader'; import useImageUploader from 'common/hooks/useImageUploader';
import {
canvasSelector,
isStagingSelector,
} from 'features/canvas/store/canvasSelectors';
export const selector = createSelector( export const selector = createSelector(
[systemSelector], [systemSelector, canvasSelector, isStagingSelector],
(system) => { (system, canvas, isStaging) => {
const { isProcessing } = system; const { isProcessing } = system;
const { tool } = canvas;
return { return {
isProcessing, isProcessing,
isStaging,
tool,
}; };
}, },
{ {
@ -46,11 +55,23 @@ export const selector = createSelector(
const IAICanvasOutpaintingControls = () => { const IAICanvasOutpaintingControls = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { isProcessing } = useAppSelector(selector); const { isProcessing, isStaging, tool } = useAppSelector(selector);
const canvasBaseLayer = getCanvasBaseLayer(); const canvasBaseLayer = getCanvasBaseLayer();
const { openUploader } = useImageUploader(); const { openUploader } = useImageUploader();
useHotkeys(
['v'],
() => {
handleSelectMoveTool();
},
{
enabled: () => true,
preventDefault: true,
},
[]
);
useHotkeys( useHotkeys(
['r'], ['r'],
() => { () => {
@ -111,6 +132,8 @@ const IAICanvasOutpaintingControls = () => {
[canvasBaseLayer, isProcessing] [canvasBaseLayer, isProcessing]
); );
const handleSelectMoveTool = () => dispatch(setTool('move'));
const handleResetCanvasView = () => { const handleResetCanvasView = () => {
const canvasBaseLayer = getCanvasBaseLayer(); const canvasBaseLayer = getCanvasBaseLayer();
if (!canvasBaseLayer) return; if (!canvasBaseLayer) return;
@ -170,6 +193,22 @@ const IAICanvasOutpaintingControls = () => {
<IAICanvasMaskOptions /> <IAICanvasMaskOptions />
<IAICanvasToolChooserOptions /> <IAICanvasToolChooserOptions />
<ButtonGroup isAttached>
<IAIIconButton
aria-label="Move Tool (V)"
tooltip="Move Tool (V)"
icon={<FaArrowsAlt />}
data-selected={tool === 'move' || isStaging}
onClick={handleSelectMoveTool}
/>
<IAIIconButton
aria-label="Reset View (R)"
tooltip="Reset View (R)"
icon={<FaCrosshairs />}
onClick={handleResetCanvasView}
/>
</ButtonGroup>
<ButtonGroup isAttached> <ButtonGroup isAttached>
<IAIIconButton <IAIIconButton
aria-label="Merge Visible (Shift+M)" aria-label="Merge Visible (Shift+M)"
@ -212,12 +251,6 @@ const IAICanvasOutpaintingControls = () => {
icon={<FaUpload />} icon={<FaUpload />}
onClick={openUploader} onClick={openUploader}
/> />
<IAIIconButton
aria-label="Reset View (R)"
tooltip="Reset View (R)"
icon={<FaCrosshairs />}
onClick={handleResetCanvasView}
/>
<IAIIconButton <IAIIconButton
aria-label="Clear Canvas" aria-label="Clear Canvas"
tooltip="Clear Canvas" tooltip="Clear Canvas"