|
1 | | -import React, { useState } from "react"; |
2 | | -import { Renderer, Window, Button } from "./index"; |
3 | | -import { BoxView } from "./components/BoxView"; |
4 | | -import { useEventHandler } from "./hooks"; |
5 | | -import { QPushButtonSignals, Direction } from "@nodegui/nodegui"; |
| 1 | +import React from "react"; |
| 2 | +import { Renderer, Window, MenuBar, Menu } from "./index"; |
| 3 | +import { QAction, QApplication } from "@nodegui/nodegui"; |
6 | 4 |
|
7 | | -const App = () => { |
8 | | - const [additionalButtons, setAdditionalButtons] = useState<string[]>([]); |
9 | | - const [direction, setDirection] = useState<Direction>(Direction.LeftToRight); |
| 5 | +const quitAction = new QAction(); |
| 6 | +quitAction.setText("Quit"); |
| 7 | +quitAction.addEventListener("triggered", () => { |
| 8 | + const app = QApplication.instance(); |
| 9 | + app.exit(0); |
| 10 | +}); |
10 | 11 |
|
11 | | - const addHandler = useEventHandler<QPushButtonSignals>( |
12 | | - { |
13 | | - clicked: () => |
14 | | - setAdditionalButtons((buttons) => [ |
15 | | - ...buttons, |
16 | | - `Button ${buttons.length}`, |
17 | | - ]), |
18 | | - }, |
19 | | - [] |
20 | | - ); |
| 12 | +const fileActions: QAction[] = [quitAction]; |
21 | 13 |
|
22 | | - const removeHandler = useEventHandler<QPushButtonSignals>( |
23 | | - { |
24 | | - clicked: () => |
25 | | - setAdditionalButtons((buttons) => buttons.slice(0, buttons.length - 1)), |
26 | | - }, |
27 | | - [] |
28 | | - ); |
| 14 | +const sayHi = new QAction(); |
| 15 | +sayHi.setText("Hello"); |
| 16 | +sayHi.addEventListener("triggered", () => { |
| 17 | + console.log("hello"); |
| 18 | +}); |
29 | 19 |
|
30 | | - const toggleDirection = useEventHandler<QPushButtonSignals>( |
31 | | - { |
32 | | - clicked: () => |
33 | | - setDirection((prevDirection) => ((prevDirection + 1) % 4) as Direction), |
34 | | - }, |
35 | | - [] |
36 | | - ); |
| 20 | +const randActions: QAction[] = [sayHi]; |
37 | 21 |
|
| 22 | +const App = () => { |
38 | 23 | return ( |
39 | 24 | <Window> |
40 | | - <BoxView direction={direction}> |
41 | | - <Button text="Add" on={addHandler} /> |
42 | | - <Button text="Remove" on={removeHandler} /> |
43 | | - <Button text="Toggle direction" on={toggleDirection} /> |
44 | | - {additionalButtons.map((button) => ( |
45 | | - <Button key={button} text={button} /> |
46 | | - ))} |
47 | | - </BoxView> |
| 25 | + <MenuBar> |
| 26 | + <Menu title={"File"} actions={fileActions} /> |
| 27 | + <Menu title={"Random"} actions={randActions} /> |
| 28 | + </MenuBar> |
48 | 29 | </Window> |
49 | 30 | ); |
50 | 31 | }; |
|
0 commit comments