Added more notification positions

This commit is contained in:
Robinson 2023-11-24 22:25:54 +01:00
parent 87a9e6ade4
commit 5ac55596de
No known key found for this signature in database
GPG Key ID: 8E7DB78588BD6F5C
4 changed files with 43 additions and 24 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2017 dorkbox, llc * Copyright 2023 dorkbox, llc
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -47,8 +47,11 @@ internal class AppNotify(override val notification: Notify): Canvas(), NotifyTyp
val screenWidth = bounds.getWidth().toInt() val screenWidth = bounds.getWidth().toInt()
return when (position) { return when (position) {
// LEFT ALIGN
Position.TOP_LEFT, Position.BOTTOM_LEFT -> Notify.MARGIN + startX Position.TOP_LEFT, Position.BOTTOM_LEFT -> Notify.MARGIN + startX
Position.CENTER -> startX + screenWidth / 2 - Notify.WIDTH / 2 - Notify.MARGIN / 2 // CENTER ALIGN
Position.TOP, Position.CENTER, Position.BOTTOM -> startX + screenWidth / 2 - Notify.WIDTH / 2 - Notify.MARGIN / 2
// RIGHT ALIGN
Position.TOP_RIGHT, Position.BOTTOM_RIGHT -> startX + screenWidth - Notify.WIDTH - Notify.MARGIN Position.TOP_RIGHT, Position.BOTTOM_RIGHT -> startX + screenWidth - Notify.WIDTH - Notify.MARGIN
} }
} }
@ -58,9 +61,12 @@ internal class AppNotify(override val notification: Notify): Canvas(), NotifyTyp
val screenHeight = bounds.getHeight().toInt() val screenHeight = bounds.getHeight().toInt()
return when (position) { return when (position) {
Position.TOP_LEFT, Position.TOP_RIGHT -> startY + Notify.MARGIN // TOP ALIGN
Position.TOP_LEFT, Position.TOP, Position.TOP_RIGHT -> startY + Notify.MARGIN
// CENTER ALIGN
Position.CENTER -> startY + screenHeight / 2 - Notify.HEIGHT / 2 - Notify.MARGIN / 2 - Notify.SPACER Position.CENTER -> startY + screenHeight / 2 - Notify.HEIGHT / 2 - Notify.MARGIN / 2 - Notify.SPACER
Position.BOTTOM_LEFT, Position.BOTTOM_RIGHT -> screenHeight - Notify.HEIGHT - Notify.MARGIN - Notify.SPACER * 2 // BOTTOM ALIGN
Position.BOTTOM_LEFT, Position.BOTTOM, Position.BOTTOM_RIGHT -> screenHeight - Notify.HEIGHT - Notify.MARGIN - Notify.SPACER * 2
} }
} }
} }

View File

