rkt-tree-widget
1 Tree Widget
tree-widget%
new
get-root
set-root
append-item
prepend-item
insert-item
update-item
delete-item
expand-item
reset-items
on-positions-changed
paint-item
compute-item-size
locate-item
make-indices-cursor
2 Tree mixin
tree<%>
get-root
set-root
compute-item-size
on-positions-changed
tree-mixin
3 Functional Updating
tree-updater%
new
append-item
prepend-item
insert-item
update-item
delete-item
expand-item
update-children
set-tree
empty-tree
4 Cursor Operations
root-cursor?
node-cursor?
cursor?
indices-cursor?
generic-cursor?
cursor-up
cursor-equal?
cursor-valid?
cursor-children
cursor-children-cursor
cursor-children-count
cursor-get-child
node-cursor-item-size
node-cursor-value
node-cursor-expand?
node-cursor-pos
node-cursor-children-indent
root-cursor-total-size
root-cursor-locate-item
root-cursor-get-visible-items
5 rkt-tree-widget/  base
8.2

rkt-tree-widget

yjqww6

 (require rkt-tree-widget) package: rkt-tree-widget

Yet another tree widget for Racket. It uses functional cursors to represent the nodes of the tree.

1 Tree Widget

class

tree-widget% : class?

  superclass: canvas%

  extends: tree<%>
A canvas%-based tree widget.

constructor

(new tree-widget% 
    [[wheel-step wheel-step]] 
    ...superclass-args...) 
  (is-a?/c tree-widget%)
  wheel-step : exact-positive-integer? = 3
The wheel-step argument controls the speed of scrolling.

method

(send a-tree-widget get-root)  root-cursor?

Returns a cursor representing the root of the tree.

method

(send a-tree-widget set-root c)  void?

  c : root-cursor?
Set the root of the tree.

method

(send a-tree-widget append-item c v [expand?])  void?

  c : generic-cursor?
  v : any/c
  expand? : boolean? = #f
Appends an item v to the children of c. All the cursors acquired previously will be invalidated.

method

(send a-tree-widget prepend-item c    
  v    
  [expand?])  void?
  c : generic-cursor?
  v : any/c
  expand? : boolean? = #f
Prepends an item v to the children of c. All the cursors acquired previously will be invalidated.

method

(send a-tree-widget insert-item c    
  i    
  v    
  [expand?])  void?
  c : generic-cursor?
  i : exact-nonnegative-integer?
  v : any/c
  expand? : boolean? = #f
Inserts an item v as the ith child of c. All the cursors acquired previously will be invalidated.

method

(send a-tree-widget update-item c i v)  void?

  c : generic-cursor?
  i : exact-nonnegative-integer?
  v : any/c
Updates the ith child of c to v. All the cursors acquired previously will be invalidated.

method

(send a-tree-widget delete-item c i)  void?

  c : generic-cursor?
  i : exact-nonnegative-integer?
Deletes the ith child of c. All the cursors acquired previously will be invalidated.

method

(send a-tree-widget expand-item c expand?)  void?

  c : generic-cursor?
  expand? : boolean?
Changes the expanding status of c to expand?. All the cursors acquired previously will be invalidated.

method

(send a-tree-widget reset-items)  void

Resets the tree to empty. All the cursors acquired previously will be invalidated.

method

(send a-tree-widget on-positions-changed)  void?

Called after the tree is modified.

Default Implementation: Calls refresh.

method

(send a-tree-widget paint-item c v x y)  void?

  c : node-cursor?
  v : any/c
  x : exact-nonnegative-integer?
  y : exact-nonnegative-integer?
Paints the item v represented by cursor c at specific dc location.

Computes the width, height and children indentation of item v.

Default Implementation: Returns (values 1 1 0).

method

