Difference between revisions of "ATListbox"

From Free Pascal wiki
Jump to navigationJump to search
(Props)
(sections moving)
Line 9: Line 9:
 
[[File:atlistbox.png]]
 
[[File:atlistbox.png]]
  
= Properties =
+
= Download =
  
* ItemCount
+
Homepage at github: https://github.com/Alexey-T/ATButtons
* ItemIndex (index of active item)
 
* ItemTop (index of item visible at the top)
 
* ItemHeight (height in pixels of each item)
 
* VisibleItems (count of items fully visible inside control)
 
* OnClick
 
* OnDrawItem
 
  
 
= License =
 
= License =
  
 
MPL 2.0 or LGPL.
 
MPL 2.0 or LGPL.
 
= Download =
 
 
Homepage at github is at https://github.com/Alexey-T/ATButtons
 
  
 
= Requirements =
 
= Requirements =
Line 32: Line 22:
  
 
Tested on: Linux gtk2 (Ubuntu 14.04), Win32 (Win7), QT.
 
Tested on: Linux gtk2 (Ubuntu 14.04), Win32 (Win7), QT.
 +
 +
= Properties =
 +
 +
* ItemCount
 +
* ItemIndex (index of active item)
 +
* ItemTop (index of item visible at the top)
 +
* ItemHeight (height in pixels of each item)
 +
* VisibleItems (count of items fully visible inside control)
 +
* OnDrawItem
 +
* OnClick
  
 
= Example =
 
= Example =

Revision as of 12:18, 2 August 2015

About

ATListbox is OS-independant listbox control. It's made for list like Sublime Text's command list, it cannot be focused, it doesn't handle keyboard. Fully owner-drawn: you must not set captions, but must add OnDrawItem event, and set ItemCount.

Author: Alexey Torgashin.

Screenshot:

atlistbox.png

Download

Homepage at github: https://github.com/Alexey-T/ATButtons

License

MPL 2.0 or LGPL.

Requirements

Lazarus: 1.4.0.

Tested on: Linux gtk2 (Ubuntu 14.04), Win32 (Win7), QT.

Properties

  • ItemCount
  • ItemIndex (index of active item)
  • ItemTop (index of item visible at the top)
  • ItemHeight (height in pixels of each item)
  • VisibleItems (count of items fully visible inside control)
  • OnDrawItem
  • OnClick

Example

Let's create list:

var
  b: TATListbox;

procedure TfmMain.FormCreate(Sender: TObject);
begin
  b:= TATListbox.Create(Self);
  b.Parent:= Self;
  b.Align:= alClient;

  b.OnDrawItem:= @ListDraw;
  b.OnClick:= @ListClick;

  b.Color:= $e0e0e0;
  b.ItemCount:= 21;
end;

Let's set OnDrawItem to this (simply paint "itemNN"):

procedure TfmMain.ListDraw(Sender: TObject; C: TCanvas; AIndex: integer;
  const ARect: TRect);
begin
  C.Brush.Color:= IfThen(AIndex=b.ItemIndex, clMedGray, b.Color);
  C.FillRect(ARect);

  C.Pen.Color:= clMedGray;
  C.Line(ARect.Left+2, ARect.Bottom-1, ARect.Right-2, ARect.Bottom-1);

  C.TextOut(ARect.Left+6, ARect.Top+2, 'item '+inttostr(AIndex));
end;

Then need to add OnKeyDown event to form, which handles Up/Down/Home/End keys: just change "b.ItemIndex". Example of this event is in demo.