Sign in Join
Wiki copytemporary

ATListbox: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: ATListbox

OldNewLine
1+# About
2+
3+ATListbox is OS-independant listbox control. It's made for dialog like Sublime Text's command list. If OnDrawItem is set, listbox is fully owner-drawn: you must not set items, just set ItemCount, ItemIndex.
4+
5+Listbox doesn't get focus by click; to get focus on click set CanGetFocus=true (if focused, it handles keys Up/Down/PgUp/PgDn/Home/End, else you need to handle OnKeyDown in form and set listbox's ItemIndex by hand, which is boring).
6+
7+Author: Alexey Torgashin
8+
9+Screenshot:
10+
11+<figure>
12+<img src="atlistbox.png" title="atlistbox.png" />
13+<figcaption>atlistbox.png</figcaption>
14+</figure>
15+
16+# Download
17+
18+Homepage at github: <https://github.com/Alexey-T/ATFlatControls>
19+
20+# License
21+
22+MPL 2.0 or LGPL.
23+
24+# Properties
25+
26+- Items: StringList to store items, or you can ignore it if you use OnDrawItem event (listbox will be fully virtual)
27+- ItemCount: count of items
28+- ItemIndex: index of active item
29+- ItemTop: index of item visible at the top
30+- ItemHeight: height (in pixels) of each item
31+- VisibleItems: count of items fully visible inside control
32+- CanGetFocus: allow control to be focused on click
33+
34+- ThemedScrollbar: allows control to use [[ATScrollBar]] instead of default OS scrollbar
35+- ThemedColors: not used (made to use in CudaText app)
36+
37+Events
38+
39+- OnClick
40+- OnDblClick
41+- OnDrawItem: allows to owner-draw all items
42+- OnChangedSel: fired on changed ItemIndex
43+
44+# Example
45+
46+Let's create list:
47+
48+``` pascal
49+uses Math, ATListbox; //package atflatcontrols_package.lpk
50+
51+var
52+ b: TATListbox;
53+
54+procedure TfmMain.FormCreate(Sender: TObject);
55+begin
56+ b:= TATListbox.Create(Self);
57+ b.Parent:= Self;
58+ b.Align:= alClient;
59+
60+ b.OnDrawItem:= @ListDraw;
61+ b.OnClick:= @ListClick; //see example in github https://github.com/Alexey-T/ATFlatControls/blob/master/app/demo_listbox/unit1.pas
62+
63+ b.Color:= $e0e0e0;
64+ b.ItemCount:= 21;
65+end;
66+```
67+
68+Let's set OnDrawItem to this (simply paint "itemNN"):
69+
70+``` pascal
71+procedure TfmMain.ListDraw(Sender: TObject; C: TCanvas; AIndex: integer;
72+ const ARect: TRect);
73+begin
74+ C.Brush.Color:= IfThen(AIndex=b.ItemIndex, clMedGray, b.Color);
75+ C.FillRect(ARect);
76+
77+ C.Pen.Color:= clMedGray;
78+ C.Line(ARect.Left+2, ARect.Bottom-1, ARect.Right-2, ARect.Bottom-1);
79+
80+ C.TextOut(ARect.Left+6, ARect.Top+2, 'item '+inttostr(AIndex));
81+end;
82+```
83+
84+---
85+*From the Free Pascal wiki, page "ATListbox", as it stood on 2021-12-16 after a change by Alextp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
86+Category: Components
87+Category: Lazarus

Back to history