Recent

Author Topic: Radio and Check with no caption still select empty text  (Read 3324 times)

Gald

  • Full Member
  • ***
  • Posts: 107
Radio and Check with no caption still select empty text
« on: July 21, 2022, 05:29:24 pm »
Hello guys!

I really need to avoid these lines/dots of the selection when there's no caption on RadioButtons and Checkboxes. Because I will use StaticText instead.

Just need to say that know that StaticText can't be visually focused, I'm working on this.

Just need to know how to remove this 'empty' selection.
« Last Edit: July 21, 2022, 05:34:02 pm by Gald »
Lazarus 2.0.12 r64642 FPC 3.2.0 x86_64-win64-win32/win64/Manjaro KDE 21
AMD Ryzen 3 1300X Quad-Core Processor 3.50 GHz / 8,00 GB RAM / GTX 1500 TI / 2TB M.2 NVMe

ASerge

  • Hero Member
  • *****
  • Posts: 2483
Re: Radio and Check with no caption still select empty text
« Reply #1 on: July 21, 2022, 08:11:41 pm »
I really need to avoid these lines/dots of the selection when there's no caption on RadioButtons and Checkboxes. Because I will use StaticText instead.
Use the Panel near to it (see the attached image). Of course without a caption.
Z-Order: Checkbox, Panel, StaticText.

Don't forget that the user must somehow see which element he selects if the system method is hidden.
In my opinion, the system method of selecting elements, familiar to the user, is preferable.

Handoko

  • Hero Member
  • *****
  • Posts: 5530
  • My goal: build my own game engine using Lazarus
Re: Radio and Check with no caption still select empty text
« Reply #2 on: July 21, 2022, 08:27:11 pm »
Nice trick!

I tried to examine into the source code but couldn't find anything useful to hide the selection rectangle.

Gald

  • Full Member
  • ***
  • Posts: 107
Re: Radio and Check with no caption still select empty text
« Reply #3 on: July 22, 2022, 04:25:30 am »
I tried to examine into the source code but couldn't find anything useful to hide the selection rectangle.

Oh, no! Very bad news.
So this must be a Windows 'feature', unfortunately.
I appreciate your work, anyway.

Use the Panel near to it (see the attached image).

What a funny and nice solution!
This is the kind of thing I totally use in a random project, but my goal is to make a set of components, so it demands an elegant solution.
I'll probably store the selected object in a var while the object, the checkbox in the case, will have no TabStop.

Don't forget that the user must somehow see which element he selects if the system method is hidden.
In my opinion, the system method of selecting elements, familiar to the user, is preferable.

Yes, i'm using TShape. Pic related.
Lazarus 2.0.12 r64642 FPC 3.2.0 x86_64-win64-win32/win64/Manjaro KDE 21
AMD Ryzen 3 1300X Quad-Core Processor 3.50 GHz / 8,00 GB RAM / GTX 1500 TI / 2TB M.2 NVMe

Handoko

  • Hero Member
  • *****
  • Posts: 5530
  • My goal: build my own game engine using Lazarus
Re: Radio and Check with no caption still select empty text
« Reply #4 on: July 22, 2022, 05:08:48 am »
That looks nice. Writing own components is fun. If I were you, I might inherited the checkbox from TWinControl or TControl and do the drawing using TCanvas not TShape, the focus rectangle can be drawn using TCanvas.DrawFocusRect.

... the checkbox in the case, will have no TabStop.

Why no tabstop? How can user select that item using keyboard?

Gald

  • Full Member
  • ***
  • Posts: 107
Re: Radio and Check with no caption still select empty text
« Reply #5 on: July 22, 2022, 10:14:06 am »
Quote from: Handoko
Why no tabstop? How can user select that item using keyboard?

About the keyboard, I could try to send the sender through various methods or something like this, but now I realize now that even with no TabStop the problem keeps on.
I also find out 3 problems with the StaticText. I'll open a thread about it tomorrow.

Quote from: Handoko
I might inherited the checkbox from TWinControl or TControl and do the drawing using TCanvas.

I choose this because:

