B4J Question Possible to force a delay on a pressed button to retain CSS styling longer?

m4.s

Member
Licensed User
Longtime User
I apply this type of CSS styling to various buttons in my B4J application:

B4X:
.goldBtnPressed .button:pressed {
    -fx-background-color:  rgb(177,129,11);
    -fx-text-fill: white;
}

so when a button is pressed, its background momentarily changes to gold (as shown):

1692245304524.png


However, when my application is in its self-recording mode, I need the button's [changed] background color to remain for 1 or 2 seconds; ideally before the button's MouseClick event code is executed.

I've tried replacing the MouseClick event with the MousePressed event, and also adding a MouseReleased event, to conditionally call
B4X:
Sleep(1000)
in order to force the delay - but to no avail.

So, suggestions are welcomed! Thanks in advance.
 
Last edited:

Daestrum

Expert
Licensed User
Longtime User
B4X:
Sleep(1)

Is only a delay of one millisecond, if you want to 'wait' a second you need 1000
 
Upvote 0

kimstudio

Active Member
Licensed User
Longtime User
Is only a delay of one millisecond, if you want to 'wait' a second you need 1000
Since Resumable subs feature is available I am not sure whether sleep(1000) will really suspend for 1000ms. Could Erel or someone tell me? Thanks!
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Look at using a Togglebutton. it has a CSS psuedo class of 'selected'. It would the be easy to sleep the required time, then turn off the Togglebutton's selection.

Relevant CSS docs
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Simple example attached using a togglebutton and css.
 

Attachments

  • ToggleButtonCSS.zip
    2.2 KB · Views: 49
Upvote 0

m4.s

Member
Licensed User
Longtime User
Thank you @stevel05 and everyone for your assistance (this amazing developer community/forum continues to impress me!).

The ToggleButton solution worked, yet introduced other residual problems.

Nevertheless, this exercise has helped me rethink some UI behavior in my application, so I'll likely alternatively address with via small but beneficial redesign and refactoring.
 
Upvote 0
Top