Recent

Author Topic: Radiobox "Owner Drawn"  (Read 1531 times)

Nicole

  • Hero Member
  • *****
  • Posts: 970
Radiobox "Owner Drawn"
« on: September 26, 2022, 07:18:25 pm »
I want my Radiobox "formatted".
e.g. (I write asterix for a circle)

NOT:
* item1
* item2
* item3
* item4
* item5

BUT:

header1
* item1
* item2

header2
* item3

header3
* item4
* item5

I tried this type TRadiogroupbox (not sure about the name), which looks good, but does not work exactly alike a TRadiobox. And I tried to use "empty" items and deactivate them. It does not look nicely under the line.

Any ideas?

Arioch

  • Sr. Member
  • ****
  • Posts: 421
Re: Radiobox "Owner Drawn"
« Reply #1 on: September 26, 2022, 08:31:47 pm »
1. Use regular TGroupBox or TPanel or TNotebook - any container

2. Select a component for headers - can be anything which look you would like. Customized TLabel, TStaticText, Tpanel, TEdit in read-only mode, anything.

3. drop it in and set .Align to alTop and then tweak .BorderSpacing to make margins look good. Also, set font size, color, whatever you would want.

4. drop TRadiobutton, set .Align to alTop and then tweak .BorderSpacing - so it would look more (or less) indendted than header components.

keep doing it until all the headers and radiobuttons are in

P.S. After them all populated, you might want to play with GroupBox's property ChildSizing.EnlargeVertical

P.P.S. This should make all radiobuttons to "see" each other and only let single one turned on across all the headers. If you want every "header" to have a separate group - you would have to add a TPanel after headers, set it Bevels and Borders to none, and place radiobuttons inside that panel
« Last Edit: September 26, 2022, 08:35:06 pm by Arioch »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2006
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Radiobox "Owner Drawn"
« Reply #2 on: September 26, 2022, 11:05:23 pm »
If each "header/item"-thing shall be useable, i'd suggest to write a small class for that purpose that create a panel top-aligned text and a variable amount of radio-buttons...
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: Radiobox "Owner Drawn"
« Reply #3 on: September 27, 2022, 01:21:56 am »
There are options:

   1.TTreeView is one. It's customizable and natural for indenting etc.

   2. TVirtualstring is another. that allows you to customize the display because you have to draw it anyways.

   3. Multiple group boxes on a TscrollBox.
 
   4. TPanel and implement the paint cycle to place radio marks on the surface using Icons etc.

 
 The list goes on. I've been there and done that ! :o
The only true wisdom is knowing you know nothing

Arioch

  • Sr. Member
  • ****
  • Posts: 421
Re: Radiobox "Owner Drawn"
« Reply #4 on: September 27, 2022, 01:33:00 am »
   1.TTreeView is one. It's customizable and natural for indenting etc.
   2. TVirtualstring is another. that allows you to customize the display because you have to draw it anyways.
   3. Multiple group boxes on a TscrollBox.

Those would create isolated groups, with each group having their own selected item, won't it?
Sure, it can be overriden using events, but why fight problems that we can avoid creating...

I might be reading mind wrongly, but to me the items numbering used by the TS suggests she wants "global" checkboxes, that work "over" headers rather than being contained by them.

Nicole

  • Hero Member
  • *****
  • Posts: 970
Re: Radiobox "Owner Drawn"
« Reply #5 on: September 27, 2022, 12:32:40 pm »
Thank you for all answers.
Yes, I want the function of selecting ONE radiobutton.
About Arioch's answer.
I tried it, but am not very excited about the result:
The problem is, that my groups are not of the same size.
I grouped the radiobox in columns and there I want e.g. the first column five items, the second three and the fifth four.
The items shall belong to my headers.
Or did I do something wrong?

I wonder, if I shall work with 6 radiogroups and let them interact in the way, that each selection makes the 5 others to set their itemndex to -1.
Does this sound, as it would work?
But how to grab the results? I would have to digg into the mess of 5 groups.

Arioch

  • Sr. Member
  • ****
  • Posts: 421
Re: Radiobox "Owner Drawn"
« Reply #6 on: September 27, 2022, 01:14:53 pm »
I wonder, if I shall work with 6 radiogroups and let them interact in the way
But how to grab the results? I would have to digg into the mess of 5 groups.

