How To Register A Scooter Without Title
Acquire how to create a frameless window with custom controls (minimize, maximize and close buttons) in Electron Framework.
To create a window without chrome, or a transparent window in arbitrary shape, you lot demand to utilise the Frameless Window API. This "api" let you to create a frameless window that has no chrome, the parts of the window, like toolbars, that are not a part of the spider web folio.
In a browser, the chrome is whatever visible aspect of a browser aside from the webpages themselves (east.thousand., toolbars, menu bar, tabs).To create a frameless window, yous need to set the frame property to imitation in the BrowserWindow instance that you desire:
const {BrowserWindow} = require('electron') let win = new BrowserWindow({ width: 800, top: 600, frame: false }) win.show() Tipically, yous may want to enable this feature in your main Window (principal.js), that should be similar to:
function createWindow () { // Create the browser window. mainWindow = new BrowserWindow({width: 800, top: 600, frame: false}) // and load the index.html of the app. mainWindow.loadURL(`file://${__dirname}/index.html`) // Open the DevTools. mainWindow.webContents.openDevTools() // Emitted when the window is airtight. mainWindow.on('closed', role () { // Dereference the window object, usually y'all would store windows // in an array if your app supports multi windows, this is the time // when you should delete the respective element. mainWindow = null }) } Whose execution should create a window similar to:
However, you probably don't want to remove the user the possibility to close, minimize or maximize your app, then you demand to learn how to do information technology. Those methods are available in the BrowserWindow, and so you only need to retrieve the focused window using the BrowserWindow constant when you are in the renderer procedure:
const {BrowserWindow} = require('electron').remote; // Think focused window var theWindow = BrowserWindow.getFocusedWindow(); // Execute common tasks // Minimize theWindow.minimize(); // Maximize app theWindow.maximize(); // Close app theWindow.close(); The typical buttons but with some CSS and HTML
You can create the same toolbar that a desktop application uses with custom HTML and CSS.
In this case, we are going to use the post-obit markup:
<div id="championship-bar"> <div id="title"> <span style="vertical-marshal: eye;"> <img src="https://raw.githubusercontent.com/zeke/atom-icon/master/old-icon/2.png" fashion="width:20px;summit:20px;"/> </bridge> Our Code Earth Frameless (But draggable,resizable and closable Window) </div> <div id="title-bar-btns"> <button id="min-btn">-</button> <button id="max-btn">+</button> <button id="close-btn">x</button> </div> </div> And some style to make it wait "practiced":
torso { padding: 0px; margin: 0px; } #title-bar { -webkit-app-region: drag; acme: 40px; text-align: center; line-height: 40px; vertical-marshal: middle; groundwork-color: #03a9f4; padding: none; margin: 0px; } #title { position: fixed; superlative: 0px; left: 6px; color:white; } #championship-bar-btns { -webkit-app-region: no-elevate; position: fixed; top: 0px; correct: 6px; } Note that the title-bar form has the class that makes possible to drag the window effectually the screen, otherwise your user volition exist forced to work with your app in a static position in the screen (matter y'all probably don't want).-webkit-app-region: elevate; volition make the selected chemical element a betoken to drag the entire window around the screen in the aforementioned way that the original title bar does.
The final implementation in your index.html file should look like:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>My Electron Frameless Window</championship> <style> torso { padding: 0px; margin: 0px; } #title-bar { -webkit-app-region: drag; top: 40px; text-align: center; line-elevation: 40px; vertical-marshal: middle; groundwork-color: #03a9f4; padding: none; margin: 0px; } #championship { position: fixed; top: 0px; left: 6px; color:white; } #championship-bar-btns { -webkit-app-region: no-drag; position: fixed; top: 0px; right: 6px; } </style> </head> <body> <div id="title-bar"> <div id="title"> <span style="vertical-align: eye;"><img src="https://raw.githubusercontent.com/zeke/atom-icon/principal/sometime-icon/2.png" style="width:20px;superlative:20px;"/></span> Our Code Globe Frameless (Merely draggable,resizable and closable Window) </div> <div id="title-bar-btns"> <push id="min-btn">-</button> <push button id="max-btn">+</button> <button id="close-btn">10</push button> </div> </div> <div fashion="text-align:center;"> <h4>Electron rocks!</h4> <img src="http://ourcodeworld.com/resources/img/ocw-empty.png" width="300" height="300"/> </div> <script> (function () { // Retrieve remote BrowserWindow const {BrowserWindow} = require('electron').remote function init() { // Minimize chore document.getElementById("min-btn").addEventListener("click", (e) => { var window = BrowserWindow.getFocusedWindow(); window.minimize(); }); // Maximize window document.getElementById("max-btn").addEventListener("click", (eastward) => { var window = BrowserWindow.getFocusedWindow(); if(window.isMaximized()){ window.unmaximize(); }else{ window.maximize(); } }); // Close app document.getElementById("shut-btn").addEventListener("click", (eastward) => { var window = BrowserWindow.getFocusedWindow(); window.close(); }); }; document.onreadystatechange = () => { if (document.readyState == "complete") { init(); } }; })(); </script> </body> </html> And the consequence app volition look like:
Have fun !
Source: https://ourcodeworld.com/articles/read/287/how-to-create-a-custom-frameless-window-without-title-bar-with-minimize-maximize-and-close-controls-in-electron-framework
Posted by: steinvoiled.blogspot.com

0 Response to "How To Register A Scooter Without Title"
Post a Comment