Recent

Author Topic: Multicolumn combobox [SOLVED]  (Read 2517 times)

wp

  • Hero Member
  • *****
  • Posts: 8119
Re: Multicolumn combobox
« Reply #15 on: December 20, 2020, 10:27:23 pm »
Can't agree with this. I like column separators, especially when column text consists of few words:

John Lennon| Liverpool
Lady Gaga| New York

Those who do not like separators can just switch them off...
Yes. But like in TStringGrid there should also be a property for the separator color because the black of the old version stands out too strongly among the other colors of today's themes.
« Last Edit: December 20, 2020, 11:51:22 pm by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Sieben

  • Full Member
  • ***
  • Posts: 206
Re: Multicolumn combobox
« Reply #16 on: December 20, 2020, 10:42:25 pm »
Some more notes:

- SetDelimiter currently does not supply it's value to FParser as well

- while OnDrawItem is no more 'occupied' it is sort of decoupled now

- the look of the dropdown doesn't seem to reflect themes or certain desktop features, it does seem to do a better job when using code from StdCtrls InternalDrawItem (which unfortunately isn't exported so that it could be used directly here):

Code: Pascal  [Select][+][-]
  1. procedure TColumnCombo.DrawItem(Index: Integer; ARect: TRect; State: TOwnerDrawState);
  2. var
  3.   OldBrushStyle: TBrushStyle;
  4.   OldTextStyle: TTextStyle;
  5.   NewTextStyle: TTextStyle;
  6.   i, xl: Integer;
  7. begin
  8.  
  9.   if Assigned(OnDrawItem) then
  10.     OnDrawItem(Self, Index, ARect, State)
  11.   else
  12.   begin
  13.  
  14.     if (Index < 0) or not Assigned(FOffsets) then
  15.       Exit;
  16.  
  17.     if not (odBackgroundPainted in State) then
  18.       Canvas.FillRect(ARect);
  19.  
  20.     OldBrushStyle := Canvas.Brush.Style;
  21.     Canvas.Brush.Style := bsClear;
  22.  
  23.     OldTextStyle := Canvas.TextStyle;
  24.     NewTextStyle := OldTextStyle;
  25.     NewTextStyle.Layout := tlCenter;
  26.     NewTextStyle.RightToLeft := UseRightToLeftReading;
  27.     if UseRightToLeftAlignment then
  28.     begin
  29.       NewTextStyle.Alignment := taRightJustify;
  30.       ARect.Right := ARect.Right - 2;
  31.     end
  32.     else
  33.     begin
  34.       NewTextStyle.Alignment := taLeftJustify;
  35.       ARect.Left := ARect.Left + 2;
  36.     end;
  37.     Canvas.TextStyle := NewTextStyle;
  38.  
  39.     FParser.DelimitedText := Items[Index];
  40.     for i := 0 to FParser.Count-1 do
  41.     begin
  42.       xl := ARect.Left + FOffsets[i];
  43.       Canvas.TextRect(ARect, xl, 0, FParser[i]);
  44.     end;
  45.  
  46.     Canvas.Brush.Style := OldBrushStyle;
  47.     Canvas.TextStyle := OldTextStyle;
  48.   end;
  49. end;

Also csOwnerDrawFixed does not adjust the dropdown to the item width like eg csDropDownList does, is this a general issue or again due to my wicked Unity7 desktop here?
Lazarus 2.0.10, FPC 3.2.0, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

jamie

  • Hero Member
  • *****
  • Posts: 4210
Re: Multicolumn combobox
« Reply #17 on: December 20, 2020, 11:43:04 pm »
When owner drawing you are pretty much in control..

There is a ItemWidth if set to something non 0 will force the drop down width to a fixed size..

just calculate your max width needed and if its variable then you can change that I guess on the fly depending on what is going to be shown.

There is a OnDropDown, maybe you could set the with there by scanning the known strings that will be shown for a max width..

The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 8119
Re: Multicolumn combobox
« Reply #18 on: December 21, 2020, 12:07:52 am »
- the look of the dropdown doesn't seem to reflect themes or certain desktop features, it does seem to do a better job when using code from StdCtrls InternalDrawItem (which unfortunately isn't exported so that it could be used directly here):
What do you mean? When I put the columncombo and a standard combobox side by side they look exactly the same (Windows, though).