(send a-tree-widget locate-item x y)  (or/c #f node-cursor?)

  x : (or/c #f exact-nonnegative-integer?)
  y : exact-nonnegative-integer?
Finds out the item at specific location (dc coordinates). If x is #f, only y is considered.

method

(send a-tree-widget make-indices-cursor indices)

  indices-cursor?
  indices : (non-empty-listof exact-nonnegative-integer?)
Constructs an cursor from indices, which should be only used to modify the tree immediately. Equivalent to
(for/fold ([t (send this get-root)])
          ([i (in-list indices)])
  (cursor-get-child t i))
when used to modify the tree.

2 Tree mixin

interface

tree<%> : interface?

method

(send a-tree get-root)  root-cursor?

Returns a cursor representing the root of the tree.

method

(send a-tree set-root c)  void?

  c : root-cursor?
Set the root of the tree.

Computes the width, height and children indentation of item v.

method

(send a-tree on-positions-changed)  void?

Called after the tree is modified.

mixin

tree-mixin : (class? . -> . class?)

  result implements: tree<%>

3 Functional Updating

class

tree-updater% : class?

  superclass: object%

tree-updater% is used to building and updating tree-widget% functionally.

constructor

(new tree-updater% [tree tree])  (is-a?/c tree-updater%)

  tree : (instanceof/c (implementation?/c tree<%>))
Constructs a tree-updater% associated with tree.

method

(send a-tree-updater append-item t    
  v    
  [expand?    
  children])  root-cursor?
  t : generic-cursor?
  v : any/c
  expand? : boolean? = #f
  children : (or/c #f cursor?) = #f

method

(send a-tree-updater prepend-item t    
  v    
  [expand?    
  children])  root-cursor?
  t : generic-cursor?
  v : any/c
  expand? : boolean? = #f
  children : (or/c #f cursor?) = #f

method

(send a-tree-updater insert-item t    
  i    
  v    
  [expand?    
  children])  root-cursor?
  t : generic-cursor?
  i : exact-nonnegative-integer?
  v : any/c
  expand? : boolean? = #f
  children : (or/c #f cursor?) = #f

method

(send a-tree-updater update-item t i v)  root-cursor?

  t : generic-cursor?
  i : exact-nonnegative-integer?
  v : any/c

method

(send a-tree-updater delete-item t i)  root-cursor?

  t : generic-cursor?
  i : exact-nonnegative-integer?

method

(send a-tree-updater expand-item t expand?)  root-cursor?

  t : generic-cursor?
  expand? : boolean?

method

(send a-tree-updater update-children t f)  root-cursor?

  t : generic-cursor?
  f : (-> root-cursor? root-cursor?)

method

(send a-tree-updater set-tree tree)  void?

  tree : root-cursor?
Set the root of associated tree<%> to tree.

method

(send a-tree-updater empty-tree)  root-cursor?

4 Cursor Operations

procedure

(root-cursor? v)  boolean?

  v : any/c
Returns #t if v is a root cursor, otherwise #f. A root cursor represents the root of a tree.

procedure

(node-cursor? v)  boolean?

  v : any/c
Returns #t if v is a node cursor, otherwise #f. A node cursor represents an internal node of a tree.

procedure

(cursor? v)  boolean?

  v : any/c
Returns #t if either (root-cursor? v) or (node-cursor? v) return #t, otherwise #f.

procedure

(indices-cursor? v)  boolean?

  v : any/c
Returns #t if v is a indices cursor, otherwise #f. See also make-indices-cursor.

procedure

(generic-cursor? v)  boolean?

  v : any/c
Returns #t if either (cursor? v) or (indices-cursor? v) return #t, otherwise #f.

procedure

(cursor-up c)  cursor?

  c : cursor?
Returns a cursor representing the parent node of c. If c is a root cursor, returns itself.

procedure

(cursor-equal? a b)  boolean?

  a : cursor?
  b : cursor?
Returns #t if a and b represent same node (or same root), otherwise #f.

procedure

(cursor-valid? t c)  boolean?

  t : root-cursor?
  c : cursor?
Returns #t if t is the root of c, otherwise #f.

procedure

(cursor-children c)  (listof node-cursor?)

  c : cursor?
Returns the children of c.

procedure

(cursor-children-cursor c)  root-cursor?

  c : cursor?
Similar to cursor-children, but returns a root cursor instead.
Returns the the number of children of c.

procedure

(cursor-get-child c i)  node-cursor?

  c : cursor?
  i : exact-nonnegative-integer?
Returns the ith child of c.
Returns the width and height of the item of c.

procedure

(node-cursor-value c)  any/c

  c : node-cursor?
Returns the item value of c.

procedure

(node-cursor-expand? c)  boolean?

  c : node-cursor?
Returns #t if c is expanded, otherwise #f.
Returns the position of c in its parent.
Returns the chilren indentation of c.
Returns the total size required by c.

procedure

(root-cursor-locate-item c x y)  (or/c #f node-cursor?)

  c : root-cursor?
  x : (or/c #f exact-nonnegative-integer?)
  y : exact-nonnegative-integer?
Similar to locate-item, but x and y are relative to c.
Returns a list of visible items (flattened) in [y-start, y-end) (relative to c). Vectors in that list consist of the cursor, the y location, and the value of correspoding node.

5 rkt-tree-widget/base

rkt-tree-widget/base provides all the exports provided from rkt-tree-widget, except tree-widget%. It doesn’t depend on racket/gui.