close image popup and add to playlist dialog on escape

This commit is contained in:
Drew Weymouth
2023-03-02 20:27:08 -08:00
parent 27ed8216f3
commit 595d9116f0
2 changed files with 10 additions and 5 deletions
+2
View File
@@ -42,6 +42,7 @@ func (m Controller) ShowPopUpImage(img image.Image) {
w := s.Width * 0.8
popS = fyne.NewSize(w, w*(1/asp))
}
util.ClosePopUpOnEscape(pop)
pop.Resize(popS)
pop.ShowAtPosition(fyne.NewPos(
(s.Width-popS.Width)/2,
@@ -120,6 +121,7 @@ func (m Controller) DoAddTracksToPlaylistWorkflow(trackIDs []string) {
dlg := dialogs.NewAddToPlaylistDialog("Add to Playlist", plNames)
pop := widget.NewModalPopUp(dlg, m.MainWindow.Canvas())
util.ClosePopUpOnEscape(pop)
dlg.OnCanceled = pop.Hide
dlg.OnSubmit = func(playlistChoice int, newPlaylistName string) {
pop.Hide()
+8 -5
View File
@@ -27,11 +27,6 @@ func ImageAspect(im image.Image) float32 {
return float32(b.Max.X-b.Min.X) / float32(b.Max.Y-b.Min.Y)
}
type PopUpProvider interface {
CreatePopUp(fyne.CanvasObject) *widget.PopUp
WindowSize() fyne.Size
}
func RichTextSegsFromHTMLString(s string) []widget.RichTextSegment {
tokr := html.NewTokenizer(strings.NewReader(s))
var segs []widget.RichTextSegment
@@ -59,3 +54,11 @@ func RichTextSegsFromHTMLString(s string) []widget.RichTextSegment {
return segs
}
func ClosePopUpOnEscape(pop *widget.PopUp) {
pop.Canvas.SetOnTypedKey(func(e *fyne.KeyEvent) {
if e.Name == fyne.KeyEscape {
pop.Hide()
}
})
}