2- Canvas is too slow, they say (i have never used it).
3- Demands a lot of work and test (for animation, colors, etc).
4- The default component match visually well with what I'm trying to do, even while the "skins" are changed.
5- I do not have too much knowledge for that.
6- There's a lack of material (i guess).

Please, correct me if I am wrong.

But the (1) primal reason, is because I'm trying to do runtime "components", with no installation, no package files. Just a Unit to be added to the project. That's why so much work around, but they feel fast/natural/native. Honestly, I don't know if I can hit that, but at least I'm having fun.

I also read somewhere that BGRA can draw way faster than Canvas, but I will try to not use it as far as I can go to not require any installation or third party.
Lazarus 2.0.12 r64642 FPC 3.2.0 x86_64-win64-win32/win64/Manjaro KDE 21
AMD Ryzen 3 1300X Quad-Core Processor 3.50 GHz / 8,00 GB RAM / GTX 1500 TI / 2TB M.2 NVMe

Handoko

  • Hero Member
  • *****
  • Posts: 5530
  • My goal: build my own game engine using Lazarus
Re: Radio and Check with no caption still select empty text
« Reply #6 on: July 22, 2022, 10:30:16 am »
Quote from: Handoko
... do the drawing using TCanvas.

I choose this because:
...
2- Canvas is too slow, they say (i have never used it).
...

TCanvas is slow but TShape is slower because TShape internally uses TCanvas. So instead of using TShape, it will be 'better' to use TCanvas directly.

I also read somewhere that BGRA can draw way faster than Canvas ...

TBGRABitmap has some new features that uses hardware accelerated functions (OpenGL) but most of TBGRABitmap functions are not hardware accelerated.

I read that we can easily switch the program from using TCanvas to use TBGRABitmap/Canvas. I tried it on my 2D side scrolling game, which uses purely TCanvas. The TBGRABitmap version run as slow as the original TCanvas version, but on some very rare cases it run about 3% slower.

If performance is important you should go directly to OpenGL, like what I'm doing now, still not finished yet.

If you're willing to share the code you already have now, share it here. I will modified it to use TCanvas. That shouldn't be hard, I consider it as a fun thing to do for my weekend.

Gald

  • Full Member
  • ***
  • Posts: 107
Re: Radio and Check with no caption still select empty text
« Reply #7 on: July 22, 2022, 12:02:57 pm »
HAHA!

The real thing is: that there's no code.
I just started this some hours ago, with a few controls in the form while I tested his behaviors.
I'll attach it anyway just for you to know how I do my tests.
But, there's nothing to do there because I still understand the behavior of the StaticText.

Please, don't be mad.  :-[
Lazarus 2.0.12 r64642 FPC 3.2.0 x86_64-win64-win32/win64/Manjaro KDE 21
AMD Ryzen 3 1300X Quad-Core Processor 3.50 GHz / 8,00 GB RAM / GTX 1500 TI / 2TB M.2 NVMe

Gald

  • Full Member
  • ***
  • Posts: 107
Re: Radio and Check with no caption still select empty text
« Reply #8 on: July 22, 2022, 12:31:21 pm »
It's time to pass some shame online.  :-[ :-[ :-[

Look at my folder full of tests.
I gonna post one here just to see your opinion.
I did revise the code by months, and it's probably full of tests and incomplete code, but is working.
But, is using Panel and Timer. Please be honest, Handoko. I'll not get offended. Panel and Timer is a noobie combination, I know.
Lazarus 2.0.12 r64642 FPC 3.2.0 x86_64-win64-win32/win64/Manjaro KDE 21
AMD Ryzen 3 1300X Quad-Core Processor 3.50 GHz / 8,00 GB RAM / GTX 1500 TI / 2TB M.2 NVMe

Paolo

  • Hero Member
  • *****
  • Posts: 695
Re: Radio and Check with no caption still select empty text
« Reply #9 on: July 22, 2022, 01:25:08 pm »
what about the code here attached ? (Delphi code, but you can copy paste on lazarus-fpc project).
a new Tpanel componente created at fly with checkbox inside. Add the tbutton1 and click on it several time you'll see a column of check boxes.

