[react] fix: seam allowance slider (#210)
Fixes #208 Reviewed-on: https://codeberg.org/freesewing/freesewing/pulls/210 Reviewed-by: Joost De Cock <joostdecock@noreply.codeberg.org> Co-authored-by: Jonathan Haas <haasjona@gmail.com> Co-committed-by: Jonathan Haas <haasjona@gmail.com>
This commit is contained in:
parent
b4a5393290
commit
a110d222c9
3 changed files with 16 additions and 11 deletions
|
@ -1,4 +1,4 @@
|
||||||
import React, { useMemo, useCallback, useState } from 'react'
|
import React, { useCallback, useMemo, useState } from 'react'
|
||||||
import { i18n } from '@freesewing/collection'
|
import { i18n } from '@freesewing/collection'
|
||||||
import {
|
import {
|
||||||
designOptionType,
|
designOptionType,
|
||||||
|
@ -188,7 +188,7 @@ export const MenuListToggle = ({ config, changed, updateHandler, name }) => {
|
||||||
|
|
||||||
export const MenuMmInput = (props) => {
|
export const MenuMmInput = (props) => {
|
||||||
const { updateHandler, current, config } = props
|
const { updateHandler, current, config } = props
|
||||||
const units = props.state.settings?.units
|
const units = props.settings?.units
|
||||||
const imperial = units === 'imperial'
|
const imperial = units === 'imperial'
|
||||||
const mmUpdateHandler = useCallback(
|
const mmUpdateHandler = useCallback(
|
||||||
(path, newCurrent) => {
|
(path, newCurrent) => {
|
||||||
|
@ -201,25 +201,30 @@ export const MenuMmInput = (props) => {
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set a default step that matches the unit
|
* Set a default step that matches the unit.
|
||||||
|
*
|
||||||
|
* Note that we could try to use something like 1.5875 for imperial to move in steps of 1/16 inches,
|
||||||
|
* but we round the mm values to two digits in the options, which would accumulate rounding errors.
|
||||||
|
*
|
||||||
|
* Because of this, we use 10ths of inches instead of 16ths of inches.
|
||||||
*/
|
*/
|
||||||
const defaultStep = units === 'imperial' ? 0.125 : 0.1
|
const defaultStep = imperial ? 1.27 : 1 // mm
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MenuSliderInput
|
<MenuSliderInput
|
||||||
{...props}
|
{...props}
|
||||||
{...{
|
{...{
|
||||||
config: {
|
config: {
|
||||||
step: defaultStep,
|
|
||||||
...config,
|
...config,
|
||||||
min: imperial ? config.min / 25.4 : config.min / 10,
|
min: measurementAsUnits(config.min, units),
|
||||||
max: imperial ? config.max / 25.4 : config.max / 10,
|
max: measurementAsUnits(config.max, units),
|
||||||
dflt: measurementAsUnits(config.dflt, units),
|
dflt: measurementAsUnits(config.dflt, units),
|
||||||
|
step: measurementAsUnits(defaultStep, units),
|
||||||
},
|
},
|
||||||
current: current === undefined ? undefined : measurementAsUnits(current, units),
|
current: current === undefined ? undefined : measurementAsUnits(current, units),
|
||||||
updateHandler: mmUpdateHandler,
|
updateHandler: mmUpdateHandler,
|
||||||
valFormatter: (val) => (units === 'imperial' ? formatFraction128(val, null) : val),
|
valFormatter: (val) => (imperial ? formatFraction128(val, null) : val),
|
||||||
suffix: units === 'imperial' ? '"' : 'cm',
|
suffix: imperial ? '"' : 'cm',
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|
|
@ -102,7 +102,7 @@ export function menuCoreSettingsStructure({ units = 'metric', sabool = false, pa
|
||||||
),
|
),
|
||||||
ux: config.uxLevels.core.sa,
|
ux: config.uxLevels.core.sa,
|
||||||
min: 0,
|
min: 0,
|
||||||
max: units === 'imperial' ? 2 : 2.5,
|
max: units === 'imperial' ? 25.4 : 25, // values are in mm
|
||||||
dflt: defaultSamm(units),
|
dflt: defaultSamm(units),
|
||||||
icon: SaIcon,
|
icon: SaIcon,
|
||||||
}
|
}
|
||||||
|
|
|
@ -366,7 +366,7 @@ export function measurementAsMm(value, units = 'metric') {
|
||||||
} else {
|
} else {
|
||||||
const decimal = fractionToDecimal(value)
|
const decimal = fractionToDecimal(value)
|
||||||
if (isNaN(decimal)) return false
|
if (isNaN(decimal)) return false
|
||||||
return decimal * 24.5
|
return decimal * 25.4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue