Skip to content

doc - menubar enhancement #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions resources/views/docs/1/the-basics/menu-bar.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ To remove the label, you may pass an empty string to the `label()` method.
MenuBar::label('');
```

### Tooltip

Add a tooltip to the menu bar icon:
```php
MenuBar::tooltip('Click to open');
```

## Configuring the Menu Bar

### Menu Bar URL
Expand Down Expand Up @@ -162,6 +169,17 @@ MenuBar::create()
->icon(storage_path('app/menuBarIconTemplate.png'));
```

### Vibrancy and Background Color

For macOS, you may use the `vibrancy` method to apply window vibrancy effects:
```php
MenuBar::create()->vibrancy('light');
```

To create a solid background color instead:
```php
MenuBar::create()->backgroundColor('#ffffff');
```
### Menu Bar Window Sizes

![Menu Bar Window Sizes](/img/docs/menubar-window-size.png)
Expand All @@ -176,6 +194,22 @@ MenuBar::create()
->height(600);
```

### Resizable Window

Allow or prevent resizing of the menu bar window:
```php
MenuBar::resizable(false);
```

### Positioning

You may manually set the position of the menu bar window:
```php
MenuBar::create()
->x(100)
->y(200);
```

### Menu Bar on Top

When developing a menu bar application, you may want to make sure that the menu bar window is always open and on top of all other windows.
Expand Down Expand Up @@ -223,6 +257,23 @@ window events to the `nativephp` broadcast channel.

To learn more about NativePHP's broadcasting capabilities, please refer to the [Broadcasting](/docs/digging-deeper/broadcasting) section.

### Listening for Custom Events

Attach a custom event that should be fired when the menu bar icon is clicked. This only works when combined with [`onlyShowContextMenu()`](#context-menu-only):
```php
MenuBar::create()->event(MenuBarClicked::class);

class MenuBarClicked
{
public function __construct(public array $combo, public array $bounds, public array $position)
{
// $combo - details of any combo keys pressed when the click occurred
// $bounds - the current absolute bounds of the menu bar icon at the time of the event
// $position - the absolute cursor position at the time of the event
}
}
```

### `MenuBarShown`

The `Native\Laravel\Events\MenuBar\MenuBarShown` event will be dispatched when the user clicks on the menu bar icon and the menu bar window opens, or when
Expand All @@ -236,3 +287,10 @@ the menu bar gets hidden by using the `MenuBar::hide()` method.
### `MenuBarContextMenuOpened`

The `Native\Laravel\Events\MenuBar\MenuBarContextMenuOpened` event will be dispatched when the user right-clicks on the menu bar icon and the context menu opens.

### Context Menu Only

Show only the context menu without opening a window when the menu bar icon is clicked:
```php
MenuBar::onlyShowContextMenu();
```