Code: Pascal  [Select][+][-]
  1. type
  2.   TMyPanel = Class(TPanel)
  3.   private
  4.     MyChkBox : TCheckBox;
  5.     function GetChecked : boolean;
  6.   public
  7.     property Checked : boolean read GetChecked;
  8.     Constructor Create(AOwner : TComponent); override;
  9.   End;
  10.  
  11.   TForm1 = class(TForm)
  12.     Button1: TButton;
  13.     procedure Button1Click(Sender: TObject);
  14.   end;
  15.  
  16. var
  17.   Form1: TForm1;
  18.  
  19. implementation
  20.  
  21. {$R *.dfm}
  22.  
  23. var
  24.   Counter : integer;
  25.  
  26. procedure TForm1.Button1Click(Sender: TObject);
  27. var
  28.   X : TMyPanel;
  29. begin
  30.   X:=TMyPanel.Create(Self);
  31.   X.Top:=Counter;
  32.   X.Left:=0;
  33.   Counter:=Counter+X.Height;
  34. end;
  35.  
  36. { TMyPanel }
  37.  
  38. constructor TMyPanel.Create(AOwner: TComponent);
  39. begin
  40.   inherited Create(AOwner);
  41.   Parent:=Form1;
  42.   Width:=16;
  43.   Height:=16;
  44.   BevelOuter:=bvNone;  //flat effect
  45.   MyChkBox:=TCheckBox.Create(Self);
  46.   MyChkBox.Parent:=Self;
  47.   MyChkBox.Caption:='';
  48. end;
  49.  
  50. function TMyPanel.GetChecked: boolean;
  51. begin
  52.   result:=MyChkBox.Checked;
  53. end;
  54.  
  55. initialization
  56.   Counter:=0;
  57. end.
  58.  
  59.  

Maybe a better approach should be similar but using a TImage with internally images of checked, unchecked and grayed "checkbox images".
« Last Edit: July 22, 2022, 01:35:29 pm by Paolo »

wp

  • Hero Member
  • *****
  • Posts: 13491
