|
1 |
| -# Custom Electron Titlebar 4 |
| 1 | +# Custom Electron Titlebar |
2 | 2 |
|
3 | 3 | This project is a typescript library for electron that allows you to configure a fully customizable title bar.
|
4 | 4 |
|
5 | 5 | [](https://github.com/AlexTorresSk/custom-electron-titlebar/blob/master/LICENSE)
|
6 | 6 | [](https://npmjs.org/package/custom-electron-titlebar)
|
7 | 7 |
|
8 |
| -<img width="100%" src="screenshots/cet-001.png"> |
9 |
| -<img width="100%" src="screenshots/cet-002.png"> |
| 8 | + |
10 | 9 |
|
11 |
| -## Install |
| 10 | + |
12 | 11 |
|
| 12 | +## 🟢 Install |
13 | 13 | ```
|
14 |
| -npm i custom-electron-titlebar |
| 14 | +npm install custom-electron-titlebar |
15 | 15 | ```
|
16 | 16 |
|
17 |
| -or use example folder to init basic electron project with this titlebar. |
18 |
| - |
19 |
| -## Usage |
20 |
| - |
21 |
| -#### Step 1 |
22 |
| -In your **preload** file add: |
23 |
| - |
24 |
| -For javascript |
25 |
| - |
26 |
| -```js |
27 |
| -const customTitlebar = require('custom-electron-titlebar'); |
28 |
| - |
29 |
| -new customTitlebar.Titlebar({ |
30 |
| - backgroundColor: customTitlebar.Color.fromHex('#ECECEC') |
31 |
| -}); |
32 |
| -``` |
33 |
| - |
34 |
| -For typescript |
35 |
| -```ts |
36 |
| -import { Titlebar, Color } from 'custom-electron-titlebar' |
37 |
| - |
38 |
| -new Titlebar({ |
39 |
| - backgroundColor: Color.fromHex('#ECECEC') |
40 |
| -}); |
41 |
| -``` |
42 |
| - |
43 |
| -The parameter `backgroundColor: Color` is required, this should be `Color` type. |
44 |
| -(View [Update Background](#update-background) for more details). |
45 |
| - |
46 |
| -#### Step 2 |
47 |
| -Update the code that launches browser window |
48 |
| -```js |
49 |
| -let mainWindow = new BrowserWindow({ |
50 |
| - width: 1000, |
51 |
| - height: 600, |
52 |
| - titleBarStyle: "hidden", // add this line |
53 |
| - webPreferences: { |
54 |
| - preload: path.join(__dirname, 'preload.js') |
55 |
| - } |
56 |
| -}); |
57 |
| -``` |
58 |
| - |
59 |
| -## Options |
60 |
| - |
61 |
| -The interface [`TitleBarOptions`] is managed, which has the following configurable options for the title bar. Some parameters are optional. |
62 |
| - |
63 |
| -| Parameter | Type | Description | Default | |
64 |
| -| ------------------------------ | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------- | ------------------------- | |
65 |
| -| backgroundColor **(required)** | Color | The background color of the titlebar. | #444444 | |
66 |
| -| icon | string | The icon shown on the left side of the title bar. | null | |
67 |
| -| shadow | boolean | The shadow of the titlebar. | false | |
68 |
| -| drag | boolean | Define whether or not you can drag the window by holding the click on the title bar. | true | |
69 |
| -| onMinimize | Funtion | Enables or disables the option to minimize the window by clicking on the corresponding button in the title bar. | undefined | |
70 |
| -| onMaximize | Funtion | Enables or disables the option to maximize and un-maximize the window by clicking on the corresponding button in the title bar. | undefined | |
71 |
| -| onClose | Funtion | Enables or disables the option of the close window by clicking on the corresponding button in the title bar. | undefined | |
72 |
| -| isMaximized | Funtion | Check if window is maximized. | undefined | |
73 |
| -| onMenuItemClick | Funtion(commandId: number)| Fires when any menu option is pressed. | undefined | |
74 |
| -| order | string | Set the order of the elements on the title bar. (`inverted`, `first-buttons`) | null | |
75 |
| -| titleHorizontalAlignment | string | Set horizontal alignment of the window title. (`left`, `center`, `right`) | center | |
76 |
| -| menuPosition | string | The position of menubar on titlebar. | left | |
77 |
| -| enableMnemonics | boolean | Enable the mnemonics on menubar and menu items. | true | |
78 |
| -| hideWhenClickingClose | boolean | When the close button is clicked, the window is hidden instead of closed. | false | |
79 |
| -| overflow | string | The overflow of the container (`auto`, `visible`, `hidden`) | auto | |
80 |
| -| unfocusEffect | boolean | Enables or disables the blur option in the title bar. | false | |
81 |
| - |
82 |
| -## Methods |
83 |
| - |
84 |
| -### Update Background |
85 |
| - |
86 |
| -This change the color of titlebar and it's checked whether the color is light or dark, so that the color of the icons adapts to the background of the title bar. |
87 |
| - |
88 |
| -```js |
89 |
| -titlebar.updateBackground(new Color(new RGBA(0, 0, 0, .7))); |
90 |
| -``` |
91 |
| - |
92 |
| -To assign colors you can use the following options: `Color.fromHex()`, `new Color(new RGBA(r, g, b, a))`, `new Color(new HSLA(h, s, l, a))`, `new Color(new HSVA(h, s, v, a))` or `Color.BLUE`, `Color.RED`, etc. |
93 |
| - |
94 |
| -### Update Items Background Color |
95 |
| - |
96 |
| -This method change background color on hover of items of menubar. |
97 |
| - |
98 |
| -```js |
99 |
| -titlebar.updateItemBGColor(new Color(new RGBA(0, 0, 0, .7))); |
100 |
| -``` |
101 |
| - |
102 |
| -To assign colors you can use the following options: `Color.fromHex()`, `new Color(new RGBA(r, g, b, a))`, `new Color(new HSLA(h, s, l, a))`, `new Color(new HSVA(h, s, v, a))` or `Color.BLUE`, `Color.RED`, etc. |
103 |
| - |
104 |
| -### Update Title |
105 |
| - |
106 |
| -This method updated the title of the title bar, If you change the content of the `title` tag, you should call this method for update the title. |
107 |
| - |
108 |
| -```js |
109 |
| -document.title = 'My new title'; |
110 |
| -titlebar.updateTitle(); |
111 |
| - |
112 |
| -// Or you can do as follows and avoid writing document.title |
113 |
| -titlebar.updateTitle('New Title'); |
114 |
| -``` |
115 |
| - |
116 |
| -if this method is called and the title parameter is added, the title of the document is changed to that of the parameter. |
117 |
| - |
118 |
| -### Update Icon |
119 |
| - |
120 |
| -With this method you can update the icon. This method receives the url of the image _(it is advisable to use transparent image formats)_ |
121 |
| - |
122 |
| -```js |
123 |
| -titlebar.updateIcon('./images/my-icon.svg'); |
124 |
| -``` |
125 |
| - |
126 |
| -### Update Menu Position |
127 |
| - |
128 |
| -You can change the position of the menu bar. `left` and `bottom` are allowed. |
129 |
| - |
130 |
| -```js |
131 |
| -titlebar.updateMenuPosition('bottom'); |
132 |
| -``` |
133 |
| - |
134 |
| -### Set Horizontal Alignment |
135 |
| - |
136 |
| -You can change the position of the title of title bar. `left`, `center` and `right` are allowed |
137 |
| - |
138 |
| -```js |
139 |
| -titlebar.setHorizontalAlignment('right'); |
140 |
| -``` |
141 |
| - |
142 |
| -### Dispose |
143 |
| - |
144 |
| -This method removes the title bar completely and all recorded events. |
145 |
| - |
146 |
| -```js |
147 |
| -titlebar.dispose(); |
148 |
| -``` |
149 |
| - |
150 |
| -## License |
| 17 | +## 🚀 Usage |
| 18 | +To see the documentation on how to use the title bar, visit the [Wiki](https://github.com/AlexTorresSk/custom-electron-titlebar/wiki) |
151 | 19 |
|
| 20 | +## ✅ License |
152 | 21 | This project is under the [MIT](https://github.com/AlexTorresSk/custom-electron-titlebar/blob/master/LICENSE) license.
|
| 22 | + |
| 23 | +## 💰 Support |
| 24 | +If you want to support my development, you can do so by donating through [Buy me a coffee](https://www.buymeacoffee.com/AlexTorresSk), [Paypal](https://www.paypal.com/paypalme/hapovedat) or [Patreon](https://www.patreon.com/AlexTorresSk) |
0 commit comments