Skip to content

Commit

Permalink
Capture text scale for Advanced pane
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Aug 9, 2021
1 parent 632b687 commit 163194d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions cmd/fyne_demo/tutorials/advanced.go
Expand Up @@ -14,14 +14,21 @@ func scaleString(c fyne.Canvas) string {
return strconv.FormatFloat(float64(c.Scale()), 'f', 2, 32)
}

func texScaleString(c fyne.Canvas) string {
pixels, _ := c.PixelCoordinateForPosition(fyne.NewPos(1, 1))
texScale := float32(pixels) / c.Scale()
return strconv.FormatFloat(float64(texScale), 'f', 2, 32)
}

func prependTo(g *fyne.Container, s string) {
g.Objects = append([]fyne.CanvasObject{widget.NewLabel(s)}, g.Objects...)
g.Refresh()
}

func setScaleText(obj *widget.Label, win fyne.Window) {
for obj.Visible() {
obj.SetText(scaleString(win.Canvas()))
func setScaleText(scale, tex *widget.Label, win fyne.Window) {
for scale.Visible() {
scale.SetText(scaleString(win.Canvas()))
tex.SetText(texScaleString(win.Canvas()))

time.Sleep(time.Second)
}
Expand All @@ -31,12 +38,14 @@ func setScaleText(obj *widget.Label, win fyne.Window) {
// more detailed than normally needed.
func advancedScreen(win fyne.Window) fyne.CanvasObject {
scale := widget.NewLabel("")
tex := widget.NewLabel("")

screen := widget.NewCard("Screen info", "", widget.NewForm(
&widget.FormItem{Text: "Scale", Widget: scale},
&widget.FormItem{Text: "Texture Scale", Widget: tex},
))

go setScaleText(scale, win)
go setScaleText(scale, tex, win)

label := widget.NewLabel("Just type...")
generic := container.NewVBox()
Expand Down

0 comments on commit 163194d

Please sign in to comment.