-
Notifications
You must be signed in to change notification settings - Fork 11
/
InspectorGeneral.tsx
121 lines (106 loc) · 3.13 KB
/
InspectorGeneral.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { Colors } from '../constants/Colors';
import { InspectorHeader } from './InspectorHeader';
import { InspectorHr } from './InspectorHr';
import { InspectorItem } from './InspectorItem';
import { NumberParam } from './NumberParam';
import { useDispatch, useSelector } from '../states/store';
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
// == styles =======================================================================================
const ConfirmButton = styled.div`
margin: 4px auto 0;
font-size: 0.8rem;
line-height: 1.2rem;
width: 4rem;
text-align: center;
background: ${ Colors.back3 };
cursor: pointer;
&:hover {
background: ${ Colors.back4 };
}
&:active {
background: ${ Colors.back1 };
}
`;
// == element ======================================================================================
export interface InspectorGeneralProps {
className?: string;
}
const InspectorGeneral = (): JSX.Element | null => {
const dispatch = useDispatch();
const {
automaton,
settingsMode,
minimizedPrecisionTime,
minimizedPrecisionValue,
initResolution
} = useSelector( ( state ) => ( {
automaton: state.automaton.instance,
settingsMode: state.settings.mode,
minimizedPrecisionTime: state.automaton.guiSettings.minimizedPrecisionTime,
minimizedPrecisionValue: state.automaton.guiSettings.minimizedPrecisionValue,
initResolution: state.automaton.resolution
} ) );
const [ resolution, setResolution ] = useState( 0.0 );
useEffect(
() => {
if ( settingsMode === 'general' ) {
setResolution( initResolution );
}
},
[ automaton, settingsMode, initResolution ]
);
return ( automaton && <>
<InspectorHeader text="General Config" />
<InspectorHr />
<InspectorItem
name="Min Prec Time"
description="Specify precision of time axis for minimized serialization."
>
<NumberParam
type="int"
value={ minimizedPrecisionTime }
onChange={ ( value ) => {
automaton.setGUISettings( 'minimizedPrecisionTime', Math.max( 0, value ) );
} }
/>
</InspectorItem>
<InspectorItem
name="Min Prec Value"
description="Specify precision of value axis for minimized serialization."
>
<NumberParam
type="int"
value={ minimizedPrecisionValue }
onChange={ ( value ) => {
automaton.setGUISettings( 'minimizedPrecisionValue', Math.max( 0, value ) );
} }
/>
</InspectorItem>
<InspectorHr />
<InspectorItem
name="Resolution"
description="Specify samples per second of curves."
>
<NumberParam
type="int"
value={ resolution }
onChange={ ( value ) => {
setResolution( Math.max( 0, value ) );
} }
/>
</InspectorItem>
<ConfirmButton
data-stalker="Apply the change of resolution."
onClick={ () => {
automaton.setResolution( resolution );
dispatch( {
type: 'History/Drop'
} );
} }
>
Apply
</ConfirmButton>
</> ) ?? null;
};
export { InspectorGeneral };