Compare commits

...

4 Commits

Author SHA1 Message Date
Lea Anthony
6424579a9e v2.0.0-alpha.52 2021-03-17 23:30:42 +11:00
Lea Anthony
a962ae6f63 Support rich text in Tray labels 2021-03-17 23:30:08 +11:00
Lea Anthony
c7dee158ba tray menu Icon->Image. Support template images. 2021-03-17 22:24:09 +11:00
Lea Anthony
237d25089d Update CLI banner 2021-03-17 21:59:31 +11:00
10 changed files with 109 additions and 62 deletions

View File

@@ -23,14 +23,14 @@ func fatal(message string) {
} }
func banner(_ *clir.Cli) string { func banner(_ *clir.Cli) string {
return fmt.Sprintf("%s %s - Go/HTML Application Framework", colour.Yellow("Wails"), colour.DarkRed(version)) return fmt.Sprintf("%s %s", colour.Yellow("Wails CLI"), colour.DarkRed(version))
} }
func main() { func main() {
var err error var err error
app := clir.NewCli("Wails", "Go/HTML Application Framework", version) app := clir.NewCli("Wails", "Go/HTML Appkit", version)
app.SetBannerFunction(banner) app.SetBannerFunction(banner)

View File

@@ -1,3 +1,3 @@
package main package main
var version = "v2.0.0-alpha.51" var version = "v2.0.0-alpha.52"

View File

@@ -576,38 +576,7 @@ id processCheckboxMenuItem(Menu *menu, id parentmenu, const char *title, const c
return item; 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 createAttributedString(const char* title, const char* fontName, int fontSize, const char* RGBA) {
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);
}
// Process Menu Item attributes // Process Menu Item attributes
id dictionary = ALLOC_INIT("NSMutableDictionary"); id dictionary = ALLOC_INIT("NSMutableDictionary");
@@ -658,10 +627,46 @@ id processTextMenuItem(Menu *menu, id parentMenu, const char *title, const char
id attributedString = ALLOC("NSMutableAttributedString"); id attributedString = ALLOC("NSMutableAttributedString");
msg(attributedString, s("initWithString:attributes:"), str(title), dictionary); msg(attributedString, s("initWithString:attributes:"), str(title), dictionary);
msg(dictionary, s("release"));
msg(item, s("setAttributedTitle:"), attributedString);
msg(attributedString, s("autorelease")); 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("setEnabled:"), !disabled);
msg(item, s("autorelease")); msg(item, s("autorelease"));
@@ -762,7 +767,7 @@ void processMenuItem(Menu *menu, id parentMenu, JsonNode *item) {
bool templateImage = false; bool templateImage = false;
getJSONBool(item, "MacTemplateImage", &templateImage); getJSONBool(item, "MacTemplateImage", &templateImage);
int fontSize = 12; int fontSize = 13;
getJSONInt(item, "FontSize", &fontSize); getJSONInt(item, "FontSize", &fontSize);
// If we have an accelerator // If we have an accelerator

View File

@@ -109,6 +109,8 @@ id processTextMenuItem(Menu *menu, id parentMenu, const char *title, const char
void processMenuItem(Menu *menu, id parentMenu, JsonNode *item); void processMenuItem(Menu *menu, id parentMenu, JsonNode *item);
void processMenuData(Menu *menu, JsonNode *menuData); void processMenuData(Menu *menu, JsonNode *menuData);
void processRadioGroupJSON(Menu *menu, JsonNode *radioGroup) ; void processRadioGroupJSON(Menu *menu, JsonNode *radioGroup);
id GetMenu(Menu *menu); id GetMenu(Menu *menu);
id createAttributedString(const char* title, const char* fontName, int fontSize, const char* RGBA);
#endif //ASSETS_C_MENU_DARWIN_H #endif //ASSETS_C_MENU_DARWIN_H

View File

@@ -31,10 +31,15 @@ TrayMenu* NewTrayMenu(const char* menuJSON) {
result->ID = mustJSONString(processedJSON, "ID"); result->ID = mustJSONString(processedJSON, "ID");
result->label = mustJSONString(processedJSON, "Label"); result->label = mustJSONString(processedJSON, "Label");
result->icon = mustJSONString(processedJSON, "Icon"); result->icon = mustJSONString(processedJSON, "Image");
JsonNode* processedMenu = mustJSONObject(processedJSON, "ProcessedMenu"); result->fontName = getJSONString(processedJSON, "FontName");
result->RGBA = getJSONString(processedJSON, "RGBA");
getJSONBool(processedJSON, "MacTemplateImage", &result->templateImage);
result->fontSize = 13;
getJSONInt(processedJSON, "FontSize", &result->fontSize);
// Create the menu // Create the menu
JsonNode* processedMenu = mustJSONObject(processedJSON, "ProcessedMenu");
result->menu = NewMenu(processedMenu); result->menu = NewMenu(processedMenu);
result->delegate = NULL; result->delegate = NULL;
@@ -54,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 // Exit early if NULL
if( trayMenu->label == NULL ) { if( trayMenu->label == NULL ) {
@@ -62,7 +67,8 @@ void UpdateTrayLabel(TrayMenu *trayMenu, const char *label) {
} }
// Update button label // Update button label
id statusBarButton = msg(trayMenu->statusbaritem, s("button")); 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) { void UpdateTrayIcon(TrayMenu *trayMenu) {
@@ -89,6 +95,10 @@ void UpdateTrayIcon(TrayMenu *trayMenu) {
id imageData = msg(data, s("initWithBase64EncodedString:options:"), str(trayMenu->icon), 0); id imageData = msg(data, s("initWithBase64EncodedString:options:"), str(trayMenu->icon), 0);
trayImage = ALLOC("NSImage"); trayImage = ALLOC("NSImage");
msg(trayImage, s("initWithData:"), imageData); msg(trayImage, s("initWithData:"), imageData);
if( trayMenu->templateImage ) {
msg(trayImage, s("setTemplate:"), YES);
}
} }
msg(statusBarButton, s("setImagePosition:"), trayMenu->trayIconPosition); msg(statusBarButton, s("setImagePosition:"), trayMenu->trayIconPosition);
@@ -112,7 +122,7 @@ void ShowTrayMenu(TrayMenu* trayMenu) {
UpdateTrayIcon(trayMenu); UpdateTrayIcon(trayMenu);
// Update the label if needed // Update the label if needed
UpdateTrayLabel(trayMenu, trayMenu->label); UpdateTrayLabel(trayMenu, trayMenu->label, trayMenu->fontName, trayMenu->fontSize, trayMenu->RGBA);
// Update the menu // Update the menu
id menu = GetMenu(trayMenu->menu); id menu = GetMenu(trayMenu->menu);

View File

@@ -14,6 +14,11 @@ typedef struct {
const char *icon; const char *icon;
const char *ID; const char *ID;
bool templateImage;
const char *fontName;
int fontSize;
const char *RGBA;
Menu* menu; Menu* menu;
id statusbaritem; id statusbaritem;
@@ -30,7 +35,7 @@ void DumpTrayMenu(TrayMenu* trayMenu);
void ShowTrayMenu(TrayMenu* trayMenu); void ShowTrayMenu(TrayMenu* trayMenu);
void UpdateTrayMenuInPlace(TrayMenu* currentMenu, TrayMenu* newMenu); void UpdateTrayMenuInPlace(TrayMenu* currentMenu, TrayMenu* newMenu);
void UpdateTrayIcon(TrayMenu *trayMenu); 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 LoadTrayIcons();
void UnloadTrayIcons(); void UnloadTrayIcons();

View File

@@ -118,7 +118,13 @@ void UpdateTrayMenuLabelInStore(TrayMenuStore* store, const char* JSON) {
// Check we have this menu // Check we have this menu
TrayMenu *menu = MustGetTrayMenuFromStore(store, ID); 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);
} }

View File

@@ -23,13 +23,17 @@ func generateTrayID() string {
} }
type TrayMenu struct { type TrayMenu struct {
ID string ID string
Label string Label string
Icon string FontSize int
menuItemMap *MenuItemMap FontName string
menu *menu.Menu Image string
ProcessedMenu *WailsMenu MacTemplateImage bool
trayMenu *menu.TrayMenu RGBA string
menuItemMap *MenuItemMap
menu *menu.Menu
ProcessedMenu *WailsMenu
trayMenu *menu.TrayMenu
} }
func (t *TrayMenu) AsJSON() (string, error) { func (t *TrayMenu) AsJSON() (string, error) {
@@ -43,11 +47,15 @@ func (t *TrayMenu) AsJSON() (string, error) {
func NewTrayMenu(trayMenu *menu.TrayMenu) *TrayMenu { func NewTrayMenu(trayMenu *menu.TrayMenu) *TrayMenu {
result := &TrayMenu{ result := &TrayMenu{
Label: trayMenu.Label, Label: trayMenu.Label,
Icon: trayMenu.Icon, FontName: trayMenu.FontName,
menu: trayMenu.Menu, FontSize: trayMenu.FontSize,
menuItemMap: NewMenuItemMap(), Image: trayMenu.Image,
trayMenu: trayMenu, MacTemplateImage: trayMenu.MacTemplateImage,
menu: trayMenu.Menu,
RGBA: trayMenu.RGBA,
menuItemMap: NewMenuItemMap(),
trayMenu: trayMenu,
} }
result.menuItemMap.AddMenu(trayMenu.Menu) result.menuItemMap.AddMenu(trayMenu.Menu)

View File

@@ -29,7 +29,7 @@ type MenuItem struct {
// Callback function when menu clicked // Callback function when menu clicked
Click Callback `json:"-"` Click Callback `json:"-"`
// Colour // Text Colour
RGBA string RGBA string
// Font // Font

View File

@@ -6,11 +6,22 @@ type TrayMenu struct {
// Label is the text we wish to display in the tray // Label is the text we wish to display in the tray
Label string Label string
// Icon is the name of the tray icon we wish to display. // Image is the name of the tray icon we wish to display.
// These are read up during build from <projectdir>/trayicons and // These are read up during build from <projectdir>/trayicons and
// the filenames are used as IDs, minus the extension // the filenames are used as IDs, minus the extension
// EG: <projectdir>/trayicons/main.png can be referenced here with "main" // EG: <projectdir>/trayicons/main.png can be referenced here with "main"
Icon string // If the image is not a filename, it will be treated as base64 image data
Image string
// 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 is the initial menu we wish to use for the tray
Menu *Menu Menu *Menu