Notifications
Clear all

[Closed] backgroundcolor

I’m trying to get a colorpicker to update it’s color whenever Background color is changed. So far have it setup to read background color whenever first opened but can’t seem to find info on how to change it while program is running. Getting the background color to change based on colorpicker is easy on other hand.

3 Replies
2 Replies
(@bobo)
Joined: 1 year ago

Posts: 0

Unfortunately, there is no callback (I know of) that can notify you of changes of the background color.
When this is the case, the only (ugly) workaround is to use polling.
In the following example, the backgroundcolor global variable is being polled 100 times/second and the UI spinner is being updated as necessary. Note that at least on my machine, this polling does not appear to be eating any CPU time, so it is a relatively safe workaround.


rollout BGColor_Rollout "BG Color"
(
	colorPicker bg_color "BG COLOR:"
	timer tmr_bgcolor interval:10 active:true
	on bg_color changed clr do backgroundColor = clr
	on tmr_bgcolor tick do bg_color.color = backgroundColor 
)
createDialog BGColor_Rollout 
(@bobo)
Joined: 1 year ago

Posts: 0

Ok, I lied.

There IS a callback that can monitor the backgroundColor.
While the code appears to be more complex, it is event-driven (as opposed to the 100 times per second polling in the previous example) so it is to be preferred…

(
global BGColor_Rollout
try(destroyDialog BGColor_Rollout)catch()

rollout BGColor_Rollout "BG Color"
(
	colorPicker bg_color "BG COLOR:"
	on bg_color changed clr do backgroundColor = clr
	on BGColor_Rollout open do
	(
		deleteAllChangeHandlers id:#BGColorMonitor
		when parameters backgroundColorController changes id:#BGColorMonitor do 
			BGColor_Rollout.bg_color.color = backgroundColor 
		BGColor_Rollout.bg_color.color = backgroundColor 	
	)
	on BGColor_Rollout close do
		deleteAllChangeHandlers id:#BGColorMonitor
)
createDialog BGColor_Rollout 
)

Great. Both of those worked.