quickshell-web/modules/Quickshell/LazyLoader.json
2024-09-28 02:35:19 +03:00

71 lines
5 KiB
JSON

{
"name": "LazyLoader",
"module": "Quickshell",
"type": "class",
"super": {
"type": "local",
"module": "Quickshell",
"name": "Reloadable"
},
"description": "Asynchronous component loader.",
"details": "The LazyLoader can be used to prepare components that don't need to be\ncreated immediately, such as windows that aren't visible until triggered\nby another action. It works on creating the component in the gaps between\nframe rendering to prevent blocking the interface thread.\nIt can also be used to preserve memory by loading components only\nwhen you need them and unloading them afterward.\n\nNote that when reloading the UI due to changes, lazy loaders will always\nload synchronously so windows can be reused.\n\n#### Example\nThe following example creates a PopupWindow asynchronously as the bar loads.\nThis means the bar can be shown onscreen before the popup is ready, however\ntrying to show the popup before it has finished loading in the background\nwill cause the UI thread to block.\n\n```qml\nimport QtQuick\nimport QtQuick.Controls\nimport Quickshell\n\nShellRoot {\n PanelWindow {\n id: window\n height: 50\n\n anchors {\n bottom: true\n left: true\n right: true\n }\n\n LazyLoader {\n id: popupLoader\n\n // start loading immediately\n loading: true\n\n // this window will be loaded in the background during spare\n // frame time unless active is set to true, where it will be\n // loaded in the foreground\n PopupWindow {\n // position the popup above the button\n parentWindow: window\n relativeX: window.width / 2 - width / 2\n relativeY: -height\n\n // some heavy component here\n\n width: 200\n height: 200\n }\n }\n\n Button {\n anchors.centerIn: parent\n text: \"show popup\"\n\n // accessing popupLoader.item will force the loader to\n // finish loading on the UI thread if it isn't finished yet.\n onClicked: popupLoader.item.visible = !popupLoader.item.visible\n }\n }\n}\n```\n\n> [!WARNING] Components that internally load other components must explicitly\n> support asynchronous loading to avoid blocking.\n>\n> Notably, TYPE99MQS_Quickshell99NVariants99TYPE does not corrently support asynchronous\n> loading, meaning using it inside a LazyLoader will block similarly to not\n> having a loader to start with.\n\n> [!WARNING] LazyLoaders do not start loading before the first window is created,\n> meaning if you create all windows inside of lazy loaders, none of them will ever load.\n",
"properties": {
"item": {
"type": {
"type": "qt",
"module": "qml.QtQml",
"name": "QtObject"
},
"details": "The fully loaded item if the loader is TYPE99Vloading99Tprop99TYPE or TYPE99Vactive99Tprop99TYPE, or `null`\nif neither TYPE99Vloading99Tprop99TYPE nor TYPE99Vactive99Tprop99TYPE.\n\nNote that the item is owned by the LazyLoader, and destroying the LazyLoader\nwill destroy the item.\n\n> [!WARNING] If you access the `item` of a loader that is currently loading,\n> it will block as if you had set `active` to true immediately beforehand.\n>\n> You can instead set TYPE99Vloading99Tprop99TYPE and listen to TYPE99VactiveChanged99Tsignal99TYPE signal to\n> ensure loading happens asynchronously.\n",
"flags": [
"readonly"
]
},
"source": {
"type": {
"type": "qt",
"module": "qml",
"name": "string"
},
"details": "The URI to load the component from. Mutually exclusive to TYPE99Vcomponent99Tprop99TYPE.\n"
},
"active": {
"type": {
"type": "qt",
"module": "qml",
"name": "bool"
},
"details": "If the component is fully loaded.\n\nSetting this property to `true` will force the component to load to completion,\nblocking the UI, and setting it to `false` will destroy the component, requiring\nit to be loaded again.\n\nSee also: TYPE99VactiveAsync99Tprop99TYPE.\n"
},
"loading": {
"type": {
"type": "qt",
"module": "qml",
"name": "bool"
},
"details": "If the loader is actively loading.\n\nIf the component is not loaded, setting this property to true will start\nloading it asynchronously. If the component is already loaded, setting\nthis property has no effect.\n\nSee also: TYPE99VactiveAsync99Tprop99TYPE.\n"
},
"activeAsync": {
"type": {
"type": "qt",
"module": "qml",
"name": "bool"
},
"details": "If the component is fully loaded.\n\nSetting this property to true will asynchronously load the component similarly to\nTYPE99Vloading99Tprop99TYPE. Reading it or setting it to false will behanve\nthe same as TYPE99Vactive99Tprop99TYPE.\n"
},
"component": {
"type": {
"type": "qt",
"module": "qml.QtQml",
"name": "Component"
},
"details": "The component to load. Mutually exclusive to TYPE99Vsource99Tprop99TYPE.\n",
"flags": [
"default"
]
}
},
"functions": [],
"signals": {},
"variants": {}
}