Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BackgroundColour and deprecate RGBA #1475

Merged
merged 1 commit into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {
Frameless: false,
StartHidden: false,
HideWindowOnClose: false,
RGBA: &options.RGBA{R: 255, G: 255, B: 255, A: 255},
BackgroundColour: &options.RGBA{R: 255, G: 255, B: 255, A: 255},
Assets: assets,
Menu: nil,
Logger: nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func main() {
Frameless: false,
StartHidden: false,
HideWindowOnClose: false,
RGBA: &options.RGBA{R: 255, G: 255, B: 255, A: 255},
BackgroundColour: &options.RGBA{R: 255, G: 255, B: 255, A: 255},
Assets: assets,
Menu: nil,
Logger: nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func main() {
Frameless: false,
StartHidden: false,
HideWindowOnClose: false,
RGBA: &options.RGBA{R: 255, G: 255, B: 255, A: 255},
BackgroundColour: &options.RGBA{R: 255, G: 255, B: 255, A: 255},
Assets: assets,
Menu: nil,
Logger: nil,
Expand Down
4 changes: 2 additions & 2 deletions v2/internal/frontend/desktop/darwin/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func NewWindow(frontendOptions *options.App, debugMode bool) *Window {
context: unsafe.Pointer(context),
}

if frontendOptions.RGBA != nil {
result.SetRGBA(frontendOptions.RGBA.R, frontendOptions.RGBA.G, frontendOptions.RGBA.B, frontendOptions.RGBA.A)
if frontendOptions.BackgroundColour != nil {
result.SetRGBA(frontendOptions.BackgroundColour.R, frontendOptions.BackgroundColour.G, frontendOptions.BackgroundColour.B, frontendOptions.BackgroundColour.A)
}

if frontendOptions.Mac != nil && frontendOptions.Mac.About != nil {
Expand Down
2 changes: 1 addition & 1 deletion v2/internal/frontend/desktop/linux/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ func NewWindow(appoptions *options.App, debug bool) *Window {
}

// Set background colour
RGBA := appoptions.RGBA
RGBA := appoptions.BackgroundColour
result.SetRGBA(RGBA.R, RGBA.G, RGBA.B, RGBA.A)

// Setup window
Expand Down
2 changes: 1 addition & 1 deletion v2/internal/frontend/desktop/windows/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func (f *Frontend) setupChromium() {
onFocus.Bind(f.onFocus)

// Set background colour
f.WindowSetRGBA(f.frontendOptions.RGBA)
f.WindowSetRGBA(f.frontendOptions.BackgroundColour)

chromium.SetGlobalPermission(edge.CoreWebView2PermissionStateAllow)
chromium.AddWebResourceRequestedFilter("*", edge.COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL)
Expand Down
4 changes: 2 additions & 2 deletions v2/internal/frontend/desktop/windows/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func NewWindow(parent winc.Controller, appoptions *options.App, versionInfo *ope
}
}

if appoptions.RGBA != nil {
win32.SetBackgroundColour(result.Handle(), appoptions.RGBA.R, appoptions.RGBA.G, appoptions.RGBA.B)
if appoptions.BackgroundColour != nil {
win32.SetBackgroundColour(result.Handle(), appoptions.BackgroundColour.R, appoptions.BackgroundColour.G, appoptions.BackgroundColour.B)
}

result.SetSize(appoptions.Width, appoptions.Height)
Expand Down
2 changes: 1 addition & 1 deletion v2/internal/menumanager/processedMenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func NewProcessedMenuItem(menuItemMap *MenuItemMap, menuItem *menu.MenuItem) *Pr
Hidden: menuItem.Hidden,
Checked: menuItem.Checked,
SubMenu: nil,
//RGBA: menuItem.RGBA,
//BackgroundColour: menuItem.BackgroundColour,
//FontSize: menuItem.FontSize,
//FontName: menuItem.FontName,
//Image: menuItem.Image,
Expand Down
32 changes: 17 additions & 15 deletions v2/pkg/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,20 @@ type App struct {
StartHidden bool
HideWindowOnClose bool
AlwaysOnTop bool
RGBA *RGBA
Assets fs.FS
AssetsHandler http.Handler
Menu *menu.Menu
Logger logger.Logger `json:"-"`
LogLevel logger.LogLevel
OnStartup func(ctx context.Context) `json:"-"`
OnDomReady func(ctx context.Context) `json:"-"`
OnShutdown func(ctx context.Context) `json:"-"`
OnBeforeClose func(ctx context.Context) (prevent bool) `json:"-"`
Bind []interface{}
WindowStartState WindowStartState
BackgroundColour *RGBA
// RGBA is deprecated. Please use BackgroundColour
RGBA *RGBA
Assets fs.FS
AssetsHandler http.Handler
Menu *menu.Menu
Logger logger.Logger `json:"-"`
LogLevel logger.LogLevel
OnStartup func(ctx context.Context) `json:"-"`
OnDomReady func(ctx context.Context) `json:"-"`
OnShutdown func(ctx context.Context) `json:"-"`
OnBeforeClose func(ctx context.Context) (prevent bool) `json:"-"`
Bind []interface{}
WindowStartState WindowStartState

//ContextMenus []*menu.ContextMenu
//TrayMenus []*menu.TrayMenu
Expand All @@ -75,9 +77,9 @@ func MergeDefaults(appoptions *App) {
log.Fatal(err)
}

// DEfault colour. Doesn't work well with mergo
if appoptions.RGBA == nil {
appoptions.RGBA = &RGBA{
// Default colour. Doesn't work well with mergo
if appoptions.BackgroundColour == nil {
appoptions.BackgroundColour = &RGBA{
R: 255,
G: 255,
B: 255,
Expand Down
9 changes: 9 additions & 0 deletions v2/wails.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ import (
// Run creates an application based on the given config and executes it
func Run(options *options.App) error {

if options.RGBA != nil {
println("---- WARNING ----")
println("The `RGBA` option has been deprecated. Please use `BackgroundColour`.")

if options.BackgroundColour == nil {
options.BackgroundColour = options.RGBA
}
}

// Call an Init method manually
err := Init()
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions website/docs/reference/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func main() {
MaxHeight: 1024,
StartHidden: false,
HideWindowOnClose: false,
RGBA: &options.RGBA{R: 0, G: 0, B: 0, A: 255},
BackgroundColour: &options.RGBA{R: 0, G: 0, B: 0, A: 255},
AlwaysOnTop: false,
Assets: assets,
AssetsHandler: assetsHandler,
Expand Down Expand Up @@ -196,14 +196,14 @@ Type: bool
By default, closing the window will close the application. Setting this to `true` means closing the window will
hide the window instead.

### RGBA
### BackgroundColour

Name: RGBA
Name: BackgroundColour

Type: int (0xRRGGBBAA)
Example: 0xFF000088 - Red at 50% transparency

This value is the RGBA value to set the window by default.
This value is the default background colour of the window.
Default: 0xFFFFFFFF.

### AlwaysOnTop
Expand Down Expand Up @@ -392,7 +392,7 @@ Name: WebviewIsTransparent
Type: bool

Setting this to `true` will make the webview background transparent when an alpha value of `0` is used.
This means that if you use `rgba(0,0,0,0)`, the host window will show through.
This means that if you use `rgba(0,0,0,0)` for `background-color` in your CSS, the host window will show through.
Often combined with [WindowIsTranslucent](#WindowIsTranslucent) to make frosty-looking applications.

### WindowIsTranslucent
Expand Down Expand Up @@ -545,7 +545,7 @@ Name: WebviewIsTransparent
Type: bool

Setting this to `true` will make the webview background transparent when an alpha value of `0` is used.
This means that if you use `rgba(0,0,0,0)`, the host window will show through.
This means that if you use `rgba(0,0,0,0)` for `background-color` in your CSS, the host window will show through.
Often combined with [WindowIsTranslucent](#WindowIsTranslucent) to make frosty-looking applications.

### WindowIsTranslucent
Expand Down