Theme for required button style

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
User avatar
Jiri
Posts: 45
Joined: Thu Feb 11, 2016 11:41 pm

Theme for required button style

Post by Jiri » Wed Apr 12, 2017 6:44 pm

Hello,
We have request for button style behaviour:
Inactive (dissabled) buttons should have fill color grey
Enabled buttons should fill red. All others states (i.e. focused, mouseover etc.) are identified by text style change and cursor for mouseover, the fill reminds red.
The problem is, in Theme definition, for pushButton style are available Mouseoverstyle, Focusedinactivestyle Selectedinactivestyle Selectedstyle and Focusedstyle
Therefore, all active changes are not problem, but we cannot find how to differ the color of Enabled/Dissabled button, which is not focused, not selected, not mouse placed. Can you advice how to set the theme for it?

jyoung
Posts: 687
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Re: Theme for required button style

Post by jyoung » Thu Apr 13, 2017 12:15 am

Hi Jiri,

You may have to create a custom theme draw style for the enabled/disabled states. Then manually set the button's themedrawstyle when you enable or disable the button.
theme.PNG
theme.PNG (76.74 KiB) Viewed 1895 times

Code: Select all

if (#Button3.Enabled)
#Button3.Enabled := False
#Button3.ThemeDrawStyle := ButtonDisabled
else
#Button3.Enabled := True
#Button3.ThemeDrawStyle := ButtonEnabled
endif
endroutine
page.PNG
page.PNG (2.56 KiB) Viewed 1895 times
This may get a bit messy as I don't think themes are additive, meaning you can not add multiple drawstyles to a single control. So the custom draw style may have to all the style elements for a particular state.

User avatar
Stewart Marshall
Posts: 417
Joined: Thu Nov 05, 2015 5:25 pm

Re: Theme for required button style

Post by Stewart Marshall » Thu Apr 13, 2017 9:59 am

Hi Jiri

Currently, Theme's don't provide a way of specifying a disabled appearance, so you'll need to make a Disabled DrawStyle and apply it at runtime.

Fortunately, when defining a DrawStyle for a Disabled state, you need only specify the Style. The control will be disabled, so MouseOver, Focus and Selection become irrelevant.

If you change the PushButton DrawStyle itself to the colours you require, that will be applied automatically to all buttons, so Joe's sample code becomes as follows.

Code: Select all

if (#Button3.Enabled)
#Button3.Enabled := False
#Button3.ThemeDrawStyle := ButtonDisabled
else
#Button3.Enabled := True
#Button3.ThemeDrawStyle := ""
endif
endroutine
One important thing to note is that DrawStyles are cumulative. This can be done on the ribbon by holding down the Ctrl key, or by setting in code.

Code: Select all

#Control.ThemeDrawStyle := DrawStyle1+DrawStyle2
Only the features specifically coded in the Styles that make up a DrawStyle will be overriden. All other Style settings will remain exactly as is.

So in Joe's sample code where he's used a specific DrawStyle on a Button, you could write the following

Code: Select all

if (#Button3.Enabled)
#Button3.Enabled := False
#Button3.ThemeDrawStyle := ButtonEnabled+ButtonDisabled
else
#Button3.Enabled := True
#Button3.ThemeDrawStyle := ButtonEnabled
endif
endroutine
ButtonDisabled need only define the Fill colour. All other features of ButtonEnabled would remain unchanged.

Regards
Stewart Marshall

Independent IT Consultant
www.marshallfloyd.com.au

jyoung
Posts: 687
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Re: Theme for required button style

Post by jyoung » Thu Apr 13, 2017 11:08 pm

I did not know you could do that with DrawStyles.
Good to know!

Post Reply