Skip to content

Commit

Permalink
Add a few Tree methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pwiecz committed Oct 24, 2023
1 parent 93ef143 commit 286abae
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 7 deletions.
21 changes: 21 additions & 0 deletions tree.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ Fl_Tree_Item* go_fltk_Tree_add(Fl_Tree *tree, const char *path) {
return tree->add(path);
}

int go_fltk_Tree_remove(Fl_Tree *tree, Fl_Tree_Item *item) {
return tree->remove(item);
}

void go_fltk_Tree_clear(Fl_Tree *tree) {
tree->clear();
}

void go_fltk_Tree_clear_children(Fl_Tree *tree, Fl_Tree_Item *item) {
tree->clear_children(item);
}

void go_fltk_Tree_Item_set_widget(Fl_Tree_Item *item, Fl_Widget *widget) {
item->widget(widget);
}
Expand All @@ -41,3 +53,12 @@ const int go_FL_TREE_CONNECTOR_SOLID = (int)FL_TREE_CONNECTOR_SOLID;
void go_fltk_Tree_set_connector_style(Fl_Tree *tree, int style) {
tree->connectorstyle((Fl_Tree_Connector)style);
}

const int go_FL_TREE_SELECT_NONE = (int)FL_TREE_SELECT_NONE;
const int go_FL_TREE_SELECT_SINGLE = (int)FL_TREE_SELECT_SINGLE;
const int go_FL_TREE_SELECT_MULTI = (int)FL_TREE_SELECT_MULTI;
const int go_FL_TREE_SELECT_SINGLE_DRAGGABLE = (int)FL_TREE_SELECT_SINGLE_DRAGGABLE;

void go_fltk_Tree_set_select_mode(Fl_Tree *tree, int selectMode) {
tree->selectmode((Fl_Tree_Select)selectMode);
}
39 changes: 33 additions & 6 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,53 @@ func (t *Tree) Add(path string) TreeItem {
itemPtr := C.go_fltk_Tree_add((*C.Fl_Tree)(t.ptr()), pathStr)
return TreeItem{ptr: itemPtr}
}
func (t TreeItem) SetWidget(w *widget) {
C.go_fltk_Tree_Item_set_widget(t.ptr, w.ptr())
func (t *Tree) Remove(item TreeItem) bool {
return C.go_fltk_Tree_remove((*C.Fl_Tree)(t.ptr()), item.ptr) == 0
}
func (t *Tree) Clear() {
C.go_fltk_Tree_clear((*C.Fl_Tree)(t.ptr()))
}
func (t *Tree) ClearChildren(item TreeItem) {
C.go_fltk_Tree_clear_children((*C.Fl_Tree)(t.ptr()), item.ptr)
}

func (t TreeItem) SetWidget(w Widget) {
C.go_fltk_Tree_Item_set_widget(t.ptr, w.getWidget().ptr())
}

type TreeItemDrawMode uint

var (
TreeItemDrawDefault = TreeItemDrawMode(C.go_FL_TREE_ITEM_DRAW_DEFAULT)
TreeItemDrawDefault = TreeItemDrawMode(C.go_FL_TREE_ITEM_DRAW_DEFAULT)
TreeItemDrawLabelAndWidget = TreeItemDrawMode(C.go_FL_TREE_ITEM_DRAW_LABEL_AND_WIDGET)
TreeItemHeightFromWidget = TreeItemDrawMode(C.go_FL_TREE_ITEM_HEIGHT_FROM_WIDGET)
TreeItemHeightFromWidget = TreeItemDrawMode(C.go_FL_TREE_ITEM_HEIGHT_FROM_WIDGET)
)

func (t *Tree) SetItemDrawMode(drawMode TreeItemDrawMode) {
C.go_fltk_Tree_set_item_draw_mode((*C.Fl_Tree)(t.ptr()), C.uint(drawMode))
}

type TreeConnector int

var (
TreeConnectorNone = TreeConnector(C.go_FL_TREE_CONNECTOR_NONE)
TreeConnectorNone = TreeConnector(C.go_FL_TREE_CONNECTOR_NONE)
TreeConnectorDotted = TreeConnector(C.go_FL_TREE_CONNECTOR_DOTTED)
TreeConnectorSolid = TreeConnector(C.go_FL_TREE_CONNECTOR_SOLID)
TreeConnectorSolid = TreeConnector(C.go_FL_TREE_CONNECTOR_SOLID)
)

func (t *Tree) SetConnectorStyle(style TreeConnector) {
C.go_fltk_Tree_set_connector_style((*C.Fl_Tree)(t.ptr()), C.int(style))
}

type TreeSelect int

var (
TreeSelectNone = TreeSelect(C.go_FL_TREE_SELECT_NONE)
TreeSelectSingle = TreeSelect(C.go_FL_TREE_SELECT_SINGLE)
TreeSelectMulti = TreeSelect(C.go_FL_TREE_SELECT_MULTI)
TreeSelectSingleDraggable = TreeSelect(C.go_FL_TREE_SELECT_SINGLE_DRAGGABLE)
)

func (t *Tree) SetSelectMode(selectMode TreeSelect) {
C.go_fltk_Tree_set_select_mode((*C.Fl_Tree)(t.ptr()), C.int(selectMode))
}
11 changes: 10 additions & 1 deletion tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ extern "C" {

extern void go_fltk_Tree_set_show_root(Fl_Tree* tree, int show);
extern Fl_Tree_Item* go_fltk_Tree_add(Fl_Tree* tree, const char* path);
extern int go_fltk_Tree_remove(Fl_Tree *tree, Fl_Tree_Item *item);
extern void go_fltk_Tree_clear(Fl_Tree *tree);
extern void go_fltk_Tree_clear_children(Fl_Tree* tree, Fl_Tree_Item* item);

extern void go_fltk_Tree_Item_set_widget(Fl_Tree_Item* item, Fl_Widget* widget);

Expand All @@ -24,7 +27,13 @@ extern "C" {
extern const int go_FL_TREE_CONNECTOR_NONE;
extern const int go_FL_TREE_CONNECTOR_DOTTED;
extern const int go_FL_TREE_CONNECTOR_SOLID;
extern void go_fltk_Tree_set_connector_style(Fl_Tree* tree, int style);
extern void go_fltk_Tree_set_connector_style(Fl_Tree *tree, int style);

extern const int go_FL_TREE_SELECT_NONE;
extern const int go_FL_TREE_SELECT_SINGLE;
extern const int go_FL_TREE_SELECT_MULTI;
extern const int go_FL_TREE_SELECT_SINGLE_DRAGGABLE;
extern void go_fltk_Tree_set_select_mode(Fl_Tree* tree, int selectMode);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 286abae

Please sign in to comment.