forked from joejulian/gio
example/kitchen: dump screenshots in 1.5 scale
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -13,7 +13,9 @@ import (
|
||||
"image/png"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"gioui.org/app"
|
||||
"gioui.org/app/headless"
|
||||
@@ -31,6 +33,10 @@ import (
|
||||
|
||||
var screenshot = flag.String("screenshot", "", "save a screenshot to a file and exit")
|
||||
|
||||
type scaledConfig struct {
|
||||
Scale float32
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
editor.SetText(longText)
|
||||
@@ -57,13 +63,14 @@ func main() {
|
||||
}
|
||||
|
||||
func saveScreenshot(f string) error {
|
||||
sz := image.Point{X: 800, Y: 600}
|
||||
const scale = 1.5
|
||||
sz := image.Point{X: 800 * scale, Y: 600 * scale}
|
||||
w, err := headless.NewWindow(sz.X, sz.Y)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gtx := new(layout.Context)
|
||||
gtx.Reset(nil, sz)
|
||||
gtx.Reset(&scaledConfig{scale}, sz)
|
||||
th := material.NewTheme()
|
||||
kitchen(gtx, th)
|
||||
w.Frame(gtx.Ops)
|
||||
@@ -183,6 +190,18 @@ func kitchen(gtx *layout.Context, th *material.Theme) {
|
||||
})
|
||||
}
|
||||
|
||||
func (s *scaledConfig) Now() time.Time {
|
||||
return time.Now()
|
||||
}
|
||||
|
||||
func (s *scaledConfig) Px(v unit.Value) int {
|
||||
scale := s.Scale
|
||||
if v.U == unit.UnitPx {
|
||||
scale = 1
|
||||
}
|
||||
return int(math.Round(float64(scale * v.V)))
|
||||
}
|
||||
|
||||
const longText = `1. I learned from my grandfather, Verus, to use good manners, and to
|
||||
put restraint on anger. 2. In the famous memory of my father I had a
|
||||
pattern of modesty and manliness. 3. Of my mother I learned to be
|
||||
|
||||
Reference in New Issue
Block a user