InternalDrawitem does not use ThemeServices either... BTW, are there any ThemeServices for drawing the dropdown at all? The only thing that InternalDrawItem adds is BiDi support.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

howardpc

  • Hero Member
  • *****
  • Posts: 3646
Re: Multicolumn combobox
« Reply #19 on: December 21, 2020, 12:10:25 am »
Howard, this is a quite useful component. But I am afraid that it will be forgotten again in the forum. As you know I am maintaining a package ExCtrls which contains extended versions of the standard controls. I think it would fit in there well.

Would you allow me to add this component to this package?
Sure, with the proviso that it's clearly still buggy and needs sorting out, and I don't have the time or motivation to do more on it at the moment, so over to you, or others. Please take it forward.

Quote
In order to have consistent naming, I'd change its name to TColumnComboboxEx, and for a consistent license I prefer to replace GPL by LGPL2 with linking exception (like LCL). Would this be ok for you?
Sure. A logical and consistent naming scheme helps one (subliminally) to categorise new objects conceptually, and find them quickly months later when you vaguely recall seeing something you now need.
 The best controls are nearly always a collaboration between several people, as the LCL testifies abundantly. Some people are good at throwing out brilliant ideas, others are good at picking them up, others at sorting out abstruse technical issues, others at documenting etc. It is encouraging when forum members here play to their strengths.

Sieben

  • Full Member
  • ***
  • Posts: 206
Re: Multicolumn combobox
« Reply #20 on: December 21, 2020, 12:24:31 am »
Quote from: wp
What do you mean? When I put the columncombo and a standard combobox side by side they look exactly the same (Windows, though).
When I do that here, columncombo 'as is' will display a dropdown with bright background and dark text, the standard combo (with csDropDownList) white text on a dark background. When using the code I suggested columncombo displays dark background and, unfortunately, dark text again for non-selected items (like mentioned here). But at least it displays exactly the same as a standard combo with csOwnerDrawFixed does.

@jamie - Played around with ItemWidth in both OI and OnDropDown to no avail...
Lazarus 2.0.10, FPC 3.2.0, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

jamie

  • Hero Member
  • *****
  • Posts: 4210
Re: Multicolumn combobox
« Reply #21 on: December 21, 2020, 12:28:00 am »
are you doing this on Windows ?

I know the Item width does work because I just checked it, in owner draw i can make that thing stretch across the screen with no items.

also to WP question, you can use Themes manually if you wish..

The only true wisdom is knowing you know nothing

Sieben

  • Full Member
  • ***
  • Posts: 206
Re: Multicolumn combobox
« Reply #22 on: December 21, 2020, 12:36:02 am »
Linux, as in my signature. And it doesn't exactly have to be themes but, as I said, this Unity7 desktop here. All I can say is that columncombo looks like a standard combo with the same settings if the code I suggested is used, and that it doesn't when the original code is used. Please don't ask me why, I'm still trying to find out and to find solution for this dark text on dark background nuisance...
Lazarus 2.0.10, FPC 3.2.0, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

jamie

  • Hero Member
  • *****
  • Posts: 4210
Re: Multicolumn combobox
« Reply #23 on: December 21, 2020, 12:42:23 am »
I didn't look at the code fully that was posted here but normally you need to set the brush color and style for the background and then the Font.color prior to every OnDrawItem event.


 I just did some checking and it appears you can use the OnGetItems before the list is dropped which allows you to make the adjustments at that point.

 It can also let you populate the list with a minimum content from somewhere else, this gives me some ideas now for something I was doing at some other time the hard way, a filter search and display list  ;)
The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 8119
Re: Multicolumn combobox
« Reply #24 on: December 21, 2020, 04:53:24 pm »
Now I added the unit in Howard's post (named ExCombo now) to the ExCtrls package. The component is named TColumnComboBoxEx now and, after installation, appears on the ExCtrls palette page with a new high-DPI-aware icon. I activated the ShowColSeparator property and added a new ColSeparatorColor property. Most of the issue mentioned above are fixed - except for the one that the selected item is not displayed in the collapsed control although ItemIndex >= 0. The usage of theme-aware color selection also has not yet been addressed.