You make the form-level private property and encapsulate all that mess inside one getter and one setter functions.
You also make a single OnClick event for all the radiogroups. But notice, that the name is wrong, the event is actually on-change one, so when RG 1 would be removing selection from RG 2 - that group 2 would fire it immediately, reentrantly. See recent forum threads on TCheckBox for the evermore batle of "be Delphi-compatible" vs "be consistent"

However, you have to think in advance about "composite item index" - how would you identify those items? What this propery would reort/accept as a value?
Would you just make incremental values, then, for example, you had 3 radiobuttons in group 1, then you want to add a 4th radiobutton there, but you can not. This RB then would be #3 but all your code and databases already fixed it that #3 is the first radiobutton of the seconf group...

OTOH, that holds for every visual design, radiogroups or not.

And from visual design point i dislike the radiogroups, as they might confuse user... Hopefully not for long, but still.

Maybe you can go with TListBox or with TComboBox/TComboBoxEx instead. Albeit i personally think the "selected" state in fancy modern combobox is much less visually distinct than "dull old" radiobutton.

The problem is, that my groups are not of the same size.

Are they really so large, than multi-column layout is required?  Today many screens are large. Okay, the cheapest laptops seem to stick as 1300x760, yet even that is actually a lot.  Funny to remember, many years ago i believed 1024x768 was the ideal resolution and increasing it further would be worsening human experience.

You never hinted at that before, BTW.

Some problem with multi-column is that you can no more have easy auto-size. You would have to fix the size of all the controls in designtime, and then hope the scaling for different font sizes and display resolutions would happen automagically. Hopefully it would.

But okay then, try your luck with TFlowPanel. But then all the "hader labels" and all the radiobuttons would have to have no Align and no AutoSize but carefully selected sizes.
Also you would probably want to use TFlowPanel.OnResize to proactively make header labels almost as wide (save few pixels for margins and borders) as TFlowPanel.CustomWidth
Or maybe headerlabels ".Anchors" could do it automagically, but i was hit few times with inconsistent Anchors in Delphi under less than trivial conditions, like those with lockdowns and remote work, so today i abhor Anchors.

Additionally, what if a user resizes the window (and the panel) and your 4-columns design suddenly snaps into 3-columns design? You would, perhaps, have to use TFlowPanel.OnResize to smartly resize radiobuttons, so they retain the order once designed.

You can also try with TGridPanel but i am not sure it would be a good choice here, both "headerlables" that have to span several columns (all of them, actually) and then all columns having the same width, meaning a really long RB in group2 col2 would make equally wide slot for otherwise narrow RB in group1 col1
« Last Edit: September 27, 2022, 01:19:10 pm by Arioch »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2006
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Radiobox "Owner Drawn"
« Reply #7 on: September 27, 2022, 01:39:59 pm »
Any ideas?

Please show a picture of your doing since after re-reading it makes not that much sense with splitted radiobuttons under different headers but just one of all shall be selected.
I mean, in my experience a header opens a new territory for a selection to be set, bound to headers title. I have no example in my head that opens something the way you want it to be done.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

kirchfritz

  • Jr. Member
  • **
  • Posts: 53
  • WIN10 LAZ 2.2.4 FPC 3.2.2
Re: Radiobox "Owner Drawn"
« Reply #8 on: September 28, 2022, 01:26:57 am »
What about "faking" Radiogroups?
See my example program

kirchfritz

  • Jr. Member
  • **
  • Posts: 53
  • WIN10 LAZ 2.2.4 FPC 3.2.2
Re: Radiobox "Owner Drawn"
« Reply #9 on: September 28, 2022, 07:56:45 pm »
I extended my example.
See screenshot and project-sourcecode

BrunoK

  • Sr. Member
  • ****
  • Posts: 452
  • Retired programmer
Re: Radiobox "Owner Drawn"
« Reply #10 on: September 29, 2022, 04:18:58 pm »
With GroupBox and RadioGroups

Nicole

  • Hero Member
  • *****
  • Posts: 970
Re: Radiobox "Owner Drawn"
« Reply #11 on: September 29, 2022, 05:34:37 pm »
WOW, thank you so much for those nice examples!

 

TinyPortal © 2005-2018