mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-22 03:49:28 +08:00
Support runtime colour change
This commit is contained in:
parent
52bb397105
commit
15c08ef425
@ -167,7 +167,7 @@ func (a *Application) Run(incomingDispatcher Dispatcher, bindings string) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
if a.config.Colour != 0 {
|
if a.config.Colour != 0 {
|
||||||
r, b, g, alpha := intToColour(a.config.Colour)
|
r, g, b, alpha := intToColour(a.config.Colour)
|
||||||
C.SetColour(a.app, r, g, b, alpha)
|
C.SetColour(a.app, r, g, b, alpha)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ func (c *Client) WindowSize(width int, height int) {
|
|||||||
|
|
||||||
// WindowSetColour sets the window colour
|
// WindowSetColour sets the window colour
|
||||||
func (c *Client) WindowSetColour(colour int) {
|
func (c *Client) WindowSetColour(colour int) {
|
||||||
r, b, g, a := intToColour(colour)
|
r, g, b, a := intToColour(colour)
|
||||||
C.SetColour(c.app.app, r, g, b, a)
|
C.SetColour(c.app.app, r, g, b, a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,11 +158,27 @@ void UseToolbar(struct Application *app) {
|
|||||||
app->useToolBar = 1;
|
app->useToolBar = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void applyWindowColour(struct Application *app) {
|
||||||
|
// Apply the colour only if the window has been created
|
||||||
|
if( app->mainWindow != NULL ) {
|
||||||
|
ON_MAIN_THREAD(
|
||||||
|
id colour = msg(c("NSColor"), s("colorWithCalibratedRed:green:blue:alpha:"),
|
||||||
|
(float)app->red / 255.0,
|
||||||
|
(float)app->green / 255.0,
|
||||||
|
(float)app->blue / 255.0,
|
||||||
|
(float)app->alpha / 255.0);
|
||||||
|
msg(app->mainWindow, s("setBackgroundColor:"), colour);
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SetColour(struct Application *app, int red, int green, int blue, int alpha) {
|
void SetColour(struct Application *app, int red, int green, int blue, int alpha) {
|
||||||
app->red = red;
|
app->red = red;
|
||||||
app->green = green;
|
app->green = green;
|
||||||
app->blue = blue;
|
app->blue = blue;
|
||||||
app->alpha = alpha;
|
app->alpha = alpha;
|
||||||
|
|
||||||
|
applyWindowColour(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FullSizeContent(struct Application *app) {
|
void FullSizeContent(struct Application *app) {
|
||||||
@ -225,6 +241,8 @@ void* NewApplication(const char *title, int width, int height, int resizable, in
|
|||||||
result->maximised = 0;
|
result->maximised = 0;
|
||||||
result->minimised = 0;
|
result->minimised = 0;
|
||||||
|
|
||||||
|
result->mainWindow = NULL;
|
||||||
|
|
||||||
// Features
|
// Features
|
||||||
result->frame = 1;
|
result->frame = 1;
|
||||||
result->hideTitle = 0;
|
result->hideTitle = 0;
|
||||||
@ -234,7 +252,6 @@ void* NewApplication(const char *title, int width, int height, int resizable, in
|
|||||||
result->hideToolbarSeparator = 0;
|
result->hideToolbarSeparator = 0;
|
||||||
|
|
||||||
result->titlebarAppearsTransparent = 0;
|
result->titlebarAppearsTransparent = 0;
|
||||||
printf("[l] setTitlebarAppearsTransparent %d\n", result->titlebarAppearsTransparent);
|
|
||||||
|
|
||||||
result->sendMessageToBackend = (ffenestriCallback) messageFromWindowCallback;
|
result->sendMessageToBackend = (ffenestriCallback) messageFromWindowCallback;
|
||||||
|
|
||||||
@ -727,12 +744,7 @@ void Run(void *applicationPointer, int argc, char **argv) {
|
|||||||
msg(mainWindow, s("setStyleMask:"), decorations);
|
msg(mainWindow, s("setStyleMask:"), decorations);
|
||||||
|
|
||||||
// Set Colour
|
// Set Colour
|
||||||
id colour = msg(c("NSColor"), s("colorWithCalibratedRed:green:blue:alpha:"),
|
applyWindowColour(app);
|
||||||
(float)app->red / 255.0,
|
|
||||||
(float)app->green / 255.0,
|
|
||||||
(float)app->blue / 255.0,
|
|
||||||
(float)app->alpha / 255.0);
|
|
||||||
msg(mainWindow, s("setBackgroundColor:"), colour);
|
|
||||||
|
|
||||||
|
|
||||||
// Setup webview
|
// Setup webview
|
||||||
|
@ -16,7 +16,7 @@ type Window interface {
|
|||||||
SetTitle(title string)
|
SetTitle(title string)
|
||||||
Fullscreen()
|
Fullscreen()
|
||||||
UnFullscreen()
|
UnFullscreen()
|
||||||
SetColour(colour string)
|
SetColour(colour int)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Window exposes the Windows interface
|
// Window exposes the Windows interface
|
||||||
@ -54,8 +54,8 @@ func (w *window) UnFullscreen() {
|
|||||||
w.bus.Publish("window:unfullscreen", "")
|
w.bus.Publish("window:unfullscreen", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetColour sets the window colour to the given string
|
// SetColour sets the window colour to the given int
|
||||||
func (w *window) SetColour(colour string) {
|
func (w *window) SetColour(colour int) {
|
||||||
w.bus.Publish("window:setcolour", colour)
|
w.bus.Publish("window:setcolour", colour)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ func (r *RuntimeTest) UnFullscreen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetColour will call the Runtime.UnFullscreen method
|
// SetColour will call the Runtime.UnFullscreen method
|
||||||
func (r *RuntimeTest) SetColour(colour string) {
|
func (r *RuntimeTest) SetColour(colour int) {
|
||||||
r.runtime.Window.SetColour(colour)
|
r.runtime.Window.SetColour(colour)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user