Re: Radio and Check with no caption still select empty text
« Reply #10 on: July 22, 2022, 03:20:29 pm »
I really need to avoid these lines/dots of the selection when there's no caption on RadioButtons and Checkboxes. Because I will use StaticText instead.
The TCheckboxEx and TRadioButtonEx in the ExCtrls package (https://wiki.freepascal.org/ExCtrls#TRadioButtonEx.2C_TCheckBoxEx.2C_TRadioGroupEx_and_TCheckGroupEx) do not draw the focus rectangle when the Caption is empty. They have several advantages compared to the standard controls, and I could guess that they can do what you want to achieve with the TStaticText.

If you don't want to install the full package you could alternatively copy the unit ExCheckCtrls into your project folder - it is fully self-contained.

Gald

  • Full Member
  • ***
  • Posts: 107
Re: Radio and Check with no caption still select empty text
« Reply #11 on: July 22, 2022, 08:09:28 pm »
what about the code here attached ?

Thank you, Paolo!
This approach can be useful in some future projects, I'll save your post.

If you don't want to install the full package you could alternatively copy the unit ExCheckCtrls into your project folder - it is fully self-contained.

Such a nice project! This should come pre-installed in Lazarus. That's exactly what I'm looking for!
Thank you so much!  :D
Lazarus 2.0.12 r64642 FPC 3.2.0 x86_64-win64-win32/win64/Manjaro KDE 21
AMD Ryzen 3 1300X Quad-Core Processor 3.50 GHz / 8,00 GB RAM / GTX 1500 TI / 2TB M.2 NVMe

Handoko

  • Hero Member
  • *****
  • Posts: 5530
  • My goal: build my own game engine using Lazarus
Re: Radio and Check with no caption still select empty text
« Reply #12 on: July 23, 2022, 02:35:45 am »
Paolo already provided a good and simple solution. So I wrote a more complex one. I posted it here:

https://forum.lazarus.freepascal.org/index.php/topic,60050.msg448337/topicseen.html#new

Handoko

  • Hero Member
  • *****
  • Posts: 5530
  • My goal: build my own game engine using Lazarus
Re: Radio and Check with no caption still select empty text
« Reply #13 on: July 23, 2022, 07:01:22 am »
Look at my folder full of tests.
I gonna post one here just to see your opinion.
I did revise the code by months, and it's probably full of tests and incomplete code, but is working.
But, is using Panel and Timer. Please be honest, Handoko. I'll not get offended. Panel and Timer is a noobie combination, I know.

Interesting. Where did you got the code of ToastMessage? Did you write it yourself? That was pretty nice.

Nothing wrong with TPanel + TTimer combination. TPanel is okay for most situations. But I found TPanel is not very mouse-click responsive. You won't know it until you use TPanel for a mouse clicking game. TTimer is well-suited for most cases, you can use it to do some GUI effects, even games. But TTimer has a limitation, if I am not wrong, Interval < 16 will be treated as 16. So, if time precision is important, you should use EpikTimer, but we rarely need it. Alternative, you can use delta time technique.  It has some advantages, which makes it is commonly used in game programming. But some will avoid using it because it may speeding up suddenly, which is not good for certain games. Most of the Lazarus provided components are suitable for GUI usage. Problem will arise if you use them for games, because performance and memory efficient are very important in game programming.

If I were you, I would use just only 1 TTimer. Using multiple timers may cause the code harder to debug. Not a joke, but I ever took months to help someone to debug his code that had 2 timers running at the same time.

For your case this what the timers do:
Timer1_start: do (28-12)/2 * Interval 10 -> Time1_stop, Timer2_start: wait Interval 1300 -> Timer2_stop, Timer3_start: do (28-12)/2 * Interval 10 -> Timer3_stop

That can be simplify to use only 1 timer:
Timer_start: do_task1 for (28-12)/2 * Interval 10 -> Timer_change_task: do_nothing for 130 * Interval 10 -> Timer_change_task: do_task3 for (28-12)/2 * Interval 10 -> Timer_stop

Basically these 2 above will give you the same result but using 1 TTimer is easier when to debug if something bad happens.
« Last Edit: July 23, 2022, 07:07:14 am by Handoko »

Gald

  • Full Member
  • ***
  • Posts: 107
Re: Radio and Check with no caption still select empty text
« Reply #14 on: July 25, 2022, 10:55:32 am »

Interesting. Where did you got the code of ToastMessage? Did you write it yourself? That was pretty nice.

Yes! I did with thousand tests, but it still looks like a workaround. Because is based on Panels and Timers. But I don't know anything more professional.
"if all you have is a TTimer, everything looks like a CGI."

Quote
Nothing wrong with TPanel + TTimer combination. TPanel is okay for most situations. But I found TPanel is not very mouse-click responsive. You won't know it until you use TPanel for a mouse clicking game.

I did notice some small problems like don't always execute OnExit event when the mouse is moving fast, especially on Linux and others described in the attached video 1.
But what you can tell me about using Panels like Buttons? I was excited because I emulated the key press, something that I did see in other 3° third controls. But now I'm afraid.

Quote
TTimer is well-suited for most cases, you can use it to do some GUI effects, even games. But TTimer has a limitation, if I am not wrong, Interval < 16 will be treated as 16.

I don't remember exactly, but in my tests (the left panel indicator on video 2), I found a huge difference in Timer between Windows and Linux. Maybe general faster in Linux, but way slower than Windows when Interval was about 10 and 1. I don't remember well, but is something like this. So, instead of putting a compiler directive, I found a number between the two OS that I liked. Probably it will execute differently in other machine configurations, at different speeds. So, by the video, you'll get the idea of what I'm trying to do.


About what you said in the other thread, about Grammar, I have the same problem and a browser extension called Grammarly which helps me a lot.
« Last Edit: July 25, 2022, 05:07:14 pm by Gald »
Lazarus 2.0.12 r64642 FPC 3.2.0 x86_64-win64-win32/win64/Manjaro KDE 21
AMD Ryzen 3 1300X Quad-Core Processor 3.50 GHz / 8,00 GB RAM / GTX 1500 TI / 2TB M.2 NVMe

 

TinyPortal © 2005-2018