mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 17:05:38 +00:00
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"
|
"image/png"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gioui.org/app"
|
"gioui.org/app"
|
||||||
"gioui.org/app/headless"
|
"gioui.org/app/headless"
|
||||||
@@ -31,6 +33,10 @@ import (
|
|||||||
|
|
||||||
var screenshot = flag.String("screenshot", "", "save a screenshot to a file and exit")
|
var screenshot = flag.String("screenshot", "", "save a screenshot to a file and exit")
|
||||||
|
|
||||||
|
type scaledConfig struct {
|
||||||
|
Scale float32
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
editor.SetText(longText)
|
editor.SetText(longText)
|
||||||
@@ -57,13 +63,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func saveScreenshot(f string) error {
|
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)
|
w, err := headless.NewWindow(sz.X, sz.Y)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
gtx := new(layout.Context)
|
gtx := new(layout.Context)
|
||||||
gtx.Reset(nil, sz)
|
gtx.Reset(&scaledConfig{scale}, sz)
|
||||||
th := material.NewTheme()
|
th := material.NewTheme()
|
||||||
kitchen(gtx, th)
|
kitchen(gtx, th)
|
||||||
w.Frame(gtx.Ops)
|
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
|
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
|
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
|
pattern of modesty and manliness. 3. Of my mother I learned to be
|
||||||
|
|||||||
Reference in New Issue
Block a user