-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add about dialog and window for helping apps make a pretty about screen
- Loading branch information
1 parent
61d0ff4
commit c9c8b92
Showing
9 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[Details] | ||
Icon = "Icon.png" | ||
Version = "0.1.0" | ||
Build = 5 |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package main | ||
|
||
import ( | ||
"net/url" | ||
|
||
"fyne.io/fyne/v2/app" | ||
"fyne.io/fyne/v2/container" | ||
"fyne.io/fyne/v2/widget" | ||
"fyne.io/x/fyne/dialog" | ||
) | ||
|
||
func main() { | ||
a := app.New() | ||
w := a.NewWindow("Fyne-x demo") | ||
|
||
docURL, _ := url.Parse("https://docs.fyne.io") | ||
links := []*widget.Hyperlink{ | ||
widget.NewHyperlink("Docs", docURL), | ||
} | ||
w.SetContent(container.NewGridWithColumns(1, | ||
widget.NewButton("About", func() { | ||
dialog.ShowAbout("Some **cool** stuff", links, a, w) | ||
}), | ||
widget.NewButton("About window", func() { | ||
dialog.ShowAboutWindow("Some **cool** stuff", links, a) | ||
}), | ||
)) | ||
|
||
w.ShowAndRun() | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package dialog | ||
|
||
import ( | ||
"image/color" | ||
|
||
"fyne.io/fyne/v2" | ||
"fyne.io/fyne/v2/canvas" | ||
"fyne.io/fyne/v2/container" | ||
"fyne.io/fyne/v2/dialog" | ||
"fyne.io/fyne/v2/layout" | ||
"fyne.io/fyne/v2/theme" | ||
"fyne.io/fyne/v2/widget" | ||
) | ||
|
||
// ShowAbout opens a parallax about dialog using the app metadata along with the | ||
// markdown content and links passed into this method. | ||
func ShowAbout(content string, links []*widget.Hyperlink, a fyne.App, w fyne.Window) { | ||
d := dialog.NewCustom("About", "OK", aboutContent(content, links, a), w) | ||
d.Resize(fyne.NewSize(400, 320)) | ||
d.Show() | ||
} | ||
|
||
// ShowAboutWindow opens a parallax about window using the app metadata along with the | ||
// markdown content and links passed into this method. | ||
func ShowAboutWindow(content string, links []*widget.Hyperlink, a fyne.App) { | ||
w := a.NewWindow("About") | ||
w.SetContent(aboutContent(content, links, a)) | ||
w.Resize(fyne.NewSize(360, 280)) | ||
w.Show() | ||
} | ||
|
||
func aboutContent(content string, links []*widget.Hyperlink, a fyne.App) fyne.CanvasObject { | ||
rich := widget.NewRichTextFromMarkdown(content) | ||
|
||
logo := canvas.NewImageFromResource(a.Metadata().Icon) | ||
logo.FillMode = canvas.ImageFillContain | ||
logo.SetMinSize(fyne.NewSize(128, 128)) | ||
|
||
footer := container.NewHBox(layout.NewSpacer()) | ||
for i, a := range links { | ||
footer.Add(a) | ||
if i < len(links)-1 { | ||
footer.Add(widget.NewLabel("-")) | ||
} | ||
} | ||
footer.Add(layout.NewSpacer()) | ||
|
||
body := container.NewVBox( | ||
container.NewCenter( | ||
widget.NewRichTextFromMarkdown("**Version:** "+a.Metadata().Version)), | ||
logo, | ||
container.NewCenter(rich)) | ||
scroll := container.NewScroll(body) | ||
|
||
bgColor := withAlpha(theme.BackgroundColor(), 0xe0) | ||
shadowColor := withAlpha(theme.BackgroundColor(), 0x33) | ||
|
||
underlay := canvas.NewImageFromResource(a.Metadata().Icon) | ||
bg := canvas.NewRectangle(bgColor) | ||
underlayer := underLayout{} | ||
slideBG := container.New(underlayer, underlay) | ||
footerBG := canvas.NewRectangle(shadowColor) | ||
|
||
listen := make(chan fyne.Settings) | ||
fyne.CurrentApp().Settings().AddChangeListener(listen) | ||
go func() { | ||
for range listen { | ||
bgColor = withAlpha(theme.BackgroundColor(), 0xe0) | ||
bg.FillColor = bgColor | ||
bg.Refresh() | ||
|
||
shadowColor = withAlpha(theme.BackgroundColor(), 0x33) | ||
footerBG.FillColor = bgColor | ||
footer.Refresh() | ||
} | ||
}() | ||
|
||
underlay.Resize(fyne.NewSize(512, 512)) | ||
scroll.OnScrolled = func(p fyne.Position) { | ||
underlayer.offset = -p.Y / 3 | ||
underlayer.Layout(slideBG.Objects, slideBG.Size()) | ||
} | ||
|
||
bgClip := container.NewScroll(slideBG) | ||
bgClip.Direction = container.ScrollNone | ||
return container.NewStack(container.New(unpad{top: true}, bgClip, bg), | ||
container.NewBorder(nil, | ||
container.NewStack(footerBG, footer), nil, nil, | ||
container.New(unpad{top: true, bottom: true}, scroll))) | ||
} | ||
|
||
func withAlpha(c color.Color, alpha uint8) color.Color { | ||
r, g, b, _ := c.RGBA() | ||
return color.NRGBA{R: uint8(r >> 8), G: uint8(g >> 8), B: uint8(b >> 8), A: alpha} | ||
} | ||
|
||
type underLayout struct { | ||
offset float32 | ||
} | ||
|
||
func (u underLayout) Layout(objs []fyne.CanvasObject, size fyne.Size) { | ||
under := objs[0] | ||
left := size.Width/2 - under.Size().Width/2 | ||
under.Move(fyne.NewPos(left, u.offset-50)) | ||
} | ||
|
||
func (u underLayout) MinSize(_ []fyne.CanvasObject) fyne.Size { | ||
return fyne.Size{} | ||
} | ||
|
||
type unpad struct { | ||
top, bottom bool | ||
} | ||
|
||
func (u unpad) Layout(objs []fyne.CanvasObject, s fyne.Size) { | ||
pad := theme.Padding() | ||
var pos fyne.Position | ||
if u.top { | ||
pos = fyne.NewPos(0, -pad) | ||
} | ||
size := s | ||
if u.top { | ||
size = size.AddWidthHeight(0, pad) | ||
} | ||
if u.bottom { | ||
size = size.AddWidthHeight(0, pad) | ||
} | ||
for _, o := range objs { | ||
o.Move(pos) | ||
o.Resize(size) | ||
} | ||
} | ||
|
||
func (u unpad) MinSize(_ []fyne.CanvasObject) fyne.Size { | ||
return fyne.NewSize(100, 100) | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.