ATListbox: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | # About | |
| 2 | 2 | ||
| 3 | 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 | 4 | ||
| 5 | 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 | 6 | ||
| 7 | 7 | Author: Alexey Torgashin | |
| 8 | 8 | ||
| 9 | 9 | Screenshot: | |
| 10 | 10 | ||
| 11 | - | ||
| 12 | - | ||
| 13 | - | ||
| 14 | - | ||
| 11 | + |  | |
| 15 | 12 | ||
| 16 | 13 | # Download | |
| 17 | 14 | ||
| 18 | 15 | Homepage at github: <https://github.com/Alexey-T/ATFlatControls> | |
| 19 | 16 | ||
| 20 | 17 | # License | |
| 21 | 18 | ||
| 22 | 19 | MPL 2.0 or LGPL. | |
| 23 | 20 | ||
| 24 | 21 | # Properties | |
| 25 | 22 | ||
| 26 | 23 | - Items: StringList to store items, or you can ignore it if you use OnDrawItem event (listbox will be fully virtual) | |
| 27 | 24 | - ItemCount: count of items | |
| 28 | 25 | - ItemIndex: index of active item | |
| 29 | 26 | - ItemTop: index of item visible at the top | |
| 30 | 27 | - ItemHeight: height (in pixels) of each item | |
| 31 | 28 | - VisibleItems: count of items fully visible inside control | |
| 32 | 29 | - CanGetFocus: allow control to be focused on click | |
| 33 | 30 | ||
| 34 | 31 | - ThemedScrollbar: allows control to use [[ATScrollBar]] instead of default OS scrollbar | |
| 35 | 32 | - ThemedColors: not used (made to use in CudaText app) | |
| 36 | 33 | ||
| 37 | 34 | Events | |
| 38 | 35 | ||
| 39 | 36 | - OnClick | |
| 40 | 37 | - OnDblClick | |
| 41 | 38 | - OnDrawItem: allows to owner-draw all items | |
| 42 | 39 | - OnChangedSel: fired on changed ItemIndex | |
| 43 | 40 | ||
| 44 | 41 | # Example | |
| 45 | 42 | ||
| 46 | 43 | Let's create list: | |
| 47 | 44 | ||
| 48 | 45 | ``` pascal | |
| 49 | 46 | uses Math, ATListbox; //package atflatcontrols_package.lpk | |
| 50 | 47 | ||
| 51 | 48 | var | |
| 52 | 49 | b: TATListbox; | |
| 53 | 50 | ||
| 54 | 51 | procedure TfmMain.FormCreate(Sender: TObject); | |
| 55 | 52 | begin | |
| 56 | 53 | b:= TATListbox.Create(Self); | |
| 57 | 54 | b.Parent:= Self; | |
| 58 | 55 | b.Align:= alClient; | |
| 59 | 56 | ||
| 60 | 57 | b.OnDrawItem:= @ListDraw; | |
| 61 | 58 | b.OnClick:= @ListClick; //see example in github https://github.com/Alexey-T/ATFlatControls/blob/master/app/demo_listbox/unit1.pas | |
| 62 | 59 | ||
| 63 | 60 | b.Color:= $e0e0e0; | |
| 64 | 61 | b.ItemCount:= 21; | |
| 65 | 62 | end; | |
| 66 | 63 | ``` | |
| 67 | 64 | ||
| 68 | 65 | Let's set OnDrawItem to this (simply paint "itemNN"): | |
| 69 | 66 | ||
| 70 | 67 | ``` pascal | |
| 71 | 68 | procedure TfmMain.ListDraw(Sender: TObject; C: TCanvas; AIndex: integer; | |
| 72 | 69 | const ARect: TRect); | |
| 73 | 70 | begin | |
| 74 | 71 | C.Brush.Color:= IfThen(AIndex=b.ItemIndex, clMedGray, b.Color); | |
| 75 | 72 | C.FillRect(ARect); | |
| 76 | 73 | ||
| 77 | 74 | C.Pen.Color:= clMedGray; | |
| 78 | 75 | C.Line(ARect.Left+2, ARect.Bottom-1, ARect.Right-2, ARect.Bottom-1); | |
| 79 | 76 | ||
| 80 | 77 | C.TextOut(ARect.Left+6, ARect.Top+2, 'item '+inttostr(AIndex)); | |
| 81 | 78 | end; | |
| 82 | 79 | ``` | |
| 83 | 80 | ||
| 84 | 81 | --- | |
| 85 | 82 | *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 | 83 | Category: Components | |
| 87 | 84 | Category: Lazarus |
