From fdabd847c6288292a2f7b681a49e715165ecf248 Mon Sep 17 00:00:00 2001 From: surtur Date: Tue, 24 May 2022 23:27:39 +0200 Subject: [PATCH] app: add 'about' page --- xkcdreader/about.go | 92 +++++++++++++++++++ xkcdreader/app.go | 1 + xkcdreader/app_test.go | 2 +- xkcdreader/assets/standard-license-header.txt | 14 +++ 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 xkcdreader/about.go create mode 100644 xkcdreader/assets/standard-license-header.txt diff --git a/xkcdreader/about.go b/xkcdreader/about.go new file mode 100644 index 0000000..37de5f7 --- /dev/null +++ b/xkcdreader/about.go @@ -0,0 +1,92 @@ +// Copyright 2022 wanderer +// SPDX-License-Identifier: GPL-3.0-or-later + +package xkcdreader + +import ( + // for embedding standard license header + _ "embed" + "log" + + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/layout" + "fyne.io/fyne/v2/widget" + "git.dotya.ml/wanderer/go-xkcdreader/cmd" +) + +type project struct { + name string + version string + homepage string + codeHomepage string + author string + license string +} + +var authorInfo = "Adam Mirre " +var projectURL = "https://git.dotya.ml/wanderer/go-xkcdreader" + +//go:embed assets/standard-license-header.txt +var l string + +func aboutWindow() { + app := getApp() + w := app.NewWindow("about - " + cmd.GetAppName()) + + projectInfo := &project{ + name: cmd.GetAppName(), + homepage: projectURL, + codeHomepage: projectURL, + version: cmd.GetShortVersion(), + author: authorInfo, + license: "GPL-3.0-or-later", + } + aboutTitle := container.New( + layout.NewHBoxLayout(), + &layout.Spacer{}, + &widget.Label{Text: "About", TextStyle: fyne.TextStyle{Bold: true}}, + &layout.Spacer{}, + ) + licenseScroll := container.NewScroll( + &widget.Label{Text: l, TextStyle: fyne.TextStyle{Monospace: true}}, + ) + licenseScroll.SetMinSize(fyne.Size{Height: 200, Width: 300}) + + ac := widget.NewAccordion(widget.NewAccordionItem( + projectInfo.license, + licenseScroll, + )) + + homepageScroll := container.NewHScroll( + &widget.Hyperlink{Text: projectInfo.codeHomepage, TextStyle: fyne.TextStyle{Monospace: true}}, + ) + homepageScroll.SetMinSize(fyne.Size{Width: 300}) + + about := container.New( + layout.NewFormLayout(), + &widget.Label{Text: "Name and version"}, + &widget.Label{Text: projectInfo.name + " - " + projectInfo.version, TextStyle: fyne.TextStyle{Bold: true}}, + &widget.Label{Text: "Author"}, + &widget.Label{Text: projectInfo.author, TextStyle: fyne.TextStyle{Bold: true}}, + &widget.Label{Text: "Project homepage"}, + homepageScroll, + &widget.Label{Text: "License"}, + ac, + ) + + w.SetContent(container.NewVBox( + aboutTitle, + container.NewHBox( + &layout.Spacer{}, + about, + &layout.Spacer{}, + ), + )) + + w.Resize(fyne.NewSize(600, 420)) + + log.Println("Show About window") + + w.Show() +} diff --git a/xkcdreader/app.go b/xkcdreader/app.go index 160e4e7..19a445d 100644 --- a/xkcdreader/app.go +++ b/xkcdreader/app.go @@ -73,6 +73,7 @@ func makeToolbar() *widget.Toolbar { widget.NewToolbarAction(theme.SettingsIcon(), func() { log.Println("Display settings") }), + widget.NewToolbarAction(theme.InfoIcon(), aboutWindow), ) return toolbar } diff --git a/xkcdreader/app_test.go b/xkcdreader/app_test.go index d152bcc..e2f94b5 100644 --- a/xkcdreader/app_test.go +++ b/xkcdreader/app_test.go @@ -19,7 +19,7 @@ func TestGreetingText(t *testing.T) { } func TestToolbar(t *testing.T) { - wantItems := 4 + wantItems := 5 gotToolbar := makeToolbar() if len(gotToolbar.Items) != wantItems { diff --git a/xkcdreader/assets/standard-license-header.txt b/xkcdreader/assets/standard-license-header.txt new file mode 100644 index 0000000..d99066f --- /dev/null +++ b/xkcdreader/assets/standard-license-header.txt @@ -0,0 +1,14 @@ +an offline-capable xkcd webcomic reader written in Go +Copyright (C) 2022 Adam Mirre + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see .