Lazarus

Programming => General => Topic started by: TeoUrbana on May 15, 2020, 10:42:17 pm

Title: TRadioGroup font does not accept chosen color
Post by: TeoUrbana on May 15, 2020, 10:42:17 pm
When choosing a color for the RadioGroup font, he does not accept it. The font is always black.

I need a solution that is not to uncheck the option "Use Manifest resource ..." in Project -> Project Options, because unchecking this option solves the font color problem, but it spoils something else.

I tried the following:
Code: Pascal  [Select][+][-]
  1. TControl (RadioGroup1) .Font.Color: = clRed;
But nothing done.

Does anyone have a solution that works?

(translated from portuguese to english by google)  8)
Title: Re: TRadioGroup font does not accept chosen color
Post by: jamie on May 15, 2020, 10:44:03 pm
You are on Windows obviously.. Its controlled by the OS GUI..

 Other Widgets can change their color..

 I am not sure if that control has a ownerDraw option in it, it should have If not..
Title: Re: TRadioGroup font does not accept chosen color
Post by: winni on May 15, 2020, 10:54:29 pm
Hi!

No - TRadiogroup has no OwnerDraw option.

So: Windows is too dump for TRadiogroup.Font.Color.

Write a letter to Bill Gates.

Winni
Title: Re: TRadioGroup font does not accept chosen color
Post by: jamie on May 16, 2020, 01:05:06 am
actually you can color the boxes but it involves hooking into the window procedure to catch the WM_PAINT , etc...
Title: Re: TRadioGroup font does not accept chosen color
Post by: TeoUrbana on May 16, 2020, 05:59:23 pm
See the first image:
"Use manifest feature (and enable themes)", which is under Project -> Project Options, is disabled.
The RadioGroup's background is yellow (it's the color of the form). Where's the transparency?  >:(

In the second image, I enabled the option "Use manifest resource (and enable themes)"