The ExCtrls package is not yet available via OPM because it is still very experimental. To get it you must use svn to check it out from CCR (https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/exctrls/), or you can download the snapshot zip there.

Further details on the wiki page: https://wiki.freepascal.org/ExCtrls#TColumnComboBoxEx
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Sieben

  • Full Member
  • ***
  • Posts: 206
Re: Multicolumn combobox
« Reply #25 on: December 21, 2020, 05:54:10 pm »
I made a few screenshots to illustrate what I mean. As you can see, column combo displays buggy with the suggested code, but at least it's consistently buggy with the way the standard combo does, whereas the column combo with the original code displays in a completely different fashion.

You can also see that csOwnerDraw does not adjust the width of the dropdown here, and that the dropdown covers the edit portion instead of being appended underneath as with style csDropDown/List. Unfortunately I don't have another system here right now to do some testing with eg Windows but from the screenshot in the opening post it's working different there.

EDIT: Sorry, the 'overlapping' seems to be a native feature of this here desktop. So please ignore that part.
« Last Edit: December 21, 2020, 10:16:45 pm by Sieben »
Lazarus 2.0.10, FPC 3.2.0, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

wp

  • Hero Member
  • *****
  • Posts: 8119
Re: Multicolumn combobox
« Reply #26 on: December 21, 2020, 10:37:29 pm »
We did not touch the dropdown width and positioning. So when anything is wrong it must be inherited from the ancestor TCustomComboBox.

In the meantime I fixed a another painting issue which was visible in Linux (no transparent text background) and found the reason why the selected item was not shown in the non-dropdown case (handle not yet allocated in the early phase).
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Sieben

  • Full Member
  • ***
  • Posts: 206
Re: Multicolumn combobox
« Reply #27 on: December 21, 2020, 11:17:59 pm »
Did you see my edit remark above? Positioning obviously is a feature of this here desktop, but the lack of width adjustment and the 'black on black' painting of non-selected items seems indeed to be a matter of TCustomComboBox. I've seen non-editable combos in other applications here do correctly. With csDropDown/List it works ok for the standard combo, but in this case DrawItem is not called at all, the widgetset seems to handle it directly(?). This is not an issue of the column combo alone, and we had that before...

But as you can see by comparing above screenshots LazStdCombo02 and LazColCombo01 there is a difference in painting the dropdown right now that might as well show on other OS or Desktops. It would however behave like a standard combo if the code from StdCtrls InternalDrawItem was used as suggested.
« Last Edit: December 21, 2020, 11:42:42 pm by Sieben »
Lazarus 2.0.10, FPC 3.2.0, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

wp

  • Hero Member
  • *****
  • Posts: 8119
Re: Multicolumn combobox
« Reply #28 on: December 22, 2020, 12:46:44 am »
I cannot reproduce this dropdown width issue, not even on Linux (LMDE 4/gtk2). Do the TColorBox and the TComboBoxEx work for you? They are customdrawn similar to TColumnComboboxEx. If they do you could study their code, find what's different and post a patch.

As for the InternalDrawItem code: it's essential code is already included (only RTL is still missing). Do you read my code? And I really cannot imagine how this code could affect the width of the dropdown...
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Sieben

  • Full Member
  • ***
  • Posts: 206
Re: Multicolumn combobox
« Reply #29 on: December 22, 2020, 01:06:36 am »
Below is a screenshot of how a TColorBox looks like here... but forget about the width for now, the point I'm trying to make is that the column combo paints a dark text on a bright background right now whereas the standard combo paints (or tries to paint) a bright text on a dark background. Standard and column combo look different despite same settings. It doesn't matter in the first place that this code doesn't really work here with this desktop but that it should at least be consistent.
« Last Edit: December 22, 2020, 11:55:36 am by Sieben »
Lazarus 2.0.10, FPC 3.2.0, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

 

TinyPortal © 2005-2018