mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Hide legend button Option 2 (#3797)
@psychedelicious This version I added a toggle button to the viewport controls to show/hide the legend ![image](https://github.com/invoke-ai/InvokeAI/assets/115216705/f74ea273-e043-4104-921d-76861bd69841) Option 1 https://github.com/invoke-ai/InvokeAI/pull/3790
This commit is contained in:
commit
179455ef46
@ -2,9 +2,12 @@ import { ButtonGroup } from '@chakra-ui/react';
|
|||||||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
import IAIIconButton from 'common/components/IAIIconButton';
|
import IAIIconButton from 'common/components/IAIIconButton';
|
||||||
import { memo, useCallback } from 'react';
|
import { memo, useCallback } from 'react';
|
||||||
import { FaCode, FaExpand, FaMinus, FaPlus } from 'react-icons/fa';
|
import { FaCode, FaExpand, FaMinus, FaPlus, FaInfo } from 'react-icons/fa';
|
||||||
import { useReactFlow } from 'reactflow';
|
import { useReactFlow } from 'reactflow';
|
||||||
import { shouldShowGraphOverlayChanged } from '../store/nodesSlice';
|
import {
|
||||||
|
shouldShowGraphOverlayChanged,
|
||||||
|
shouldShowFieldTypeLegendChanged,
|
||||||
|
} from '../store/nodesSlice';
|
||||||
|
|
||||||
const ViewportControls = () => {
|
const ViewportControls = () => {
|
||||||
const { zoomIn, zoomOut, fitView } = useReactFlow();
|
const { zoomIn, zoomOut, fitView } = useReactFlow();
|
||||||
@ -12,6 +15,9 @@ const ViewportControls = () => {
|
|||||||
const shouldShowGraphOverlay = useAppSelector(
|
const shouldShowGraphOverlay = useAppSelector(
|
||||||
(state) => state.nodes.shouldShowGraphOverlay
|
(state) => state.nodes.shouldShowGraphOverlay
|
||||||
);
|
);
|
||||||
|
const shouldShowFieldTypeLegend = useAppSelector(
|
||||||
|
(state) => state.nodes.shouldShowFieldTypeLegend
|
||||||
|
);
|
||||||
|
|
||||||
const handleClickedZoomIn = useCallback(() => {
|
const handleClickedZoomIn = useCallback(() => {
|
||||||
zoomIn();
|
zoomIn();
|
||||||
@ -29,6 +35,10 @@ const ViewportControls = () => {
|
|||||||
dispatch(shouldShowGraphOverlayChanged(!shouldShowGraphOverlay));
|
dispatch(shouldShowGraphOverlayChanged(!shouldShowGraphOverlay));
|
||||||
}, [shouldShowGraphOverlay, dispatch]);
|
}, [shouldShowGraphOverlay, dispatch]);
|
||||||
|
|
||||||
|
const handleClickedToggleFieldTypeLegend = useCallback(() => {
|
||||||
|
dispatch(shouldShowFieldTypeLegendChanged(!shouldShowFieldTypeLegend));
|
||||||
|
}, [shouldShowFieldTypeLegend, dispatch]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ButtonGroup isAttached orientation="vertical">
|
<ButtonGroup isAttached orientation="vertical">
|
||||||
<IAIIconButton
|
<IAIIconButton
|
||||||
@ -52,6 +62,12 @@ const ViewportControls = () => {
|
|||||||
aria-label="Show/Hide Graph"
|
aria-label="Show/Hide Graph"
|
||||||
icon={<FaCode />}
|
icon={<FaCode />}
|
||||||
/>
|
/>
|
||||||
|
<IAIIconButton
|
||||||
|
isChecked={shouldShowFieldTypeLegend}
|
||||||
|
onClick={handleClickedToggleFieldTypeLegend}
|
||||||
|
aria-label="Show/Hide Field Type Legend"
|
||||||
|
icon={<FaInfo />}
|
||||||
|
/>
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -9,10 +9,13 @@ const TopRightPanel = () => {
|
|||||||
const shouldShowGraphOverlay = useAppSelector(
|
const shouldShowGraphOverlay = useAppSelector(
|
||||||
(state: RootState) => state.nodes.shouldShowGraphOverlay
|
(state: RootState) => state.nodes.shouldShowGraphOverlay
|
||||||
);
|
);
|
||||||
|
const shouldShowFieldTypeLegend = useAppSelector(
|
||||||
|
(state: RootState) => state.nodes.shouldShowFieldTypeLegend
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Panel position="top-right">
|
<Panel position="top-right">
|
||||||
<FieldTypeLegend />
|
{shouldShowFieldTypeLegend && <FieldTypeLegend />}
|
||||||
{shouldShowGraphOverlay && <NodeGraphOverlay />}
|
{shouldShowGraphOverlay && <NodeGraphOverlay />}
|
||||||
</Panel>
|
</Panel>
|
||||||
);
|
);
|
||||||
|
@ -32,6 +32,7 @@ export type NodesState = {
|
|||||||
invocationTemplates: Record<string, InvocationTemplate>;
|
invocationTemplates: Record<string, InvocationTemplate>;
|
||||||
connectionStartParams: OnConnectStartParams | null;
|
connectionStartParams: OnConnectStartParams | null;
|
||||||
shouldShowGraphOverlay: boolean;
|
shouldShowGraphOverlay: boolean;
|
||||||
|
shouldShowFieldTypeLegend: boolean;
|
||||||
editorInstance: ReactFlowInstance | undefined;
|
editorInstance: ReactFlowInstance | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -42,6 +43,7 @@ export const initialNodesState: NodesState = {
|
|||||||
invocationTemplates: {},
|
invocationTemplates: {},
|
||||||
connectionStartParams: null,
|
connectionStartParams: null,
|
||||||
shouldShowGraphOverlay: false,
|
shouldShowGraphOverlay: false,
|
||||||
|
shouldShowFieldTypeLegend: false,
|
||||||
editorInstance: undefined,
|
editorInstance: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -125,6 +127,12 @@ const nodesSlice = createSlice({
|
|||||||
shouldShowGraphOverlayChanged: (state, action: PayloadAction<boolean>) => {
|
shouldShowGraphOverlayChanged: (state, action: PayloadAction<boolean>) => {
|
||||||
state.shouldShowGraphOverlay = action.payload;
|
state.shouldShowGraphOverlay = action.payload;
|
||||||
},
|
},
|
||||||
|
shouldShowFieldTypeLegendChanged: (
|
||||||
|
state,
|
||||||
|
action: PayloadAction<boolean>
|
||||||
|
) => {
|
||||||
|
state.shouldShowFieldTypeLegend = action.payload;
|
||||||
|
},
|
||||||
nodeTemplatesBuilt: (
|
nodeTemplatesBuilt: (
|
||||||
state,
|
state,
|
||||||
action: PayloadAction<Record<string, InvocationTemplate>>
|
action: PayloadAction<Record<string, InvocationTemplate>>
|
||||||
@ -161,6 +169,7 @@ export const {
|
|||||||
connectionStarted,
|
connectionStarted,
|
||||||
connectionEnded,
|
connectionEnded,
|
||||||
shouldShowGraphOverlayChanged,
|
shouldShowGraphOverlayChanged,
|
||||||
|
shouldShowFieldTypeLegendChanged,
|
||||||
nodeTemplatesBuilt,
|
nodeTemplatesBuilt,
|
||||||
nodeEditorReset,
|
nodeEditorReset,
|
||||||
imageCollectionFieldValueChanged,
|
imageCollectionFieldValueChanged,
|
||||||
|
Loading…
Reference in New Issue
Block a user