-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: generalize 1D apodization panels and options for reuse in 2…
…D apodization
- Loading branch information
1 parent
7f6b32d
commit 40c01bb
Showing
6 changed files
with
502 additions
and
376 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/component/header/BaseSimpleApodizationOptionsPanel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { Checkbox } from '@blueprintjs/core'; | ||
|
||
import { useToaster } from '../context/ToasterContext.js'; | ||
import ActionButtons from '../elements/ActionButtons.js'; | ||
import Label from '../elements/Label.js'; | ||
import { NumberInput2Controller } from '../elements/NumberInput2Controller.js'; | ||
import { useSharedApodization } from '../panels/filtersPanel/Filters/hooks/useSharedApodization.js'; | ||
import type { | ||
ApodizationFilterOptions, | ||
UseSharedApodizationOptions, | ||
} from '../panels/filtersPanel/Filters/hooks/useSharedApodization.js'; | ||
|
||
import { headerLabelStyle } from './Header.js'; | ||
import { HeaderWrapper } from './HeaderWrapper.js'; | ||
|
||
interface BaseSimpleApodizationOptionsPanelProps | ||
extends Pick< | ||
UseSharedApodizationOptions, | ||
'onApplyDispatch' | 'onChangeDispatch' | ||
> { | ||
filter: ApodizationFilterOptions | null; | ||
} | ||
|
||
export function BaseSimpleApodizationOptionsPanel( | ||
props: BaseSimpleApodizationOptionsPanelProps, | ||
) { | ||
const toaster = useToaster(); | ||
|
||
const { filter, onApplyDispatch, onChangeDispatch } = props; | ||
|
||
const { formMethods, submitHandler, handleApplyFilter, handleCancelFilter } = | ||
useSharedApodization(filter, { | ||
applyFilterOnload: true, | ||
onApplyDispatch, | ||
onChangeDispatch, | ||
}); | ||
|
||
const { | ||
register, | ||
handleSubmit, | ||
control, | ||
formState: { isValid }, | ||
watch, | ||
} = formMethods; | ||
|
||
const isExponentialActive = watch('options.exponential.apply') || false; | ||
|
||
const { onChange: onLivePreviewFieldChange, ...livePreviewFieldOptions } = | ||
register('livePreview'); | ||
|
||
function handleClick() { | ||
if (!isExponentialActive) { | ||
toaster.show({ | ||
intent: 'danger', | ||
message: | ||
'Activate "Exponential" filter from the Processing panel first', | ||
}); | ||
} | ||
} | ||
|
||
function handleConfirm() { | ||
void handleSubmit((values) => handleApplyFilter(values))(); | ||
} | ||
|
||
function handleCancel() { | ||
handleCancelFilter(); | ||
} | ||
|
||
return ( | ||
<HeaderWrapper> | ||
<Label title="Line broadening:" shortTitle="LB:" style={headerLabelStyle}> | ||
<NumberInput2Controller | ||
control={control} | ||
name="options.exponential.options.lineBroadening" | ||
debounceTime={250} | ||
stepSize={0.1} | ||
style={{ width: '60px' }} | ||
onValueChange={() => { | ||
submitHandler(); | ||
}} | ||
readOnly={!isExponentialActive} | ||
onClick={handleClick} | ||
/> | ||
</Label> | ||
|
||
<Label title="Live preview" style={{ label: { padding: '0 5px' } }}> | ||
<Checkbox | ||
{...livePreviewFieldOptions} | ||
onChange={(event) => { | ||
void onLivePreviewFieldChange(event); | ||
submitHandler(); | ||
}} | ||
style={{ margin: 0 }} | ||
/> | ||
</Label> | ||
|
||
<ActionButtons | ||
disabledDone={!isValid} | ||
onDone={handleConfirm} | ||
onCancel={handleCancel} | ||
/> | ||
</HeaderWrapper> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.