Skip to content

Commit af90900

Browse files
committed
style: Change layout of walking gait page, refactor
1 parent c306a93 commit af90900

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

src/components/pages/WalkingGaitsPage.js

+38-38
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { sliderList, Card, BasicButton, ToggleSwitch } from "../generic"
33
import { SECTION_NAMES, RESET_LABEL } from "../vars"
44
import getWalkSequence from "../../hexapod/solvers/walkSequenceSolver"
55
import PoseTable from "./PoseTable"
6+
import { DEFAULT_POSE } from "../../templates"
67

78
const ANIMATION_DELAY = 1
89

@@ -14,8 +15,8 @@ const SLIDER_LABELS = [
1415
"ry",
1516
"hipStance",
1617
"hipSwing",
17-
"stepCount",
1818
"liftSwing",
19+
"stepCount",
1920
]
2021

2122
const PARAMS = {
@@ -49,6 +50,7 @@ class WalkingGaitsPage extends Component {
4950
pageName = SECTION_NAMES.walkingGaits
5051
state = {
5152
gaitParams: DEFAULT_GAIT_VARS,
53+
pose: DEFAULT_POSE,
5254
isAnimating: false,
5355
isTripodGait: true,
5456
isForward: true,
@@ -133,29 +135,23 @@ class WalkingGaitsPage extends Component {
133135

134136
get widgetsSwitch() {
135137
return (
136-
<p>
137-
<ToggleSwitch
138-
id="gaitWidgetSwitch"
139-
value={this.state.showGaitWidgets ? "controlsShown" : "poseShown"}
140-
handleChange={this.toggleWidgets}
141-
showValue={true}
142-
/>
143-
</p>
138+
<ToggleSwitch
139+
id="gaitWidgetSwitch"
140+
value={this.state.showGaitWidgets ? "controlsShown" : "poseShown"}
141+
handleChange={this.toggleWidgets}
142+
showValue={true}
143+
/>
144144
)
145145
}
146146

147147
get animatingSwitch() {
148148
return (
149-
<p className="row-container">
150-
<ToggleSwitch
151-
id="IsAnimatingSwitch"
152-
value={this.state.isAnimating ? "PLAYING... " : "...PAUSED. "}
153-
handleChange={this.toggleAnimating}
154-
showValue={true}
155-
/>
156-
{" <"}--- Press this!{" "}
157-
{this.state.isAnimating ? this.state.animationCount : null}
158-
</p>
149+
<ToggleSwitch
150+
id="IsAnimatingSwitch"
151+
value={this.state.isAnimating ? "PLAYING... " : "...PAUSED. "}
152+
handleChange={this.toggleAnimating}
153+
showValue={true}
154+
/>
159155
)
160156
}
161157

@@ -182,44 +178,48 @@ class WalkingGaitsPage extends Component {
182178
}
183179

184180
get sliders() {
185-
return sliderList({
181+
const sliders = sliderList({
186182
names: SLIDER_LABELS,
187183
values: this.state.gaitParams,
188184
rangeParams: PARAMS,
189185
handleChange: this.updateGaitParams,
190186
})
191-
}
192187

193-
get gaitWidgets() {
194-
const sliders = this.sliders
195188
return (
196189
<>
197190
<div className="row-container">{sliders.slice(6, 9)}</div>
198191
<div className="row-container">{sliders.slice(0, 3)}</div>
199192
<div className="row-container">{sliders.slice(3, 6)}</div>
200-
<p className="row-container">
201-
<div className="cell">{this.gaitTypeSwitch}</div>
202-
<div className="cell">{this.directionSwitch}</div>
203-
<div className="cell"> </div>
204-
</p>
205-
<BasicButton handleClick={this.reset}>{RESET_LABEL}</BasicButton>
206193
</>
207194
)
208195
}
209196

210-
get widgetsShown() {
211-
if (this.state.showGaitWidgets) {
212-
return this.gaitWidgets
213-
} else {
214-
return <PoseTable pose={this.state.pose} />
215-
}
197+
get animationCount() {
198+
return <p hidden={!this.state.isAnimating}>{this.state.animationCount}</p>
216199
}
217200

201+
twoSwitches = (switch1, switch2) => (
202+
<div className="row-container" style={{ padding: "10px" }}>
203+
<div className="cell">{switch1}</div>
204+
<div className="cell">{switch2}</div>
205+
<div className="cell"></div>
206+
</div>
207+
)
208+
218209
render = () => {
219210
return (
220-
<Card title={<h2>{this.pageName}</h2>} other={this.widgetsSwitch}>
221-
{this.animatingSwitch}
222-
{this.widgetsShown}
211+
<Card title={<h2>{this.pageName}</h2>} other={this.animationCount}>
212+
{this.twoSwitches(this.animatingSwitch, this.widgetsSwitch)}
213+
214+
<div hidden={!this.state.showGaitWidgets}>
215+
{this.twoSwitches(this.gaitTypeSwitch, this.directionSwitch)}
216+
{this.sliders}
217+
<BasicButton handleClick={this.reset}>{RESET_LABEL}</BasicButton>
218+
</div>
219+
220+
<div hidden={this.state.showGaitWidgets}>
221+
<PoseTable pose={this.state.pose} />
222+
</div>
223223
</Card>
224224
)
225225
}

0 commit comments

Comments
 (0)