Recent

Author Topic: [Solved] Flickering issue when moving CheckboxList item  (Read 539 times)

loaded

  • Hero Member
  • *****
  • Posts: 824
[Solved] Flickering issue when moving CheckboxList item
« on: March 31, 2023, 10:31:13 am »
Hi All,
I am trying to make a simple layer manager with CheckboxList component. Thanks to the help of friends on the forum I created a simple working example. My current problem is that the flickering when moving the relevant layers up or down isn't really a major problem, but it would be great if it could be solved visually.
I would appreciate it if the experts in the business could take a look at the relevant demo. Respects.
« Last Edit: March 31, 2023, 02:28:03 pm by loaded »
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

jcmontherock

  • Full Member
  • ***
  • Posts: 234
Re: Flickering issue when moving CheckboxList item
« Reply #1 on: March 31, 2023, 10:40:13 am »
No issue for me: no flickering. W11/2.2.6 X64.
Windows 11 UTF8-64 - Lazarus 3.2-64 - FPC 3.2.2

cappe

  • Full Member
  • ***
  • Posts: 191
Re: Flickering issue when moving CheckboxList item
« Reply #2 on: March 31, 2023, 11:33:49 am »
works fine for me, I use linux

wp

  • Hero Member
  • *****
  • Posts: 11854
Re: Flickering issue when moving CheckboxList item
« Reply #3 on: March 31, 2023, 12:09:40 pm »
No flicker here either (Win 11, Laz/main (32bit) FPC 3.2.2).

Alternatively you could try a TListview with activated checkboxes (ListView1.Checkboxes := true); query the checked states from the corresponding TListItem property.

See attached demo (tested to work on Win, Linux/gtk2. It does not work on cocoa but there the customdrawn Checklistbox does not work either).

paweld

  • Hero Member
  • *****
  • Posts: 970
Re: Flickering issue when moving CheckboxList item
« Reply #4 on: March 31, 2023, 12:41:56 pm »
Draw only if indexes change:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.CheckListBox1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  2. var
  3.   c1, c2: Boolean;
  4. begin
  5.   if ssleft in shift then
  6.   begin
  7.     move_lay_son := CheckListBox1.ItemIndex;
  8.     if move_lay_son = move_lay_ilk then
  9.       exit;
  10.     c1 := CheckListBox1.Checked[move_lay_ilk];
  11.     c2 := CheckListBox1.Checked[move_lay_son];
  12.     CheckListBox1.Exchange(move_lay_ilk, move_lay_son);
  13.     CheckListBox1.Checked[move_lay_ilk] := c2;
  14.     CheckListBox1.Checked[move_lay_son] := c1;
  15.     move_lay_ilk := move_lay_son;
  16.   end;
  17. end;          
Best regards / Pozdrawiam
paweld

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Flickering issue when moving CheckboxList item
« Reply #5 on: March 31, 2023, 01:30:07 pm »
No flicker here either (Win 11, Laz/main (32bit) FPC 3.2.2).

Alternatively you could try a TListview with activated checkboxes (ListView1.Checkboxes := true); query the checked states from the corresponding TListItem property.

See attached demo (tested to work on Win, Linux/gtk2. It does not work on cocoa but there the customdrawn Checklistbox does not work either).
You forgot about the issue that he got so I've upgraded a little.
Set property DragMode for ListView1 to dmAutomatic
create OnDragDrop event with something like this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.ListView1DragDrop(Sender , Source: TObject; X , Y: Integer);
  2. var
  3.   MyItem : TListItem;
  4. begin
  5.   if Source = ListView1 then
  6.     with Source as TListView do
  7.       begin
  8.         if (GetItemAt(X,Y) <> nil) then
  9.           begin
  10.             MyItem := Items.Insert(GetItemAt(X,Y).Index);
  11.             MyItem.Assign(Selected);
  12.             Selected.Delete;
  13.           end;
  14.       end;
  15. end;
create OnDragOver event with something like this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.ListView1DragOver(Sender , Source: TObject; X , Y: Integer;
  2.   State: TDragState; var Accept: Boolean);
  3. begin
  4.   If Source = ListView1 then
  5.     Accept := True
  6.     else
  7.     Accept := False;
  8. end;

But I am unsure about how to display the content while you are dragging...
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

loaded

  • Hero Member
  • *****
  • Posts: 824
Re: Flickering issue when moving CheckboxList item
« Reply #6 on: March 31, 2023, 02:27:51 pm »
Dear brothers jcmontherock, cappe, wp, paweld  and KodeZwerg, I would like to thank each and every one of you. I took your precious time, I hope one day I will have the opportunity to offer you all a coffee  :)
I am looking for solutions for this for now as I am interested in wp and KodeZwerg Checkbox. But your advice is very valuable for me, it was good to learn about them.
paweld's suggestion worked.
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

 

TinyPortal © 2005-2018