class Iup::Tree
A tree displays a hierarchy of branch and leaf nodes. Each node may display some text and an optional image.
Example
tree = Iup::Tree.new dlg = Iup::Dialog.new(tree) do |d| d.title = 'Tree Example' end.map tree.size = '80x80' tree.font = 'Courier, Normal 10' tree.addbranch(0, '3D') tree.addbranch(0, '2D') tree.addleaf(1, 'trapeze') tree.addbranch(1, 'parallelogram') tree.addleaf(2, 'diamond') tree.addleaf(2, 'square') tree.addbranch(4, 'triangle') tree.addleaf(5, 'scalenus') tree.addleaf(5, 'isoceles') tree.addleaf(5, 'equilateral') tree.value = 6 tree.addexpanded = 'no' dlg.show
Note: the contents of the tree can only be created after its containing dialog has been mapped.
Attributes
âyesâ / ânoâ, to expand branches when created.
âyesâ / ânoâ, automatically adds an empty branch as the first node, on creation.
Enables the control to gain focus. Values âyesâ / ânoâ.
Returns total number of nodes in the tree.
Determines if tree supports dragdrop operations. Values âyesâ / ânoâ.
âyesâ / ânoâ, if set, allows a drop node to equal drag node.
Allows control to fill available space in indicated direction. Values ânoâ / âhorizontalâ / âverticalâ / âyesâ.
Expands or contracts all nodes, values âyesâ / ânoâ.
âyesâ / ânoâ, the lines connecting nodes in hierarchy.
Image to be used for all collapsed branches. This can use an actual image object, or the name of an image from IupImageLib.
Image to be used for all expanded branches. This can use an actual image object, or the name of an image from IupImageLib.
Image to be used for all leaf nodes. This can use an actual image object, or the name of an image from IupImageLib.
level of indentation in pixels, defaults to 5.
selects a range of nodes: âstart-endâ / âINVERTidâ / âblockâ / âclearallâ / âmarkallâ / âinvertallâ
Sets/gets selection indices of all marked nodes, when markmode=multiple.
âsingleâ / âmultipleâ, for selection of nodes.
Initial node for block marking, used when mark=block.
returns position in pixels within client window as âx,yâ.
Size of the control, in pixels, value as âwidthxheightâ.
returns position in pixels on screen as âx,yâ.
âyesâ / ânoâ, enables internal drag and drop of nodes.
âyesâ / ânoâ / â3stateâ, enables use of toggles for all nodes of the tree.
vertical, internal padding for each node, defaults to 3 pixels.
Positions given node id at the top of tree, or near, to make it visible.
When retrieved, returns the identifier of the focussed node. When given a value, moves focus appropriately: ârootâ / âlastâ / ânextâ / âpreviousâ / âpgdnâ / âpgupâ
Public Class Methods
Public Instance Methods
Source
# File lib/wrapped/tree.rb, line 407 def addbranch id, val IupLib.IupSetAttribute @handle, "ADDBRANCH#{id}", val.to_s end
Adds new branch after specified node.
-
id- identifier of a node -
val- text label
Source
# File lib/wrapped/tree.rb, line 414 def addleaf id, val IupLib.IupSetAttribute @handle, "ADDLEAF#{id}", val.to_s end
Adds new leaf after specified node.
-
id- identifier of a node -
val- text label
Source
# File lib/wrapped/tree.rb, line 147 def childcount id IupLib.IupGetAttribute(@handle, "CHILDCOUNT#{id}").first end
Returns the number of immediate child of given node.
-
id- identifier of a node
Source
# File lib/wrapped/tree.rb, line 158 def color id, val=nil if val.nil? IupLib.IupGetAttribute(@handle, "COLOR#{id}").first else IupLib.IupSetAttribute @handle, "COLOR#{id}", val end end
Accesses text foreground color:
-
id- identifier of a node -
val- âr g bâ color
Source
# File lib/wrapped/tree.rb, line 421 def copynode source_id, target_id IupLib.IupSetAttribute @handle, "COPYNODE#{id}", target_id.to_s end
Copies source node and its children to target.
-
source_id- identifier of a node -
target_id- identifier of a node
Source
# File lib/wrapped/tree.rb, line 432 def delnode id, val IupLib.IupSetAttribute @handle, "DELNODE#{id}", val.to_s end
Delete one or more nodes:
-
id- identifier of a node -
val- one of-
âallâ: ignores id and deletes all nodes in tree, including root.
-
âselectedâ: deletes selected node and its children.
-
âchildrenâ: deleted only the children of selected node.
-
âmarkedâ: ignores id and deletes all selected node.
-
Source
# File lib/wrapped/tree.rb, line 168 def depth id IupLib.IupGetAttribute(@handle, "DEPTH#{id}").first end
Returns the depth of the given node.
-
id- identifier of a node
Source
# File lib/wrapped/tree.rb, line 285 def image id, img attribute_reference "IMAGE#{id}", ImageWidget, img end
Sets image to use for given node.
-
id- identifier of a node -
img- image name or reference. This can use an actual image object, or the name of an image fromIupImageLib.
Source
# File lib/wrapped/tree.rb, line 292 def imageexpanded id, img attribute_reference "IMAGEEXPANDED#{id}", ImageWidget, img end
Sets image to use for given node, for expanded branches.
-
id- identifier of a node -
img- image name or reference. This can use an actual image object, or the name of an image fromIupImageLib.
Source
# File lib/wrapped/tree.rb, line 444 def insertbranch id, val IupLib.IupSetAttribute @handle, "INSERTBRANCH#{id}", val.to_s end
Inserts new branch after specified node, preserving depth.
-
id- identifier of a node -
val- text label
Source
# File lib/wrapped/tree.rb, line 451 def insertleaf id, val IupLib.IupSetAttribute @handle, "INSERTLEAF#{id}", val.to_s end
Inserts new leaf after specified node, preserving depth.
-
id- identifier of a node -
val- text label
Source
# File lib/wrapped/tree.rb, line 174 def kind id IupLib.IupGetAttribute(@handle, "KIND#{id}").first end
Returns kind of given node, as âleafâ or âbranchâ.
-
id- identifier of a node
Source
# File lib/wrapped/tree.rb, line 356 def marked id, val=nil if val.nil? IupLib.IupGetAttribute(@handle, "MARKED#{id}").first else IupLib.IupSetAttribute @handle, "MARKED#{id}", val end end
Accesses marked state of node:
-
id- identity of node -
val- âyesâ / ânoâ
Source
# File lib/wrapped/tree.rb, line 458 def movenode source_id, target_id IupLib.IupSetAttribute @handle, "MOVENODE#{id}", target_id.to_s end
Moves source to target, as a new child or sibling.
-
source_id- identifier of a node -
target_id- identifier of a node
Source
# File lib/wrapped/tree.rb, line 180 def parent id IupLib.IupGetAttribute(@handle, "PARENT#{id}").first end
Returns identifier of parent of given node.
-
id- identifier of a node
Source
# File lib/wrapped/tree.rb, line 191 def state id, val=nil if val.nil? IupLib.IupGetAttribute(@handle, "STATE#{id}").first else IupLib.IupSetAttribute @handle, "STATE#{id}", val end end
Accesses state as âcollapsedâ or âexpandedâ:
-
id- identifier of a node -
val- value âcollapsedâ or âexpandedâ.
Source
# File lib/wrapped/tree.rb, line 206 def title id, val=nil if val.nil? IupLib.IupGetAttribute(@handle, "TITLE#{id}").first else IupLib.IupSetAttribute @handle, "TITLE#{id}", val end end
Accesses title of given node:
-
id- identifier of a node -
val- title.
Source
# File lib/wrapped/tree.rb, line 221 def titlefont id, val=nil if val.nil? IupLib.IupGetAttribute(@handle, "TITLEFONT#{id}").first else IupLib.IupSetAttribute @handle, "TITLEFONT#{id}", val end end
Accesses font of node title:
-
id- identifier of a node -
val- font description.
Source
# File lib/wrapped/tree.rb, line 236 def togglevalue id, val=nil if val.nil? IupLib.IupGetAttribute(@handle, "TOGGLEVALUE#{id}").first else IupLib.IupSetAttribute @handle, "TOGGLEVALUE#{id}", val end end
Accesses toggle state of given node:
-
id- identifier of a node -
val- state as âonâ / âoffâ / ânotdefâ
Source
# File lib/wrapped/tree.rb, line 251 def togglevisible id, val=nil if val.nil? IupLib.IupGetAttribute(@handle, "TOGGLEVISIBLE#{id}").first else IupLib.IupSetAttribute @handle, "TOGGLEVISIBLE#{id}", val end end
Accesses toggle visibility of given node:
-
id- identifier of a node -
val- visibility as âyesâ / ânoâ.
Source
# File lib/wrapped/tree.rb, line 261 def totalchildcount id IupLib.IupGetAttribute(@handle, "TOTALCHILDCOUNT#{id}").first end
Returns total number of children for given node.
-
id- identifier of a node
Source
# File lib/wrapped/tree.rb, line 272 def userdata id, val=nil if val.nil? IupLib.IupGetAttribute(@handle, "USERDATA#{id}").first else IupLib.IupSetAttribute @handle, "USERDATA#{id}", val end end
Accesses userdata for given node id.
-
id- identifier of a node -
val- user data (a string)
Callbacks
Attributes
Callback called when a branch is collapsed. Callback must respond to call and takes 1 argument: (node_id)
-
node_id- reference to node closed
Callback called when a branch is expanded. Callback must respond to call and takes 1 argument: (node_id)
-
node_id- reference to node opened
Callback called when an internal drag & drop is executed. Only active if SHOWDRAGDROP=YES. Callback must respond to call and accepts 4 arguments (drag_id, drop_id, isshift, iscontrol)
-
drag_id- is an integer index of dragged item -
drop_id- is an integer index of drop location -
isshift- boolean flag for if shift key held -
iscontrol- boolean flag for if control key held
Callback should return Iup::CONTINUE for item to be moved/copied.
Callback called when a leaf is to be executed. Callback must respond to call and takes 1 argument: (node_id)
-
node_id- reference to node
Callback called when the mouse is moved. Callback must respond to call and takes 3 arguments: (x, y, state)
-
x- x position of mouse -
y- y position of mouse -
state- status of mouse buttons and certain keyboard keys at the moment the event was generated.
Callback called when the right mouse button is pressed over a node. Callback must respond to call and takes 1 argument: (node_id)
-
node_id- reference to node
Callback called when a node is selected or deselected. Callback must respond to call and takes 2 arguments: (node_id, status)
-
node_id- reference to node -
status- whether node is selected or deselected
Callback called when the toggleâs state was changed. Callback must respond to call and takes 2 arguments: (node_id, status).
-
node_id- reference to node -
status- new state of toggle