mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-07 22:15:38 -05:00
DankModal pixel snapping
This commit is contained in:
@@ -15,6 +15,15 @@ PanelWindow {
|
|||||||
property real height: 300
|
property real height: 300
|
||||||
readonly property real screenWidth: screen ? screen.width : 1920
|
readonly property real screenWidth: screen ? screen.width : 1920
|
||||||
readonly property real screenHeight: screen ? screen.height : 1080
|
readonly property real screenHeight: screen ? screen.height : 1080
|
||||||
|
readonly property real dpr: (screen && screen.devicePixelRatio) || 1
|
||||||
|
|
||||||
|
function snap(v) {
|
||||||
|
return Math.round(v * dpr) / dpr
|
||||||
|
}
|
||||||
|
|
||||||
|
function px(v) {
|
||||||
|
return Math.round(v)
|
||||||
|
}
|
||||||
property bool showBackground: true
|
property bool showBackground: true
|
||||||
property real backgroundOpacity: 0.5
|
property real backgroundOpacity: 0.5
|
||||||
property string positioning: "center"
|
property string positioning: "center"
|
||||||
@@ -134,22 +143,26 @@ PanelWindow {
|
|||||||
Rectangle {
|
Rectangle {
|
||||||
id: contentContainer
|
id: contentContainer
|
||||||
|
|
||||||
width: root.width
|
width: px(root.width)
|
||||||
height: root.height
|
height: px(root.height)
|
||||||
anchors.centerIn: positioning === "center" ? parent : undefined
|
anchors.centerIn: undefined
|
||||||
x: {
|
x: {
|
||||||
if (positioning === "top-right") {
|
if (positioning === "center") {
|
||||||
return Math.max(Theme.spacingL, root.screenWidth - width - Theme.spacingL)
|
return snap((root.screenWidth - width) / 2)
|
||||||
|
} else if (positioning === "top-right") {
|
||||||
|
return px(Math.max(Theme.spacingL, root.screenWidth - width - Theme.spacingL))
|
||||||
} else if (positioning === "custom") {
|
} else if (positioning === "custom") {
|
||||||
return root.customPosition.x
|
return snap(root.customPosition.x)
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
y: {
|
y: {
|
||||||
if (positioning === "top-right") {
|
if (positioning === "center") {
|
||||||
return Theme.barHeight + Theme.spacingXS
|
return snap((root.screenHeight - height) / 2)
|
||||||
|
} else if (positioning === "top-right") {
|
||||||
|
return px(Theme.barHeight + Theme.spacingXS)
|
||||||
} else if (positioning === "custom") {
|
} else if (positioning === "custom") {
|
||||||
return root.customPosition.y
|
return snap(root.customPosition.y)
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -159,13 +172,18 @@ PanelWindow {
|
|||||||
border.width: root.borderWidth
|
border.width: root.borderWidth
|
||||||
clip: false
|
clip: false
|
||||||
layer.enabled: true
|
layer.enabled: true
|
||||||
|
layer.smooth: false
|
||||||
|
layer.mipmap: false
|
||||||
transform: root.animationType === "slide" ? slideTransform : null
|
transform: root.animationType === "slide" ? slideTransform : null
|
||||||
|
|
||||||
Translate {
|
Translate {
|
||||||
id: slideTransform
|
id: slideTransform
|
||||||
|
|
||||||
x: root.shouldBeVisible ? 0 : 15
|
readonly property real rawX: root.shouldBeVisible ? 0 : 15
|
||||||
y: root.shouldBeVisible ? 0 : -30
|
readonly property real rawY: root.shouldBeVisible ? 0 : -30
|
||||||
|
|
||||||
|
x: snap(rawX)
|
||||||
|
y: snap(rawY)
|
||||||
}
|
}
|
||||||
|
|
||||||
FocusScope {
|
FocusScope {
|
||||||
@@ -197,7 +215,6 @@ PanelWindow {
|
|||||||
shadowBlur: 1
|
shadowBlur: 1
|
||||||
shadowColor: Theme.shadowStrong
|
shadowColor: Theme.shadowStrong
|
||||||
shadowOpacity: 0.3
|
shadowOpacity: 0.3
|
||||||
source: contentContainer
|
|
||||||
opacity: root.shouldBeVisible ? 1 : 0
|
opacity: root.shouldBeVisible ? 1 : 0
|
||||||
|
|
||||||
Behavior on opacity {
|
Behavior on opacity {
|
||||||
|
|||||||
Reference in New Issue
Block a user