Preventing button state from changing

Hi, I’ve been reading the docs trying to figure out how to get a button state to stop changing but am stuck. I’m sure the solution is fairly simple…?

~preventStateChange = nil;
Button(w, Rect(25, 25, 25, 25))
	.states_([
		["", Color.white, Color.white],
		["", Color.red, Color.red]
	])
       .action_({
		// some action
	});

How can I get the button to change from white to red as usual but fix the state and prevent any action from getting executed when ~preventStateChange is set to true? So if it’s red it should stay red upon being clicked. I’ve tried setting the state in the button action to the previous state but this creates a glitch. I’ve also tried disabling the button but this causes the color to change. Does anyone have any ideas? Thanks

.enabled_(false) should do. It doesn’t change the state/color here.

(
w= Window().front;
b= Button(w, Rect(25, 25, 25, 25))
	.states_([
		["", Color.white, Color.white],
		["", Color.red, Color.red]
	])
       .action_({
		// some action
	});
)

b.enabled_(false);
b.enabled_(true);
1 Like