mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
Add SetLabel, minor api updates
This commit is contained in:
parent
1947a9a17a
commit
ee5ca1a84a
6 changed files with 43 additions and 8 deletions
|
|
@ -62,6 +62,10 @@ void SetMenuItemChecked(void* nsMenuItem, int checked);
|
|||
void NewNSStatusItem(int id, int length);
|
||||
void SetTrayMenu(void *nsStatusItem, void* nsMenu);
|
||||
void SetTrayMenuLabel(void *nsStatusItem, const char *label);
|
||||
void SetTrayImage(void *nsStatusItem, void *imageData, int imageDataLength, int template, int position);
|
||||
|
||||
/* MenuItems */
|
||||
void SetMenuItemLabel(void *nsStatusItem, const char *label);
|
||||
|
||||
void SetAbout(void *inctx, const char* title, const char* description, void* imagedata, int datalen);
|
||||
void* AppendMenuItem(void* inctx, void* nsmenu, const char* label, const char* shortcutKey, int modifiers, int disabled, int checked, int menuItemID);
|
||||
|
|
@ -70,7 +74,6 @@ void UpdateMenuItem(void* nsmenuitem, int checked);
|
|||
|
||||
NSString* safeInit(const char* input);
|
||||
|
||||
void SetTrayImage(void *nsStatusItem, void *imageData, int imageDataLength, int template, int position);
|
||||
|
||||
int ScalingFactor(void *ctx);
|
||||
|
||||
|
|
|
|||
|
|
@ -295,12 +295,16 @@ void DeleteStatusItem(void *_nsStatusItem) {
|
|||
[nsStatusItem release];
|
||||
}
|
||||
|
||||
void on_main_thread(void (^l)(void)) {
|
||||
dispatch_async(dispatch_get_main_queue(), l);
|
||||
}
|
||||
|
||||
void SetTrayMenuLabel(void *_nsStatusItem, const char *label) {
|
||||
ON_MAIN_THREAD(
|
||||
on_main_thread(^{
|
||||
NSStatusItem *nsStatusItem = (NSStatusItem*) _nsStatusItem;
|
||||
nsStatusItem.button.title = safeInit(label);
|
||||
free((void*)label);
|
||||
)
|
||||
free((void*)label);
|
||||
});
|
||||
}
|
||||
|
||||
void SetTrayMenu(void *nsStatusItem, void* nsMenu) {
|
||||
|
|
@ -310,6 +314,16 @@ void SetTrayMenu(void *nsStatusItem, void* nsMenu) {
|
|||
}
|
||||
|
||||
|
||||
/**** Menu Item ****/
|
||||
|
||||
void SetMenuItemLabel(void *_nsMenuItem, const char *label) {
|
||||
on_main_thread(^{
|
||||
NSMenuItem *nsMenuItem = (NSMenuItem*) _nsMenuItem;
|
||||
[ nsMenuItem setTitle:safeInit(label) ];
|
||||
free((void*)label);
|
||||
});
|
||||
}
|
||||
|
||||
void* NewMenu(const char *name) {
|
||||
NSString *title = @"";
|
||||
if (name != nil) {
|
||||
|
|
|
|||
|
|
@ -131,6 +131,11 @@ func (m *MenuItem) SetChecked(value bool) {
|
|||
C.SetMenuItemChecked(m.nsmenuitem, bool2Cint(value))
|
||||
}
|
||||
|
||||
func (m *MenuItem) SetLabel(label string) {
|
||||
cLabel := C.CString(label)
|
||||
C.SetMenuItemLabel(m.nsmenuitem, cLabel)
|
||||
}
|
||||
|
||||
func (m *NSMenu) AddMenuItem(menuItem *menu.MenuItem) *MenuItem {
|
||||
c := NewCalloc()
|
||||
defer c.Free()
|
||||
|
|
|
|||
|
|
@ -46,6 +46,10 @@ type DevWebServer struct {
|
|||
devServerAddr string
|
||||
}
|
||||
|
||||
func (d *DevWebServer) TrayMenuAdd(trayMenu *menu.TrayMenu) menu.TrayMenuImpl {
|
||||
return d.desktopFrontend.TrayMenuAdd(trayMenu)
|
||||
}
|
||||
|
||||
func (d *DevWebServer) WindowSetSystemDefaultTheme() {
|
||||
d.desktopFrontend.WindowSetSystemDefaultTheme()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,17 +50,17 @@ func (m *Menu) AddSeparator() *MenuItem {
|
|||
return item
|
||||
}
|
||||
|
||||
func (m *Menu) AddSubmenu(label string) *Menu {
|
||||
func (m *Menu) AddSubmenu(label string) *MenuItem {
|
||||
submenu := NewMenu()
|
||||
item := SubMenu(label, submenu)
|
||||
m.Append(item)
|
||||
return submenu
|
||||
return item
|
||||
}
|
||||
|
||||
func (m *Menu) InsertSubmenu(label string, submenu *Menu) *Menu {
|
||||
func (m *Menu) InsertSubmenu(label string, submenu *Menu) *MenuItem {
|
||||
item := SubMenu(label, submenu)
|
||||
m.Append(item)
|
||||
return submenu
|
||||
return item
|
||||
}
|
||||
|
||||
func (m *Menu) Prepend(item *MenuItem) {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
type MenuItemImpl interface {
|
||||
SetChecked(bool)
|
||||
SetLabel(string)
|
||||
}
|
||||
|
||||
// MenuItem represents a menuitem contained in a menu
|
||||
|
|
@ -230,6 +231,14 @@ func (m *MenuItem) SetChecked(b bool) {
|
|||
}
|
||||
}
|
||||
|
||||
func (m *MenuItem) SetLabel(name string) {
|
||||
if m.Label == name {
|
||||
return
|
||||
}
|
||||
m.Label = name
|
||||
m.Impl.SetLabel(name)
|
||||
}
|
||||
|
||||
// Text is a helper to create basic Text menu items
|
||||
func Text(label string, accelerator *keys.Accelerator, click Callback) *MenuItem {
|
||||
return &MenuItem{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue