Skip to content

Commit de01257

Browse files
committed
demo/exam: cleanup
1 parent b60c6cd commit de01257

File tree

2 files changed

+15
-37
lines changed

2 files changed

+15
-37
lines changed

demo/exam/app.go

+9-37
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ func (a *App) GradeTest() {
4646
for _, s := range a.Scores {
4747
score += float32(s)
4848
}
49-
5049
a.Grades = append(a.Grades, score/float32(len(a.Scores)))
5150
}
5251

@@ -83,9 +82,7 @@ func (a *App) Dispatch(kind string, args map[string]interface{}) {
8382
a.ShowingAnswer = false
8483
a.Position++
8584
}
86-
8785
a.Changes <- true
88-
8986
}()
9087

9188
return
@@ -153,10 +150,8 @@ func renderExamWindow(a *App) interface{} {
153150

154151
g := forms.NewGrid()
155152

156-
r0 := g.AddRow()
157-
r0.AddCol(nil)
158-
r0.AddCol(forms.NewTitle(k.Question, 1)).Steps = 6
159-
r0.AddCol(nil)
153+
title := forms.NewTitle(k.Question, 1)
154+
g.AddRowItems(nil, title, nil).SetSpans(0, 6, 0)
160155

161156
r := g.AddRow()
162157
r.AddCol(nil)
@@ -182,7 +177,6 @@ func renderExamWindow(a *App) interface{} {
182177
} else {
183178
b.Action = forms.NewAction("incorrect")
184179
}
185-
186180
b.Action.Args["provided"] = o
187181
}
188182

@@ -197,43 +191,28 @@ func renderExamWindow(a *App) interface{} {
197191
w.AddMenu("Выберите наибольшее число", nil)
198192
g := forms.NewGrid()
199193

200-
r0 := g.AddRow()
201-
r0.AddCol(nil)
202-
r0.AddCol(forms.NewTitle("Что больше?", 1)).Steps = 6
203-
r0.AddCol(nil)
194+
title := forms.NewTitle("Что больше?", 1)
195+
g.AddRowItems(nil, title, nil).SetSpans(0, 6, 0)
204196

205-
r := g.AddRow()
206-
r.AddCol(nil)
197+
b := forms.NewButton(k.First, nop).EnlargeAndFill()
207198

208-
b := forms.NewButton(k.First, nop)
209-
b.Fill = true
210-
b.Large = true
199+
b2 := forms.NewButton(k.Second, nop).EnlargeAndFill()
211200

212-
r.AddCol(b)
213-
214-
b2 := forms.NewButton(k.Second, nop)
215-
b2.Fill = true
216-
b2.Large = true
217-
218-
r.AddCol(b2)
219-
r.AddCol(nil)
201+
g.AddRowItems(nil, b, b2, nil)
220202

221203
if k.CorrectAnswer == k.First {
222204

223205
if a.ShowingAnswer {
224206
b.Style = "success"
225207
b2.Style = "danger"
226-
227208
} else {
228209
b.Action = forms.NewAction("correct")
229210
b2.Action = forms.NewAction("incorrect")
230211
b.Action.Args["provided"] = b.Text
231212
b2.Action.Args["provided"] = b2.Text
232-
233213
}
234214

235215
} else {
236-
237216
if a.ShowingAnswer {
238217
b2.Style = "success"
239218
b.Style = "danger"
@@ -245,21 +224,16 @@ func renderExamWindow(a *App) interface{} {
245224
b2.Action.Args["provided"] = b2.Text
246225
}
247226
}
248-
249227
w.Content = g
250-
251228
}
252229

253230
return w
254-
255231
}
256232

257233
func renderAnswers(a *App) interface{} {
258234
w := forms.NewWindow("Результаты")
259235

260-
next := forms.NewButton("Начать новый тест", forms.NewAction("start-test"))
261-
next.Fill = true
262-
next.Style = "information"
236+
next := forms.NewButton("Начать новый тест", forms.NewAction("start-test")).EnlargeAndFill()
263237

264238
t := renderSummaryTable(a)
265239

@@ -357,9 +331,7 @@ func renderMainWindow(a *App) interface{} {
357331

358332
startAction := forms.NewAction("start-test")
359333

360-
b := forms.NewButton("Новый тест", startAction)
361-
b.Large = true
362-
b.Fill = true
334+
b := forms.NewButton("Новый тест", startAction).EnlargeAndFill()
363335

364336
g.AddRowItems(nil, b, nil)
365337

forms/button.go

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ func NewButton(text string, action *Action) *Button {
1717
}
1818
}
1919

20+
func (b *Button) EnlargeAndFill() *Button {
21+
b.Large = true
22+
b.Fill = true
23+
return b
24+
}
25+
2026
type Label struct {
2127
Type string `json:"type"`
2228
Text string `json:"text"`

0 commit comments

Comments
 (0)