Is it generally possible, to view a custom component inside a node or in the drawing rect of a nodes column?
Creating a custom component in memory, and then copy its canvas to the rect of the node is possible, using the OnAfterDrawNodeText, but that's just a workaround for me.
We do have several graphical representations of data, encapsulated in components. Now I want to embed this stuff into a tree view. Issue here, it's not just plain graphic, it allows some interaction.
So ideally I want that the node becomes the objects parent, and that the component directly renders inside that node.
Do you see any possibility to do that?
Unfortunately this is not possible. The treeview does not allow controls to be rendered inside a node. The non-interactive graphical way is currently the only way to achieve this.
I managed to get the controls into the nodes, by adding a TLayout which position and size gets updated by the GetContentClipRect. Then the TLayout acts as a global parent for the controls.Needed to do that for proper clipping. The control object pointers are referenced trough the node.dataobject. The objects position, size and visibility I adapt in the OnDrawNode by getting the node rect with:
function TObjectTree.GetVirtualNodeRect(node:TTMSFNCTreeViewVirtualNode;var Rect:TRectF):boolean;
var
i:integer;
dsp: TTMSFNCTreeViewCacheItem;
crect:TRectF;
begin
result:=false;
if not Assigned(FNodeDisplay) then
Exit;
for i := 0 to FNodeDisplay.Count - 1 do
begin
dsp := FNodeDisplay[I];
if dsp.Node=node then
begin
rect:=dsp.DrawRect;
crect:=GetContentClipRect;
rect.Top:=rect.Top-crect.Top;
rect.Bottom:=rect.Bottom-crect.Top;
result:=true;
break;
end;
end;
end;
In the OnBeforeDraw of the treeview, I set all child controls of the TLayer invisible.
If now a node has a object of type TControl assigned, it will show two little red buttons (SHOW,HIDE), to change the height of the node, to view or hide the control.
This solution is a bit of a workaround, but yeah...
(My other question / suggestion about the getting the TRect of the node I posted in another thread, was also necessary for that little project)
I wrapped all the new functions in a descendent class, only change in the main code was moving FNodeDisplay to the protected section (from private)....