AddCloseDialog adds a dialog that confirms that the user wants to close the Scene associated with this widget when they try to close it. It calls the given config function to configure the dialog. It is the responsibility of this config function to add the title and close button to the dialog, which
(config func(d *Body) bool)
| 127 | // dialog. This can be used to make the dialog conditional on other things, like whether |
| 128 | // something is saved. |
| 129 | func (wb *WidgetBase) AddCloseDialog(config func(d *Body) bool) { |
| 130 | var inClose, canClose bool |
| 131 | wb.OnClose(func(e events.Event) { |
| 132 | if canClose { |
| 133 | return // let it close |
| 134 | } |
| 135 | if inClose { |
| 136 | e.SetHandled() |
| 137 | return |
| 138 | } |
| 139 | inClose = true |
| 140 | d := NewBody() |
| 141 | d.AddBottomBar(func(parent Widget) { |
| 142 | d.AddCancel(parent).OnClick(func(e events.Event) { |
| 143 | inClose = false |
| 144 | canClose = false |
| 145 | }) |
| 146 | parent.AsWidget().SetOnChildAdded(func(n tree.Node) { |
| 147 | if bt := AsButton(n); bt != nil { |
| 148 | bt.OnFirst(events.Click, func(e events.Event) { |
| 149 | // any button click gives us permission to close |
| 150 | canClose = true |
| 151 | }) |
| 152 | } |
| 153 | }) |
| 154 | }) |
| 155 | if !config(d) { |
| 156 | return |
| 157 | } |
| 158 | e.SetHandled() |
| 159 | d.RunDialog(wb) |
| 160 | }) |
| 161 | } |
| 162 | |
| 163 | // Send sends an new event of the given type to this widget, |
| 164 | // optionally starting from values in the given original event |