How to define that node of TVirtualStringTree is presented on screen?
Asked Answered
P

1

5

It's easy to check that node is visible. But I don't know how to rightly define that node is presented on screen. I can find out only so:

BottomNode := Tree.BottomNode;
Node := Tree.TopNode;

IdBottomNode := Tree.AbsoluteIndex(BottomNode);

while Tree.AbsoluteIndex(Node) <> IdBottomNode do
begin
  Node := Node.NextSibling;
  if not Assigned(Node) then
    Break;
end;

(code without checking)

But I think it is rather rough way. May be is there more accurate way?

Patino answered 10/3, 2014 at 10:27 Comment(0)
D
14

You may write a function like follows. The Tree parameter there specifies the virtual tree, the Node is the node for which you want to check if it's visible, and the Column optional parameter is the index of a column if you would need to determine whether the node and even column is visible in client rect:

function IsNodeVisibleInClientRect(Tree: TBaseVirtualTree; Node: PVirtualNode;
  Column: TColumnIndex = NoColumn): Boolean;
begin
  Result := Tree.IsVisible[Node] and
    Tree.GetDisplayRect(Node, Column, False).IntersectsWith(Tree.ClientRect);
end;

But maybe there's a more straightforward way...

Dianthus answered 10/3, 2014 at 10:59 Comment(2)
Thank you! Now it is the best way.Patino
You're welcome! I've made a small change. You don't need to have any column in header. But as I said, maybe there's some ready made way for this.Dianthus

© 2022 - 2024 — McMap. All rights reserved.