GuiCtrl.Opt("+Background") does not revert -Background Topic is solved

Report problems with documented functionality
ntepa
Posts: 432
Joined: 19 Oct 2022, 20:52

GuiCtrl.Opt("+Background") does not revert -Background

Post by ntepa » 07 Sep 2023, 18:40

v2 docs wrote:Using +Background without specifying a color reverts -Background.
In v2, the background is not reverted:

Code: Select all

#Requires AutoHotkey v2.0

MyGui := Gui()
MyGui.Add("Edit", "vEdt w200 h100 BackgroundBlue", "abcdefg")
MyGui["Edt"].Opt("-Background")
MyGui["Edt"].Opt("+Background")
MyGui.Show()
In v1, it works:

Code: Select all

#Requires AutoHotkey v1.1

Gui, Add, Edit, vEdt w200 h100, abcdefg
Gui, Color,, Blue
GuiControl, -Background, Edt
GuiControl, +Background, Edt
Gui, Show

lexikos
Posts: 9629
Joined: 30 Sep 2013, 04:07
Contact:

Re: GuiCtrl.Opt("+Background") does not revert -Background

Post by lexikos » 11 Sep 2023, 02:47

I see that's a documented "feature", so I will fix it.

But I must say that this option is just weird. You set a custom value and -Background reverts to default. Why provide a way to revert the reversion? You can just set the value again. It's like two properties: "background color" and "use/apply background color".

lexikos
Posts: 9629
Joined: 30 Sep 2013, 04:07
Contact:

Re: GuiCtrl.Opt("+Background") does not revert -Background

Post by lexikos » 11 Sep 2023, 04:11

After more consideration, checking the code, reading both versions of the documentation, and checking your script again, I conclude that this is not a bug, but the documentation is a little unclear.

Your scripts are not equivalent. The options in v1 and v2 are not equivalent and are not intended to be equivalent.

The Background option is described very differently between the two versions.
v1 wrote:-Background (i.e. minus Background): Uses the standard background color rather than the one set by the Gui Color command. [...] Use GuiControl +Background to remove this option later.
v2 wrote:BackgroundColor: Changes the background color of the control.
In v1, the option is a simple on/off switch. The option doesn't accept a color value (for Edit controls), doesn't store a color value, and whatever you do with it can't affect the GUI's ControlColor because that's obviously a property of the GUI, not the control.

There is no ControlColor in v2, but there is BackColor, which is a combination of WindowColor and ControlColor.
If this option is not present, a Text, [and some other types but not Edit] control initially defaults to the background color set by Gui.BackColor (or if none or other control type, the system's default background color). Specifying BackgroundDefault or -Background applies the system's default background color. For example, a control can be restored to the default color via LV.Opt("+BackgroundDefault"). Using +Background without specifying a color reverts -Background.
This demonstrates what it means by "reverts -Background":

Code: Select all

#Requires AutoHotkey v2.0

MyGui := Gui()
MyGui.BackColor := "Blue"
MyGui.Add("text", "vEdt w200 h100", "abcdefg")
MyGui["Edt"].Opt("-Background")  ; Use system default, not MyGui.BackColor
MyGui["Edt"].Opt("+Background")  ; Use MyGui's default (MyGui.BackColor)
MyGui.Show()
It does not - and is not intended to - revert the option to a previous value that same option had. It is roughly equivalent with the v1 behaviour. The differences are:
  • WindowColor and ControlColor are merged into one property (BackColor).
  • Instead of merely setting "use the system default" or "use the GUI's color", you can set "use blue (or whatever color)".
I might change the documentation as follows:
BackgroundColor: Changes the background color of the control. Replace Color with a color name (see color chart) or RGB value (the 0x prefix is optional). Examples: BackgroundSilver, BackgroundFFDD99. If this option is not presentused, or if +Background is used with no suffix, a Text, Picture, GroupBox, CheckBox, Radio, Slider, Tab or Link control initially defaults touses the background color set by Gui.BackColor (or if none or other control type, the system's default background color). Specifying BackgroundDefault or -Background applies the system's default background color. For example, a control can be restored to the system default color via LV.Opt("+BackgroundDefault"). Using +Background without specifying a color reverts -Background. If a control type does not support this option, an error is thrown.
Last edited by lexikos on 11 Sep 2023, 05:47, edited 1 time in total.
Reason: BackColor->ControlColor

ntepa
Posts: 432
Joined: 19 Oct 2022, 20:52

Re: GuiCtrl.Opt("+Background") does not revert -Background

Post by ntepa » 11 Sep 2023, 05:28

Thank you for the clarification. I was not sure exactly what revert meant and assumed it was the control's previous color. I should have read that Edit was not one of the controls listed.
lexikos wrote: WindowColor and BackColor are merged into one property (BackColor).
Do you mean WindowColor and ControlColor?

Are the options -Background and BackgroundDefault equivalent?

Code: Select all

MyGui := Gui()
MyGui.BackColor := "Blue"
MyGui.Add("text", "vEdt w200 h100", "abcdefg")
MyGui["Edt"].Opt("-Background")
MyGui.Show()

MyGui2 := Gui()
MyGui2.BackColor := "Blue"
MyGui2.Add("text", "vEdt w200 h100", "abcdefg")
MyGui2["Edt"].Opt("BackgroundDefault")
MyGui2.Show()
Last edited by ntepa on 11 Sep 2023, 06:42, edited 1 time in total.

lexikos
Posts: 9629
Joined: 30 Sep 2013, 04:07
Contact:

Re: GuiCtrl.Opt("+Background") does not revert -Background

Post by lexikos » 11 Sep 2023, 06:04

Do you mean WindowColor and ControlColor?
Yes.
Are the options -BackColor and BackgroundDefault equivalent?
Do you mean -Background and BackgroundDefault? ;)

It says "Specifying BackgroundDefault or -Background applies the system's default background color. ", so yes. Also,
+/-Background is interpreted and supported more consistently. All controls which supported "Gui Color" now support +BackgroundColor and +BackgroundDefault (synonymous with -Background), not just ListView/TreeView/StatusBar/Progress.
Source: Changes from v1.1 | AutoHotkey v2
When posting code, it would be wise to mention what result you expect it to have and what result you see, for various reasons.

BackgroundDefault does not behave correctly with some controls. This will be fixed.

lexikos
Posts: 9629
Joined: 30 Sep 2013, 04:07
Contact:

Re: GuiCtrl.Opt("+Background") does not revert -Background  Topic is solved

Post by lexikos » 11 Sep 2023, 06:32

BackgroundDefault is fixed by v2.0.8.

ntepa
Posts: 432
Joined: 19 Oct 2022, 20:52

Re: GuiCtrl.Opt("+Background") does not revert -Background

Post by ntepa » 11 Sep 2023, 06:41

lexikos wrote:Do you mean -Background and BackgroundDefault? ;)
Yes. oops
lexikos wrote: When posting code, it would be wise to mention what result you expect it to have and what result you see, for various reasons.
I'll make sure to do that next time. I expected the second gui to use the system default color like the first gui, but it didn't. It just stayed blue.

Post Reply

Return to “Bug Reports”