Skip to content

Commit 5871f39

Browse files
committed
screen: working on the dialog component
1 parent e321e73 commit 5871f39

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

screen/dialog.go

+18
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ func (d *DialogRef) SetContent(i ID) {
2222
d.a.Apply(&DialogContentChanged{ID: d.ID, ContentID: i, PreviousID: dc.content})
2323
}
2424

25+
func (d *DialogRef) SetTitle(x string) {
26+
s := d.a.s
27+
t := s.controls[d.ID].(*dialogCtl).title
28+
if t == x {
29+
return
30+
}
31+
d.a.Apply(&DialogTitleChanged{ID: d.ID, Title: x})
32+
}
33+
34+
func (d *DialogRef) DoSetTitle(x string) {
35+
36+
}
37+
2538
func (d *DialogRef) Show() {
2639
s := d.a.s
2740

@@ -50,3 +63,8 @@ type DialogContentChanged struct {
5063
ContentID ID `json:"contentId"`
5164
PreviousID ID `json:"previousId"`
5265
}
66+
67+
type DialogTitleChanged struct {
68+
ID ID `json:"id"`
69+
Title string `json:"title"`
70+
}

screen/manual_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ func Test(t *testing.T) {
1919
d.SetContent(h.ID)
2020
d.Show()
2121

22+
h.OnClick(d.DoSetTitle("YEP!"))
23+
2224
time.Sleep(time.Millisecond)
2325

2426
}
@@ -31,7 +33,5 @@ func printEvents(c chan interface{}) {
3133
} else {
3234
fmt.Printf("%T: %s\n", e, string(b))
3335
}
34-
3536
}
36-
3737
}

screen/state.go

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func (s *state) apply(e interface{}) {
3030
case *DialogShown:
3131
s.top = t.ID
3232
s.controls[t.ID].(*dialogCtl).visible = true
33+
case *DialogTitleChanged:
34+
s.controls[t.ID].(*dialogCtl).title = t.Title
3335
default:
3436
panic("Unknown event type")
3537
}

0 commit comments

Comments
 (0)