@ -21,12 +21,7 @@ import dorkbox.tweenEngine.Tween
import dorkbox.tweenEngine.TweenEquations import dorkbox.tweenEngine.TweenEquations
import dorkbox.tweenEngine.TweenEvents import dorkbox.tweenEngine.TweenEvents
import dorkbox.util.ScreenUtil import dorkbox.util.ScreenUtil
import java.awt.Dimension import java.awt.*
import java.awt.Graphics
import java.awt.MouseInfo
import java.awt.Point
import java.awt.Rectangle
import java.awt.Toolkit
import java.awt.image.BufferedImage import java.awt.image.BufferedImage
import javax.swing.JWindow import javax.swing.JWindow
@ -47,8 +42,11 @@ internal class DesktopNotify(override val notification: Notify) : JWindow(), Not
val screenWidth = bounds.getWidth().toInt() val screenWidth = bounds.getWidth().toInt()
return when (position) { return when (position) {
// LEFT ALIGN
Position.TOP_LEFT, Position.BOTTOM_LEFT -> Notify.MARGIN + startX Position.TOP_LEFT, Position.BOTTOM_LEFT -> Notify.MARGIN + startX
Position.CENTER -> startX + screenWidth / 2 - Notify.WIDTH / 2 - Notify.MARGIN / 2 // CENTER ALIGN
Position.TOP, Position.CENTER, Position.BOTTOM -> startX + screenWidth / 2 - Notify.WIDTH / 2 - Notify.MARGIN / 2
// RIGHT ALIGN
Position.TOP_RIGHT, Position.BOTTOM_RIGHT -> startX + screenWidth - Notify.WIDTH - Notify.MARGIN Position.TOP_RIGHT, Position.BOTTOM_RIGHT -> startX + screenWidth - Notify.WIDTH - Notify.MARGIN
} }
} }
@ -58,9 +56,12 @@ internal class DesktopNotify(override val notification: Notify) : JWindow(), Not
val screenHeight = bounds.getHeight().toInt() val screenHeight = bounds.getHeight().toInt()
return when (position) { return when (position) {
Position.TOP_LEFT, Position.TOP_RIGHT -> startY + Notify.MARGIN // TOP ALIGN
Position.TOP_LEFT, Position.TOP, Position.TOP_RIGHT -> startY + Notify.MARGIN
// CENTER ALIGN
Position.CENTER -> startY + screenHeight / 2 - Notify.HEIGHT / 2 - Notify.MARGIN / 2 Position.CENTER -> startY + screenHeight / 2 - Notify.HEIGHT / 2 - Notify.MARGIN / 2
Position.BOTTOM_LEFT, Position.BOTTOM_RIGHT -> startY + screenHeight - Notify.HEIGHT - Notify.MARGIN // BOTTOM ALIGN
Position.BOTTOM_LEFT, Position.BOTTOM, Position.BOTTOM_RIGHT -> startY + screenHeight - Notify.HEIGHT - Notify.MARGIN
} }
} }
} }
@ -144,19 +145,16 @@ internal class DesktopNotify(override val notification: Notify) : JWindow(), Not
val gc = ScreenUtil.getMonitorAtLocation(point)?.defaultConfiguration ?: return 0 val gc = ScreenUtil.getMonitorAtLocation(point)?.defaultConfiguration ?: return 0
val screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc) val screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc)
if (showFromTop) { // " - Notify.MARGIN" is required BECAUSE each entry is offset by the margin, and we want the notification to be touching the edge!!
if (screenInsets.top > 0) { return if (showFromTop) {
return screenInsets.top - Notify.MARGIN screenInsets.top - Notify.MARGIN
}
} else { } else {
if (screenInsets.bottom > 0) { -(screenInsets.bottom - Notify.MARGIN)
return screenInsets.bottom + Notify.MARGIN
}
} }
return 0
} }
override fun paint(g: Graphics) { override fun paint(g: Graphics) {
// we cache the text + image (to an image), the two states of the close "button" and then always render the progressbar // we cache the text + image (to an image), the two states of the close "button" and then always render the progressbar
try { try {

View File

@ -152,9 +152,14 @@ internal object LAFUtil {
} }
} }
/**
* Controls which positions will grow the notification stack downwards
*
* @return true to grow downwards
*/
fun growDown(notify: NotifyType<*>): Boolean { fun growDown(notify: NotifyType<*>): Boolean {
return when (notify.notification.position) { return when (notify.notification.position) {
Position.TOP_LEFT, Position.TOP_RIGHT, Position.CENTER -> true Position.TOP_LEFT, Position.TOP, Position.TOP_RIGHT, Position.CENTER -> true
else -> false else -> false
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2015 dorkbox, llc * Copyright 2023 dorkbox, llc
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -26,11 +26,21 @@ enum class Position {
*/ */
TOP_RIGHT, TOP_RIGHT,
/**
* top vertically, center horizontally
*/
TOP,
/** /**
* center both vertically and horizontally * center both vertically and horizontally
*/ */
CENTER, CENTER,
/**
* bottom vertically, center horizontally
*/
BOTTOM,
/** /**
* bottom vertically, left horizontally * bottom vertically, left horizontally
*/ */