diff --git a/v2/internal/ffenestri/menu_darwin.c b/v2/internal/ffenestri/menu_darwin.c index 3526f752..1b6f7060 100644 --- a/v2/internal/ffenestri/menu_darwin.c +++ b/v2/internal/ffenestri/menu_darwin.c @@ -576,38 +576,7 @@ id processCheckboxMenuItem(Menu *menu, id parentmenu, const char *title, const c return item; } -id processTextMenuItem(Menu *menu, id parentMenu, const char *title, const char *menuid, bool disabled, const char *acceleratorkey, const char **modifiers, const char* tooltip, const char* image, const char* fontName, int fontSize, const char* RGBA, bool templateImage, bool alternate) { - id item = ALLOC("NSMenuItem"); - - // Create a MenuItemCallbackData - MenuItemCallbackData *callback = CreateMenuItemCallbackData(menu, item, menuid, Text); - - id wrappedId = msg(c("NSValue"), s("valueWithPointer:"), callback); - msg(item, s("setRepresentedObject:"), wrappedId); - - if( !alternate ) { - id key = processAcceleratorKey(acceleratorkey); - msg(item, s("initWithTitle:action:keyEquivalent:"), str(title), - s("menuItemCallback:"), key); - } else { - msg(item, s("initWithTitle:action:keyEquivalent:"), str(title), s("menuItemCallback:"), str("")); - } - - if( tooltip != NULL ) { - msg(item, s("setToolTip:"), str(tooltip)); - } - - // Process image - if( image != NULL && strlen(image) > 0) { - id data = ALLOC("NSData"); - id imageData = msg(data, s("initWithBase64EncodedString:options:"), str(image), 0); - id nsimage = ALLOC("NSImage"); - msg(nsimage, s("initWithData:"), imageData); - if( templateImage ) { - msg(nsimage, s("setTemplate:"), YES); - } - msg(item, s("setImage:"), nsimage); - } +id createAttributedString(const char* title, const char* fontName, int fontSize, const char* RGBA) { // Process Menu Item attributes id dictionary = ALLOC_INIT("NSMutableDictionary"); @@ -658,10 +627,46 @@ id processTextMenuItem(Menu *menu, id parentMenu, const char *title, const char id attributedString = ALLOC("NSMutableAttributedString"); msg(attributedString, s("initWithString:attributes:"), str(title), dictionary); - msg(dictionary, s("release")); - - msg(item, s("setAttributedTitle:"), attributedString); msg(attributedString, s("autorelease")); + msg(dictionary, s("release")); + return attributedString; +} + +id processTextMenuItem(Menu *menu, id parentMenu, const char *title, const char *menuid, bool disabled, const char *acceleratorkey, const char **modifiers, const char* tooltip, const char* image, const char* fontName, int fontSize, const char* RGBA, bool templateImage, bool alternate) { + id item = ALLOC("NSMenuItem"); + + // Create a MenuItemCallbackData + MenuItemCallbackData *callback = CreateMenuItemCallbackData(menu, item, menuid, Text); + + id wrappedId = msg(c("NSValue"), s("valueWithPointer:"), callback); + msg(item, s("setRepresentedObject:"), wrappedId); + + if( !alternate ) { + id key = processAcceleratorKey(acceleratorkey); + msg(item, s("initWithTitle:action:keyEquivalent:"), str(title), + s("menuItemCallback:"), key); + } else { + msg(item, s("initWithTitle:action:keyEquivalent:"), str(title), s("menuItemCallback:"), str("")); + } + + if( tooltip != NULL ) { + msg(item, s("setToolTip:"), str(tooltip)); + } + + // Process image + if( image != NULL && strlen(image) > 0) { + id data = ALLOC("NSData"); + id imageData = msg(data, s("initWithBase64EncodedString:options:"), str(image), 0); + id nsimage = ALLOC("NSImage"); + msg(nsimage, s("initWithData:"), imageData); + if( templateImage ) { + msg(nsimage, s("setTemplate:"), YES); + } + msg(item, s("setImage:"), nsimage); + } + + id attributedString = createAttributedString(title, fontName, fontSize, RGBA); + msg(item, s("setAttributedTitle:"), attributedString); msg(item, s("setEnabled:"), !disabled); msg(item, s("autorelease")); @@ -762,7 +767,7 @@ void processMenuItem(Menu *menu, id parentMenu, JsonNode *item) { bool templateImage = false; getJSONBool(item, "MacTemplateImage", &templateImage); - int fontSize = 12; + int fontSize = 13; getJSONInt(item, "FontSize", &fontSize); // If we have an accelerator diff --git a/v2/internal/ffenestri/menu_darwin.h b/v2/internal/ffenestri/menu_darwin.h index dacf9381..1ab4e5a9 100644 --- a/v2/internal/ffenestri/menu_darwin.h +++ b/v2/internal/ffenestri/menu_darwin.h @@ -109,6 +109,8 @@ id processTextMenuItem(Menu *menu, id parentMenu, const char *title, const char void processMenuItem(Menu *menu, id parentMenu, JsonNode *item); void processMenuData(Menu *menu, JsonNode *menuData); -void processRadioGroupJSON(Menu *menu, JsonNode *radioGroup) ; +void processRadioGroupJSON(Menu *menu, JsonNode *radioGroup); id GetMenu(Menu *menu); +id createAttributedString(const char* title, const char* fontName, int fontSize, const char* RGBA); + #endif //ASSETS_C_MENU_DARWIN_H diff --git a/v2/internal/ffenestri/traymenu_darwin.c b/v2/internal/ffenestri/traymenu_darwin.c index 3465d297..f926c1b4 100644 --- a/v2/internal/ffenestri/traymenu_darwin.c +++ b/v2/internal/ffenestri/traymenu_darwin.c @@ -32,10 +32,14 @@ TrayMenu* NewTrayMenu(const char* menuJSON) { result->ID = mustJSONString(processedJSON, "ID"); result->label = mustJSONString(processedJSON, "Label"); result->icon = mustJSONString(processedJSON, "Image"); + result->fontName = getJSONString(processedJSON, "FontName"); + result->RGBA = getJSONString(processedJSON, "RGBA"); getJSONBool(processedJSON, "MacTemplateImage", &result->templateImage); - JsonNode* processedMenu = mustJSONObject(processedJSON, "ProcessedMenu"); + result->fontSize = 13; + getJSONInt(processedJSON, "FontSize", &result->fontSize); // Create the menu + JsonNode* processedMenu = mustJSONObject(processedJSON, "ProcessedMenu"); result->menu = NewMenu(processedMenu); result->delegate = NULL; @@ -55,7 +59,7 @@ void DumpTrayMenu(TrayMenu* trayMenu) { } -void UpdateTrayLabel(TrayMenu *trayMenu, const char *label) { +void UpdateTrayLabel(TrayMenu *trayMenu, const char *label, const char *fontName, int fontSize, const char *RGBA) { // Exit early if NULL if( trayMenu->label == NULL ) { @@ -63,7 +67,8 @@ void UpdateTrayLabel(TrayMenu *trayMenu, const char *label) { } // Update button label id statusBarButton = msg(trayMenu->statusbaritem, s("button")); - msg(statusBarButton, s("setTitle:"), str(label)); + id attributedString = createAttributedString(label, fontName, fontSize, RGBA); + msg(statusBarButton, s("setAttributedTitle:"), attributedString); } void UpdateTrayIcon(TrayMenu *trayMenu) { @@ -117,7 +122,7 @@ void ShowTrayMenu(TrayMenu* trayMenu) { UpdateTrayIcon(trayMenu); // Update the label if needed - UpdateTrayLabel(trayMenu, trayMenu->label); + UpdateTrayLabel(trayMenu, trayMenu->label, trayMenu->fontName, trayMenu->fontSize, trayMenu->RGBA); // Update the menu id menu = GetMenu(trayMenu->menu); diff --git a/v2/internal/ffenestri/traymenu_darwin.h b/v2/internal/ffenestri/traymenu_darwin.h index df5d1d72..a619a00c 100644 --- a/v2/internal/ffenestri/traymenu_darwin.h +++ b/v2/internal/ffenestri/traymenu_darwin.h @@ -15,6 +15,9 @@ typedef struct { const char *ID; bool templateImage; + const char *fontName; + int fontSize; + const char *RGBA; Menu* menu; @@ -32,7 +35,7 @@ void DumpTrayMenu(TrayMenu* trayMenu); void ShowTrayMenu(TrayMenu* trayMenu); void UpdateTrayMenuInPlace(TrayMenu* currentMenu, TrayMenu* newMenu); void UpdateTrayIcon(TrayMenu *trayMenu); -void UpdateTrayLabel(TrayMenu *trayMenu, const char*); +void UpdateTrayLabel(TrayMenu *trayMenu, const char *label, const char *fontName, int fontSize, const char *RGBA); void LoadTrayIcons(); void UnloadTrayIcons(); diff --git a/v2/internal/ffenestri/traymenustore_darwin.c b/v2/internal/ffenestri/traymenustore_darwin.c index 6bae5d41..1338532e 100644 --- a/v2/internal/ffenestri/traymenustore_darwin.c +++ b/v2/internal/ffenestri/traymenustore_darwin.c @@ -118,7 +118,13 @@ void UpdateTrayMenuLabelInStore(TrayMenuStore* store, const char* JSON) { // Check we have this menu TrayMenu *menu = MustGetTrayMenuFromStore(store, ID); - UpdateTrayLabel(menu, Label); + + const char *fontName = getJSONString(parsedUpdate, "FontName"); + const char *RGBA = getJSONString(parsedUpdate, "RGBA"); + int fontSize = 13; + getJSONInt(parsedUpdate, "FontSize", &fontSize); + + UpdateTrayLabel(menu, Label, fontName, fontSize, RGBA); } diff --git a/v2/internal/menumanager/traymenu.go b/v2/internal/menumanager/traymenu.go index 35233091..5e79258e 100644 --- a/v2/internal/menumanager/traymenu.go +++ b/v2/internal/menumanager/traymenu.go @@ -25,8 +25,11 @@ func generateTrayID() string { type TrayMenu struct { ID string Label string + FontSize int + FontName string Image string MacTemplateImage bool + RGBA string menuItemMap *MenuItemMap menu *menu.Menu ProcessedMenu *WailsMenu @@ -45,9 +48,12 @@ func NewTrayMenu(trayMenu *menu.TrayMenu) *TrayMenu { result := &TrayMenu{ Label: trayMenu.Label, + FontName: trayMenu.FontName, + FontSize: trayMenu.FontSize, Image: trayMenu.Image, MacTemplateImage: trayMenu.MacTemplateImage, menu: trayMenu.Menu, + RGBA: trayMenu.RGBA, menuItemMap: NewMenuItemMap(), trayMenu: trayMenu, } diff --git a/v2/pkg/menu/menuitem.go b/v2/pkg/menu/menuitem.go index 0750cde3..e18b9eab 100644 --- a/v2/pkg/menu/menuitem.go +++ b/v2/pkg/menu/menuitem.go @@ -29,7 +29,7 @@ type MenuItem struct { // Callback function when menu clicked Click Callback `json:"-"` - // Colour + // Text Colour RGBA string // Font diff --git a/v2/pkg/menu/tray.go b/v2/pkg/menu/tray.go index cf7a985c..2e9253b4 100644 --- a/v2/pkg/menu/tray.go +++ b/v2/pkg/menu/tray.go @@ -16,6 +16,13 @@ type TrayMenu struct { // MacTemplateImage indicates that on a Mac, this image is a template image MacTemplateImage bool + // Text Colour + RGBA string + + // Font + FontSize int + FontName string + // Menu is the initial menu we wish to use for the tray Menu *Menu