Add NLoader

This commit is contained in:
Ly-sec 2025-08-10 13:52:58 +02:00
parent c612347f0c
commit a7e17c25ef
5 changed files with 91 additions and 101 deletions

View file

@ -79,9 +79,7 @@ PanelWindow {
NIconButton { NIconButton {
id: demoPanelToggler id: demoPanelToggler
icon: "experiment" icon: "experiment"
onClicked: function () { onClicked: function () { demoPanel.isLoaded = !demoPanel.isLoaded }
demoPanel.visible ? demoPanel.hide() : demoPanel.show()
}
} }
} }
} }

View file

@ -10,12 +10,18 @@ import qs.Widgets
An experiment/demo panel to tweaks widgets An experiment/demo panel to tweaks widgets
*/ */
NLoader {
NPanel {
id: root id: root
panel: Component {
NPanel {
id: demoPanel
readonly property real scaling: Scaling.scale(screen) readonly property real scaling: Scaling.scale(screen)
// Ensure panel shows itself once created
Component.onCompleted: show()
Rectangle { Rectangle {
color: Colors.backgroundPrimary color: Colors.backgroundPrimary
radius: Style.radiusMedium * scaling radius: Style.radiusMedium * scaling
@ -25,11 +31,8 @@ NPanel {
height: 400 height: 400
anchors.centerIn: parent anchors.centerIn: parent
// Prevent closing when clicking in the panel bg // Prevent closing when clicking in the panel bg
MouseArea { MouseArea { anchors.fill: parent }
anchors.fill: parent
}
ColumnLayout { ColumnLayout {
anchors.fill: parent anchors.fill: parent
@ -39,71 +42,43 @@ NPanel {
// NIconButton // NIconButton
ColumnLayout { ColumnLayout {
spacing: 16 * scaling spacing: 16 * scaling
NText { NText { text: "NIconButton"; color: Colors.accentSecondary }
text: "NIconButton + NTooltip"
color: Colors.accentSecondary
}
NIconButton { NIconButton {
id: myIconButton id: myIconButton
icon: "refresh" icon: "refresh"
onEntered: function() { onEntered: function() { myTooltip.show() }
myTooltip.show(); onExited: function() { myTooltip.hide() }
}
onExited: function() {
myTooltip.hide();
}
}
NTooltip {
id: myTooltip
target: myIconButton
positionAbove: false
text: "Hello world"
} }
NDivider { Layout.fillWidth: true } NDivider { Layout.fillWidth: true }
} }
// NToggle // NToggle
ColumnLayout { ColumnLayout {
spacing: Style.marginLarge * scaling spacing: Style.marginLarge * scaling
uniformCellSizes: true uniformCellSizes: true
NText { NText { text: "NToggle + NTooltip"; color: Colors.accentSecondary }
text: "NToggle"
color: Colors.accentSecondary
}
NToggle { NToggle {
label: "Label" label: "Label"
description: "Description" description: "Description"
onToggled: function(value: bool) { onToggled: function(value: bool) { console.log("NToggle: " + value) }
console.log("NToggle: " + value)
}
} }
NTooltip { id: myTooltip; target: myIconButton; positionAbove: false; text: "Hello world" }
NDivider { NDivider { Layout.fillWidth: true }
Layout.fillWidth: true
}
} }
// NSlider // NSlider
ColumnLayout { ColumnLayout {
spacing: 16 * scaling spacing: 16 * scaling
NText { text: "NSlider"; color: Colors.accentSecondary }
NText {
text: "NSlider"
color: Colors.accentSecondary
}
NSlider {} NSlider {}
NDivider { NDivider { Layout.fillWidth: true }
Layout.fillWidth: true }
} }
} }
} }
} }
} }

31
Widgets/NLoader.qml Normal file
View file

@ -0,0 +1,31 @@
import QtQuick
Loader {
id: loader
// Boolean control to load/unload the item
property bool isLoaded: false
// Provide the component to load.
// Example usage:
// content: Component { NPanel { /* ... */ } }
property Component panel
active: isLoaded
asynchronous: true
sourceComponent: panel
onActiveChanged: {
if (active && item && item.show) item.show()
}
onItemChanged: {
if (active && item && item.show) item.show()
}
Connections {
target: loader.item
function onDismissed() { loader.isLoaded = false }
}
}

View file

@ -10,9 +10,11 @@ PanelWindow {
property bool showOverlay: Settings.settings.dimPanels property bool showOverlay: Settings.settings.dimPanels
property int topMargin: Style.barHeight * scaling property int topMargin: Style.barHeight * scaling
property color overlayColor: showOverlay ? Colors.overlay : "transparent" property color overlayColor: showOverlay ? Colors.overlay : "transparent"
signal dismissed()
function hide() { function hide() {
visible = false visible = false
dismissed()
} }
function show() { function show() {

View file

@ -24,22 +24,6 @@ ShellRoot {
Background {} Background {}
Overview {} Overview {}
// Variants {
// model: Quickshell.screens
// delegate: Background {
// modelData: item
// }
// }
// Variants {
// model: Quickshell.screens
// delegate: Overview {
// modelData: item
// }
// }
DemoPanel { DemoPanel {
id: demoPanel id: demoPanel
} }