Helpers.kt 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright (c) Milan Jurkulák 2024.
  3. * Contact:
  4. * e: mimoccc@gmail.com
  5. * e: mj@mjdev.org
  6. * w: https://mjdev.org
  7. */
  8. package eu.mjdev.desktop.helpers.application.base
  9. import androidx.compose.ui.unit.Density
  10. import androidx.compose.ui.unit.LayoutDirection
  11. import java.awt.ComponentOrientation
  12. import java.awt.GraphicsConfiguration
  13. import java.awt.GraphicsEnvironment
  14. import java.util.*
  15. val GraphicsConfiguration.density: Density
  16. get() = Density(
  17. defaultTransform.scaleX.toFloat(),
  18. fontScale = 1f
  19. )
  20. val GlobalDensity
  21. get() = GraphicsEnvironment.getLocalGraphicsEnvironment()
  22. .defaultScreenDevice
  23. .defaultConfiguration
  24. .density
  25. val ComponentOrientation.layoutDirection: LayoutDirection
  26. get() = when {
  27. isLeftToRight -> LayoutDirection.Ltr
  28. isHorizontal -> LayoutDirection.Rtl
  29. else -> LayoutDirection.Ltr
  30. }
  31. val Locale.layoutDirection: LayoutDirection
  32. get() = ComponentOrientation.getOrientation(this).layoutDirection
  33. val GlobalLayoutDirection
  34. get() = Locale.getDefault().layoutDirection