mirror of
https://gitlab.com/cc-ru/ocelot/ocelot-desktop.git
synced 2025-12-20 02:59:19 +01:00
Tooltips should not clip through screen edges
This commit is contained in:
parent
e4aca89f92
commit
d533e33f2b
@ -10,7 +10,6 @@ import ocelot.desktop.util.Orientation
|
||||
import ocelot.desktop.util.animation.UnitAnimation
|
||||
|
||||
abstract class Tooltip extends Widget {
|
||||
protected def tooltipPool: TooltipPool = parent.get.asInstanceOf[TooltipPool]
|
||||
protected val openCloseAnimation: UnitAnimation = UnitAnimation.easeInOutQuad(0.3f)
|
||||
|
||||
val body: Widget = new Widget {
|
||||
|
||||
@ -10,7 +10,15 @@ import ocelot.desktop.util.animation.easing.Easing
|
||||
import scala.collection.mutable.ListBuffer
|
||||
|
||||
class TooltipPool extends Widget {
|
||||
val offset: Vector2D = Vector2D(10, 10)
|
||||
private val Offset = 10
|
||||
private val ScreenPadding = 10
|
||||
|
||||
private def offset(tooltip: Tooltip): Vector2D = {
|
||||
val mouse = UiHandler.mousePosition
|
||||
val x = if (mouse.x > width - tooltip.width - Offset - ScreenPadding) -Offset - tooltip.width else Offset
|
||||
val y = if (mouse.y > height - tooltip.height - Offset - ScreenPadding) -Offset - tooltip.height else Offset
|
||||
Vector2D(x, y)
|
||||
}
|
||||
|
||||
override protected val layout: Layout = new Layout(this) {
|
||||
override def relayout(): Unit = {
|
||||
@ -18,7 +26,7 @@ class TooltipPool extends Widget {
|
||||
tooltip.tooltip match {
|
||||
case t: Tooltip =>
|
||||
if (!(t.isClosing && tooltip.delay == 0))
|
||||
t.rawSetPosition(UiHandler.mousePosition + offset)
|
||||
t.rawSetPosition(UiHandler.mousePosition + offset(t))
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
@ -81,7 +89,7 @@ class TooltipPool extends Widget {
|
||||
dueToClean = true
|
||||
}
|
||||
tooltip.tooltip.position = tooltip.tooltip.position +
|
||||
(UiHandler.mousePosition + offset - tooltip.tooltip.position) *
|
||||
(UiHandler.mousePosition + offset(tooltip.tooltip) - tooltip.tooltip.position) *
|
||||
(if (tooltip.tooltip.isClosing) math.pow(Easing.easeInQuad(tooltip.tooltip.getAlpha), 6).toFloat else 1f)
|
||||
})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user