1
0
Fork 0

toggle to hide part buttons on cut and print layouts

This commit is contained in:
Enoch Riese 2023-03-09 08:52:28 -06:00
parent cc0f9e78a5
commit 1b259a4205
6 changed files with 62 additions and 21 deletions

View file

@ -68,7 +68,7 @@ const useFabricList = (draft) => {
const bgProps = { fill: 'none' } const bgProps = { fill: 'none' }
export const CutLayout = (props) => { export const CutLayout = (props) => {
const { t } = useTranslation(['workbench']) const { t } = useTranslation(['workbench', 'plugin'])
const { gist, design, updateGist } = props const { gist, design, updateGist } = props
// disable xray // disable xray
@ -110,7 +110,7 @@ export const CutLayout = (props) => {
}`} }`}
onClick={() => setCutFabric(title)} onClick={() => setCutFabric(title)}
> >
{title} {t('plugin:' + title)}
</button> </button>
))} ))}
</div> </div>
@ -124,6 +124,7 @@ export const CutLayout = (props) => {
gistReady={props.gistReady} gistReady={props.gistReady}
layoutPart="fabric" layoutPart="fabric"
layoutType={['cuttingLayout', fabricSettings.activeFabric]} layoutType={['cuttingLayout', fabricSettings.activeFabric]}
layoutSetType="forCutting"
/> />
</div> </div>
</div> </div>

View file

@ -1,6 +1,7 @@
import { ClearIcon, IconWrapper } from 'shared/components/icons.mjs' import { ClearIcon, IconWrapper } from 'shared/components/icons.mjs'
import { useTranslation } from 'next-i18next' import { useTranslation } from 'next-i18next'
import { formatFraction128, measurementAsMm, round, formatMm } from 'shared/utils.mjs' import { formatFraction128, measurementAsMm, round, formatMm } from 'shared/utils.mjs'
import { ShowButtonsToggle } from '../draft/buttons.mjs'
const SheetIcon = (props) => ( const SheetIcon = (props) => (
<IconWrapper {...props}> <IconWrapper {...props}>
@ -118,14 +119,21 @@ export const CutLayoutSettings = ({
<SheetIcon className="h-6 w-6 mr-2 inline align-middle" /> <SheetIcon className="h-6 w-6 mr-2 inline align-middle" />
<span className="text-xl font-bold align-middle">{fabricLength}</span> <span className="text-xl font-bold align-middle">{fabricLength}</span>
</div> </div>
<button <div>
key="reset" <ShowButtonsToggle
onClick={() => unsetGist(['layouts', 'cuttingLayout', activeFabric])} gist={gist}
className="btn btn-primary btn-outline" updateGist={updateGist}
> layoutSetType="forCutting"
<ClearIcon className="h-6 w-6 mr-2" /> ></ShowButtonsToggle>
{t('reset')} <button
</button> key="reset"
onClick={() => unsetGist(['layouts', 'cuttingLayout', activeFabric])}
className="btn btn-primary btn-outline"
>
<ClearIcon className="h-6 w-6 mr-2" />
{t('reset')}
</button>
</div>
</div> </div>
) )
} }

View file

@ -1,5 +1,6 @@
import { useTranslation } from 'next-i18next' import { useTranslation } from 'next-i18next'
import { ClearIcon } from 'shared/components/icons.mjs' import { ClearIcon } from 'shared/components/icons.mjs'
import get from 'lodash.get'
const Triangle = ({ transform = 'translate(0,0)', fill = 'currentColor' }) => ( const Triangle = ({ transform = 'translate(0,0)', fill = 'currentColor' }) => (
<path <path
@ -53,6 +54,25 @@ const Button = ({ onClickCb, transform, Icon, children }) => {
) )
} }
export const ShowButtonsToggle = ({ gist, layoutSetType, updateGist }) => {
const { t } = useTranslation('workbench')
const path = ['_state', 'layout', layoutSetType, 'showButtons']
const showButtons = get(gist, path, true)
const setShowButtons = () => updateGist(path, !showButtons)
return (
<label htmlFor="showButtons" className="label">
<span className="mr-2">{t('showButtons')}</span>
<input
type="checkbox"
className="toggle toggle-primary"
checked={showButtons}
onChange={setShowButtons}
/>
</label>
)
}
/** buttons for manipulating the part */ /** buttons for manipulating the part */
export const Buttons = ({ transform, flip, rotate, resetPart, rotate90 }) => { export const Buttons = ({ transform, flip, rotate, resetPart, rotate90 }) => {
const { t } = useTranslation('workbench') const { t } = useTranslation('workbench')

View file

@ -13,6 +13,7 @@ export const Draft = (props) => {
bgProps = {}, bgProps = {},
fitLayoutPart = false, fitLayoutPart = false,
layoutType = 'printingLayout', layoutType = 'printingLayout',
layoutSetType = 'forPrinting',
} = props } = props
const svgRef = useRef(null) const svgRef = useRef(null)
@ -98,6 +99,7 @@ export const Draft = (props) => {
gist, gist,
updateLayout, updateLayout,
isLayoutPart: stackName === props.layoutPart, isLayoutPart: stackName === props.layoutPart,
layoutSetType: layoutSetType,
}} }}
/> />
) )

