Put the titlebar elsewhere
Last updated
Last updated
What if you don't want your window's titlebar to be at the very top of the window? Take the File Manager for example, its titlebar is to the right of the sidebar, which immediately indicates it's not being rendered outside the window body like normal titlebars. In first-party apps I do this using the <CustomTitlebar/>
svelte component, which is a recreation of the regular titlebar in Svelte that can be put anywhere. But you're in luck! I've added a similar system for third-party apps to allow you to put the titlebar wherever you want.
Using the CustomTitlebar
class, you can put a titlebar wherever you want. It doesn't even have to be just one! The sky is the limit, even if I'd discourage you from having more than one titlebar as to not confuse your users.
To create a titlebar, simply construct the class, passing in your app's main process:
You can then call the render
method of this titlebar
constant to append the titlebar to any given HTML element. Keep in mind that you can only use a custom titlebar instance once: you'll have to call dispose
on it if you wish to relocate it. Let's render the titlebar on a div
named content
:
If you need a custom class name on that titlebar, you can also pass that in as a second argument in the class constructor, like so:
If you somehow need to access the titlebar's HTML element, or the target that the titlebar was appended to, I made methods for that:
If you want to get rid of the titlebar, or perhaps if you want to move it to another part of your app, call the dispose
method:
This removes the titlebar from its target and clears out the titlebar and target from the class instance, so that it's ready for new adventures.