I think the key is to understand how the Use manifest feature option works, and to use this code to change the font color, but unfortunately for me, this is a distant knowledge from my current level (I'm still fighting with the OOP).

Can anyone get around this situation?  :'(

In the case of Windows, the ideal is to leave the "use manifest feature ..." checked, because the images on disabled buttons, the font design, etc ... the images get better.
Title: Re: TRadioGroup font does not accept chosen color
Post by: lucamar on May 16, 2020, 06:18:41 pm
Note the second part of that option:
With themes enabled, the Windows theming engine takes almost absolute control of all the drawing, bypassing (and ignoring) most any "custom" options you might set: font, colors, etc.

There is little the LCL can do to avoid it since that behaviour is set on stone by Windows itself. And not only Windows: it might happen also on other widgetsets, depending on several conditions.
Title: Re: TRadioGroup font does not accept chosen color
Post by: TeoUrbana on May 16, 2020, 07:33:34 pm
Quote
... that behaviour is set on stone by Windows itself.

But, is there not a way to overload?
Title: Re: TRadioGroup font does not accept chosen color
Post by: ASerge on May 16, 2020, 10:38:33 pm
Quote
... that behaviour is set on stone by Windows itself.
But, is there not a way to overload?
Whether it is necessary? By changing the standard behavior and appearance of controls, we make the interface less familiar, i.e. degrades usability.
Only at first the unusual can attract attention. Later the functionality and speed of control come first, and then the standardness of the interface becomes more important.
Title: Re: TRadioGroup font does not accept chosen color
Post by: wp on May 17, 2020, 12:47:31 am
I absolutely agree with ASerge that it is not a good idea to change colors of a themed user interface at will. But maybe you have good reason for it. So, for this case, here is a "faked radiogroup" in which you can change the colors of the buttons arbitrarily:
Almost perfect...

When you select items with the keyboard you will notice a slight difference to a "true" RadioGroup: While you can navigate with the UP/DOWN arrows in the RadioGroup and select the radio items simultaneously you only navigate in the faked group and must press the space bar to select the item. There is no difference when you select items with the mouse.

A large difference, however, exists in source code: you no longer have the Items[] and ItemIndex properties. Now you must query the Checked property of the individual radiobuttons.

I tested this on Windows, and it works fine - see screenshot. But I could imagine that there are other widgetsets which do not allow to modify the font color of a Label. In this case you could try a TStaticText, or you could draw the item captions directly on the canvas, without using a component. But in the latter case, the entire business gets more complex because the Groupbox does not expose an OnPaint event - probably it would be easier to create a small component based on this idea.
Title: Re: TRadioGroup font does not accept chosen color
Post by: winni on May 17, 2020, 01:04:17 am
Hi!

I found in my sources a quick hack from Delphi1 times.

The details must be inserted by you.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var s : string;
  3. can : TCanvas;
  4.  
  5. begin
  6. Can := TCanvas.Create;
  7. Can.Handle := GetDC(RadioGroup1.handle);
  8. can.Brush.color := clAqua;
  9. can.Font.Color := clRed;
  10. s := RadioGroup1.Items[0];
  11. RadioGroup1.Items[0] := '';
  12. Application.ProcessMessages;
  13. can.FillRect(30,10,60,35);
  14. can.TextOut (30,10,s);
  15. ReleaseDC(RadioGroup1.handle, Can.Handle);
  16. Can.Free;                          
  17. end;

Winni
Title: Re: TRadioGroup font does not accept chosen color
Post by: wp on May 18, 2020, 12:44:20 pm
Another less hacky solution: Install package pl_exControls from the Online Package Manager. It contains a TplRadioButton (and a TplCheckbox) which descends directly from TCustomControl, not from TCustomRadioButton; therefore, you have more control of its properties than with the standard TRadioButton. In particular, you can change the font color as you request.

Put several of these plRadioButtons into a TGroupbox, and you'll have something close to a RadioGroup with color items.
Title: Re: TRadioGroup font does not accept chosen color
Post by: TeoUrbana on May 19, 2020, 02:17:13 am
Quote
I absolutely agree with ASerge that it is not a good idea to change colors of a themed user interface at will.

It is a matter of visual identity. My taste is not very good, but I am trying something different.

winni, thanks for the suggestion. It was almost good. But the background has to be transparent, because of the background colors.

wp, thanks for the pl_exControls suggestion, but it also has a transparency problem and is little ugly.

The way will be to put several GroupBox, RadioButton and Labels, to achieve the desired effect.
It will take work but do what? Is life.
Title: Re: TRadioGroup font does not accept chosen color
Post by: wp on May 19, 2020, 09:50:20 am
wp, thanks for the pl_exControls suggestion, but it also has a transparency problem
In fact, and it also does not handle LCL scaling.

In the meantime I've been working on my own set of custom-drawn check controls (TRadioButtonEx, TCheckBoxEx) and their grouped versions (TRadioGroupEx, TCheckGroupEx). Their code is a combination (and extension) of TCheckboxThemed and TRadioGroup/TCheckGroup. They will respect the Font settings and provide some more properties like vertical alignment, multiple lines and user-defined bitmaps for check marks. Just give me some time to complete.
Title: Re: TRadioGroup font does not accept chosen color
Post by: wp on May 22, 2020, 10:32:02 am
Done. Please see my post at https://forum.lazarus.freepascal.org/index.php/topic,46141.msg363193.html#msg363193 (I don't want to double-post).
Title: Re: TRadioGroup font does not accept chosen color
Post by: TeoUrbana on May 25, 2020, 10:01:36 pm
wp,
thanks for the components. They will supply the need for several developers who face this problem (in this forum we have several posts on the subject).

Without wanting to abuse ... but already abusing  :), could you extend the functionality of the font color of the buttons, to the caption of RadioGroup too?
Title: Re: TRadioGroup font does not accept chosen color
Post by: wp on May 25, 2020, 10:05:26 pm
This is already possible as you can see at the demo. However, you must do this at runtime by changing the Font.Color of the Buttons[index]. Having this available at designtime would make the component much more complicated
Code: Pascal  [Select][+][-]
  1.   RadioGroupEx1.Buttons[0].Font.Color := clRed;
Title: Re: TRadioGroup font does not accept chosen color
Post by: TeoUrbana on May 26, 2020, 03:48:02 am
Yes.
The buttons are working fine.
I speak of caption (RadioGroup.caption). It does not change its color yet.
Title: Re: TRadioGroup font does not accept chosen color
Post by: jamie on May 26, 2020, 06:58:54 pm
Looks like you found an anchor  :P

Code: Pascal  [Select][+][-]
  1.          SetTextColor(DC, GetSysColor(COLOR_GRAYTEXT));
  2.             SelectObject(DC, GroupBox.Font.Reference.Handle);        
  3.  
as you can see there.. it is getting the Systems color for graytext, what ever that is  for the day.

if you turn off your themes it appears to work as you wish..
maybe there should be a property per control to accept Themes.
Title: Re: TRadioGroup font does not accept chosen color
Post by: wp on May 26, 2020, 07:51:37 pm
what ever that is  for the day.
Read the comment a few line higher.
Title: Re: TRadioGroup font does not accept chosen color
Post by: jamie on May 26, 2020, 08:59:11 pm
yeah I notice that, only when the control is disabled..  >:(

but it appears the Themes is getting checked down stream so it is still drawing it via OS colors.

EDIT
  I see the message was already pumped to the control before testing the Themes and disable settings so there is obviously a crutch in original message handler.

TinyPortal © 2005-2018