View file

@ -50,6 +50,7 @@ import { getProps, angle } from '../../draft/utils.mjs'
import { drag } from 'd3-drag' import { drag } from 'd3-drag'
import { select } from 'd3-selection' import { select } from 'd3-selection'
import { Buttons } from './buttons.mjs' import { Buttons } from './buttons.mjs'
import get from 'lodash.get'
export const Stack = (props) => { export const Stack = (props) => {
const { layout, stack, stackName, gist } = props const { layout, stack, stackName, gist } = props
@ -230,6 +231,7 @@ export const Stack = (props) => {
// don't render if the part is empty // don't render if the part is empty
// if (Object.keys(part.snippets).length === 0 && Object.keys(part.paths).length === 0) return null; // if (Object.keys(part.snippets).length === 0 && Object.keys(part.paths).length === 0) return null;
const showButtons = get(gist, ['_state', 'layout', props.layoutSetType, 'showButtons'], true)
return ( return (
<g id={`stack-${stackName}`} {...getProps(stack)} ref={stackRef}> <g id={`stack-${stackName}`} {...getProps(stack)} ref={stackRef}>
<g id={`stack-inner-${stackName}`} ref={innerRef}> <g id={`stack-inner-${stackName}`} ref={innerRef}>
@ -249,17 +251,19 @@ export const Stack = (props) => {
id={`${stackName}-layout-rect`} id={`${stackName}-layout-rect`}
onClick={toggleDragRotate} onClick={toggleDragRotate}
/> />
<Buttons {showButtons ? (
transform={`translate(${center.x}, ${center.y}) rotate(${-rotation}) scale(${ <Buttons
flipX ? -1 : 1 transform={`translate(${center.x}, ${center.y}) rotate(${-rotation}) scale(${
},${flipY ? -1 : 1})`} flipX ? -1 : 1
flip={flip} },${flipY ? -1 : 1})`}
rotate={rotate} flip={flip}
setRotate={setRotate} rotate={rotate}
resetPart={resetPart} setRotate={setRotate}
rotate90={rotate90} resetPart={resetPart}
partName={stackName} rotate90={rotate90}
/> partName={stackName}
/>
) : null}
</> </>
)} )}
</g> </g>

View file

@ -2,6 +2,7 @@ import { PageSizePicker } from './pagesize-picker.mjs'
import { PageOrientationPicker } from './orientation-picker.mjs' import { PageOrientationPicker } from './orientation-picker.mjs'
import { PrintIcon, RightIcon, ClearIcon, ExportIcon } from 'shared/components/icons.mjs' import { PrintIcon, RightIcon, ClearIcon, ExportIcon } from 'shared/components/icons.mjs'
import { useTranslation } from 'next-i18next' import { useTranslation } from 'next-i18next'
import { ShowButtonsToggle } from '../draft/buttons.mjs'
export const PrintLayoutSettings = (props) => { export const PrintLayoutSettings = (props) => {
const { t } = useTranslation(['workbench']) const { t } = useTranslation(['workbench'])
@ -34,6 +35,11 @@ export const PrintLayoutSettings = (props) => {
<PageOrientationPicker {...props} /> <PageOrientationPicker {...props} />
</div> </div>
<div className="flex gap-4"> <div className="flex gap-4">
<ShowButtonsToggle
gist={props.gist}
updateGist={props.updateGist}
layoutSetType="forPrinting"
></ShowButtonsToggle>
<button <button
key="export" key="export"
onClick={props.exportIt} onClick={props.exportIt}