mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-21 19:39:29 +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 {
|
||||
r, b, g, alpha := intToColour(a.config.Colour)
|
||||
r, g, b, alpha := intToColour(a.config.Colour)
|
||||
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
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -158,11 +158,27 @@ void UseToolbar(struct Application *app) {
|
||||
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) {
|
||||
app->red = red;
|
||||
app->green = green;
|
||||
app->blue = blue;
|
||||
app->alpha = alpha;
|
||||
|
||||
applyWindowColour(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->minimised = 0;
|
||||
|
||||
result->mainWindow = NULL;
|
||||
|
||||
// Features
|
||||
result->frame = 1;
|
||||
result->hideTitle = 0;
|
||||
@ -234,7 +252,6 @@ void* NewApplication(const char *title, int width, int height, int resizable, in
|
||||
result->hideToolbarSeparator = 0;
|
||||
|
||||
result->titlebarAppearsTransparent = 0;
|
||||
printf("[l] setTitlebarAppearsTransparent %d\n", result->titlebarAppearsTransparent);
|
||||
|
||||
result->sendMessageToBackend = (ffenestriCallback) messageFromWindowCallback;
|
||||
|
||||
@ -727,12 +744,7 @@ void Run(void *applicationPointer, int argc, char **argv) {
|
||||
msg(mainWindow, s("setStyleMask:"), decorations);
|
||||
|
||||
// Set Colour
|
||||
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(mainWindow, s("setBackgroundColor:"), colour);
|
||||
applyWindowColour(app);
|
||||
|
||||
|
||||
// Setup webview
|
||||
|
@ -16,7 +16,7 @@ type Window interface {
|
||||
SetTitle(title string)
|
||||
Fullscreen()
|
||||
UnFullscreen()
|
||||
SetColour(colour string)
|
||||
SetColour(colour int)
|
||||
}
|
||||
|
||||
// Window exposes the Windows interface
|
||||
@ -54,8 +54,8 @@ func (w *window) UnFullscreen() {
|
||||
w.bus.Publish("window:unfullscreen", "")
|
||||
}
|
||||
|
||||
// SetColour sets the window colour to the given string
|
||||
func (w *window) SetColour(colour string) {
|
||||
// SetColour sets the window colour to the given int
|
||||
func (w *window) SetColour(colour int) {
|
||||
w.bus.Publish("window:setcolour", colour)
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ func (r *RuntimeTest) UnFullscreen() {
|
||||
}
|
||||
|
||||
// SetColour will call the Runtime.UnFullscreen method
|
||||
func (r *RuntimeTest) SetColour(colour string) {
|
||||
func (r *RuntimeTest) SetColour(colour int) {
|
||||
r.runtime.Window.SetColour(colour)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user