scale.go 524 B

123456789101112131415161718192021222324
  1. package internal
  2. import (
  3. "math"
  4. "fyne.io/fyne/v2"
  5. )
  6. // ScaleInt converts a fyne coordinate in the given canvas to a screen coordinate
  7. func ScaleInt(c fyne.Canvas, v float32) int {
  8. return int(math.Ceil(float64(v * c.Scale())))
  9. }
  10. // UnscaleInt converts a screen coordinate for a given canvas to a fyne coordinate
  11. func UnscaleInt(c fyne.Canvas, v int) float32 {
  12. switch c.Scale() {
  13. case 0.0:
  14. panic("Incorrect scale most likely not set.")
  15. case 1.0:
  16. return float32(v)
  17. default:
  18. return float32(v) / c.Scale()
  19. }
  20. }