Struct Tree

Source
pub struct Tree { /* private fields */ }
Expand description

Defines a tree widget

Implementations§

Source§

impl Tree

Source

pub fn new<'a, T: Into<Option<&'a str>>>( x: i32, y: i32, width: i32, height: i32, title: T, ) -> Tree

Creates a new widget, takes an x, y coordinates, as well as a width and height, plus a title

§Arguments
  • x - The x coordinate in the screen
  • y - The y coordinate in the screen
  • width - The width of the widget
  • heigth - The height of the widget
  • title - The title or label of the widget

To use dynamic strings use with_label(self, &str) or set_label(&mut self, &str). labels support special symbols preceded by an @ sign and for the associated formatting.

Examples found in repository?
examples/tree.rs (line 46)
45    fn new(x: i32, y: i32, width: i32, height: i32, title: &'static str) -> Self {
46        let mut t_widget = Tree::new(x, y, width, height, title);
47        let previous_focus = Rc::new(RefCell::new(None::<TreeItem>));
48        let pfr = Rc::clone(&previous_focus);
49        t_widget.set_callback_reason(TreeReason::Selected);
50        t_widget.set_callback(|_t| println!("clicked an item"));
51        t_widget.handle(move |t, e| match e {
52            Event::Move => {
53                let (_, mouse_y) = app::event_coords();
54                let mut state = State::Undefined;
55                let mut pf = pfr.borrow_mut();
56                loop {
57                    match &*pf {
58                        Some(item) => {
59                            let item_y = item.y();
60                            match state {
61                                State::MovingUp => {
62                                    if verify_open_till_root(&pf) {
63                                        if mouse_y < item_y {
64                                            *pf = pf.as_ref().unwrap().prev();
65                                            continue;
66                                        };
67                                        break;
68                                    } else {
69                                        *pf = pf.as_ref().unwrap().prev();
70                                        continue;
71                                    }
72                                }
73                                State::MovingDown => {
74                                    if verify_open_till_root(&pf) {
75                                        if mouse_y > item_y + item.h() {
76                                            *pf = pf.as_ref().unwrap().next();
77                                            continue;
78                                        };
79                                        break;
80                                    } else {
81                                        *pf = pf.as_ref().unwrap().next();
82                                        continue;
83                                    }
84                                }
85                                State::Undefined => {
86                                    if mouse_y < item_y {
87                                        *pf = pf.as_ref().unwrap().prev();
88                                        state = State::MovingUp;
89                                        continue;
90                                    };
91                                    if mouse_y > item_y + item.h() {
92                                        *pf = pf.as_ref().unwrap().next();
93                                        state = State::MovingDown;
94                                        continue;
95                                    };
96                                    return true; // If in same range, don't update 'previous_focus'
97                                }
98                            }
99                        }
100                        // End up here if y is outside tree boundaries, or no tree item is present
101                        None => match &state {
102                            State::MovingUp | State::MovingDown => return true,
103                            State::Undefined => {
104                                *pf = t.first();
105                                state = State::MovingDown;
106                                if pf.is_none() {
107                                    return true;
108                                }
109                                continue;
110                            }
111                        },
112                    };
113                }
114                if verify_open_till_root(&pf) {
115                    t.take_focus().ok();
116                    t.set_item_focus(pf.as_ref().unwrap());
117                    println!("Set focus to item: {:?}", pf.as_ref().unwrap().label());
118                }
119                true
120            }
121            _ => false,
122        });
123        Self {
124            t_widget,
125            previous_focus,
126        }
127    }
128
129    fn add(&mut self, path: &str) -> Option<TreeItem> {
130        self.t_widget.add(path)
131    }
132
133    /// Caution, variable 'previous focus' must be set to None, as it
134    /// otherwise could try to refer to an already freed memory location,
135    /// when this TreeItem is removed.
136    fn remove(&mut self, item: &TreeItem) -> Result<(), FltkError> {
137        *self.previous_focus.borrow_mut() = None;
138        self.t_widget.remove(item)
139    }
140
141    fn get_items(&self) -> Option<Vec<TreeItem>> {
142        self.t_widget.get_items()
143    }
144}
145
146fn main() {
147    let path = env::current_dir().unwrap();
148    let path: String = path
149        .to_str()
150        .unwrap()
151        .chars()
152        .map(|c| match c {
153            '\\' => '/', // change window paths to posix paths
154            _ => c,
155        })
156        .collect();
157
158    let app = app::App::default().with_scheme(app::Scheme::Gtk);
159    let mut wind = Window::default().with_size(400, 300);
160    let mut but = Button::new(260, 255, 80, 40, "Get Items");
161    let _frame = Frame::new(20, 255, 160, 40, "Focus follow mouse");
162    let mut tree = TreeMouseFocus::new(5, 10, 190, 240, "");
163    tree.add(&path);
164
165    let mut items = tree.get_items().unwrap();
166    items.as_mut_slice()[0].set_label("/");
167
168    let mut tree2 = Tree::new(205, 10, 190, 240, "");
169    tree2.set_select_mode(TreeSelect::Multi);
170    tree2.add("First");
171    tree2.add("First/1st");
172    tree2.add("First/2nd/3rd");
173    tree2.add("Second");
174    tree2.add("Third");
175
176    tree2.set_when(fltk::enums::When::ReleaseAlways);
177
178    wind.make_resizable(true);
179    wind.show();
180
181    but.set_callback({
182        let tree2 = tree2.clone();
183        move |_| match tree2.get_selected_items() {
184            None => println!("No items selected"),
185            Some(vals) => print!(
186                "In total {} items selected:\n{}",
187                vals.len(),
188                vals.iter()
189                    .map(|i| tree2.item_pathname(i).unwrap() + "\n")
190                    .collect::<String>()
191            ),
192        }
193    });
194
195    app.run().unwrap();
196}
Source

pub fn default_fill() -> Self

Constructs a widget with the size of its parent

Source§

impl Tree

Source

pub unsafe fn from_raw(ptr: *mut Fl_Tree) -> Option<Tree>

Creates a Tree from a raw Fl_Tree pointer

§Safety

The pointer must be valid

Source

pub fn begin(&self)

Begins the Tree widget

Source

pub fn end(&self)

Ends the Tree widget

Source

pub fn show_self(&mut self)

Shows the Tree widget

Source

pub fn set_root_label(&mut self, new_label: &str)

Sets the root label

Source

pub fn root(&self) -> Option<TreeItem>

Gets the Tree’s root

Source

pub fn set_root(&mut self, new_item: Option<TreeItem>)

Sets the Tree’s root

Source

pub fn add(&mut self, path: &str) -> Option<TreeItem>

Adds a TreeItem

Examples found in repository?
examples/tree.rs (line 130)
129    fn add(&mut self, path: &str) -> Option<TreeItem> {
130        self.t_widget.add(path)
131    }
132
133    /// Caution, variable 'previous focus' must be set to None, as it
134    /// otherwise could try to refer to an already freed memory location,
135    /// when this TreeItem is removed.
136    fn remove(&mut self, item: &TreeItem) -> Result<(), FltkError> {
137        *self.previous_focus.borrow_mut() = None;
138        self.t_widget.remove(item)
139    }
140
141    fn get_items(&self) -> Option<Vec<TreeItem>> {
142        self.t_widget.get_items()
143    }
144}
145
146fn main() {
147    let path = env::current_dir().unwrap();
148    let path: String = path
149        .to_str()
150        .unwrap()
151        .chars()
152        .map(|c| match c {
153            '\\' => '/', // change window paths to posix paths
154            _ => c,
155        })
156        .collect();
157
158    let app = app::App::default().with_scheme(app::Scheme::Gtk);
159    let mut wind = Window::default().with_size(400, 300);
160    let mut but = Button::new(260, 255, 80, 40, "Get Items");
161    let _frame = Frame::new(20, 255, 160, 40, "Focus follow mouse");
162    let mut tree = TreeMouseFocus::new(5, 10, 190, 240, "");
163    tree.add(&path);
164
165    let mut items = tree.get_items().unwrap();
166    items.as_mut_slice()[0].set_label("/");
167
168    let mut tree2 = Tree::new(205, 10, 190, 240, "");
169    tree2.set_select_mode(TreeSelect::Multi);
170    tree2.add("First");
171    tree2.add("First/1st");
172    tree2.add("First/2nd/3rd");
173    tree2.add("Second");
174    tree2.add("Third");
175
176    tree2.set_when(fltk::enums::When::ReleaseAlways);
177
178    wind.make_resizable(true);
179    wind.show();
180
181    but.set_callback({
182        let tree2 = tree2.clone();
183        move |_| match tree2.get_selected_items() {
184            None => println!("No items selected"),
185            Some(vals) => print!(
186                "In total {} items selected:\n{}",
187                vals.len(),
188                vals.iter()
189                    .map(|i| tree2.item_pathname(i).unwrap() + "\n")
190                    .collect::<String>()
191            ),
192        }
193    });
194
195    app.run().unwrap();
196}
Source

pub fn add_item(&mut self, path: &str, item: &TreeItem) -> Option<TreeItem>

Adds a TreeItem

Source

pub fn insert_above(&mut self, above: &TreeItem, name: &str) -> Option<TreeItem>

Inserts a TreeItem above another tree item

Source

pub fn insert( &mut self, item: &TreeItem, name: &str, pos: i32, ) -> Option<TreeItem>

Inserts a TreeItem at a position pos

Source

pub fn remove(&mut self, item: &TreeItem) -> Result<(), FltkError>

Removes a TreeItem

§Errors

Errors on failure to remove item

Examples found in repository?
examples/tree.rs (line 138)
136    fn remove(&mut self, item: &TreeItem) -> Result<(), FltkError> {
137        *self.previous_focus.borrow_mut() = None;
138        self.t_widget.remove(item)
139    }
Source

pub fn clear(&mut self)

Clears a tree

Source

pub fn clear_children(&mut self, item: &TreeItem)

Clears all children

Source

pub fn find_item(&self, path: &str) -> Option<TreeItem>

Finds a tree item

Source

pub fn find_clicked(&self, yonly: bool) -> Option<TreeItem>

finds a clicked item

Source

pub fn first(&self) -> Option<TreeItem>

Gets the first tree item

Examples found in repository?
examples/tree.rs (line 104)
45    fn new(x: i32, y: i32, width: i32, height: i32, title: &'static str) -> Self {
46        let mut t_widget = Tree::new(x, y, width, height, title);
47        let previous_focus = Rc::new(RefCell::new(None::<TreeItem>));
48        let pfr = Rc::clone(&previous_focus);
49        t_widget.set_callback_reason(TreeReason::Selected);
50        t_widget.set_callback(|_t| println!("clicked an item"));
51        t_widget.handle(move |t, e| match e {
52            Event::Move => {
53                let (_, mouse_y) = app::event_coords();
54                let mut state = State::Undefined;
55                let mut pf = pfr.borrow_mut();
56                loop {
57                    match &*pf {
58                        Some(item) => {
59                            let item_y = item.y();
60                            match state {
61                                State::MovingUp => {
62                                    if verify_open_till_root(&pf) {
63                                        if mouse_y < item_y {
64                                            *pf = pf.as_ref().unwrap().prev();
65                                            continue;
66                                        };
67                                        break;
68                                    } else {
69                                        *pf = pf.as_ref().unwrap().prev();
70                                        continue;
71                                    }
72                                }
73                                State::MovingDown => {
74                                    if verify_open_till_root(&pf) {
75                                        if mouse_y > item_y + item.h() {
76                                            *pf = pf.as_ref().unwrap().next();
77                                            continue;
78                                        };
79                                        break;
80                                    } else {
81                                        *pf = pf.as_ref().unwrap().next();
82                                        continue;
83                                    }
84                                }
85                                State::Undefined => {
86                                    if mouse_y < item_y {
87                                        *pf = pf.as_ref().unwrap().prev();
88                                        state = State::MovingUp;
89                                        continue;
90                                    };
91                                    if mouse_y > item_y + item.h() {
92                                        *pf = pf.as_ref().unwrap().next();
93                                        state = State::MovingDown;
94                                        continue;
95                                    };
96                                    return true; // If in same range, don't update 'previous_focus'
97                                }
98                            }
99                        }
100                        // End up here if y is outside tree boundaries, or no tree item is present
101                        None => match &state {
102                            State::MovingUp | State::MovingDown => return true,
103                            State::Undefined => {
104                                *pf = t.first();
105                                state = State::MovingDown;
106                                if pf.is_none() {
107                                    return true;
108                                }
109                                continue;
110                            }
111                        },
112                    };
113                }
114                if verify_open_till_root(&pf) {
115                    t.take_focus().ok();
116                    t.set_item_focus(pf.as_ref().unwrap());
117                    println!("Set focus to item: {:?}", pf.as_ref().unwrap().label());
118                }
119                true
120            }
121            _ => false,
122        });
123        Self {
124            t_widget,
125            previous_focus,
126        }
127    }
Source

pub fn first_visible_item(&self) -> Option<TreeItem>

Gets the first visible tree item

Source

pub fn next(&self, item: &TreeItem) -> Option<TreeItem>

Gets the next tree item

Source

pub fn prev(&self, item: &TreeItem) -> Option<TreeItem>

Gets the previous tree item

Source

pub fn last(&self) -> Option<TreeItem>

Gets the last tree item

Source

pub fn last_visible_item(&self) -> Option<TreeItem>

Gets the last visible tree item

Source

pub fn next_visible_item( &self, start: &TreeItem, direction_key: Key, ) -> Option<TreeItem>

Gets the next visible tree item

Source

pub fn first_selected_item(&self) -> Option<TreeItem>

Gets the first selected tree item

Source

pub fn last_selected_item(&self) -> Option<TreeItem>

Gets the last selected tree item

Source

pub fn next_item( &self, item: &TreeItem, direction_key: Key, visible: bool, ) -> Option<TreeItem>

Gets the next tree item, direction_key is by default Key::Down

Source

pub fn next_selected_item( &mut self, item: &TreeItem, direction_key: Key, ) -> Option<TreeItem>

Gets the next selected tree item, direction_key is by default Key::Down

Source

pub fn get_selected_items(&self) -> Option<Vec<TreeItem>>

Gets the selected tree items

Examples found in repository?
examples/tree.rs (line 183)
146fn main() {
147    let path = env::current_dir().unwrap();
148    let path: String = path
149        .to_str()
150        .unwrap()
151        .chars()
152        .map(|c| match c {
153            '\\' => '/', // change window paths to posix paths
154            _ => c,
155        })
156        .collect();
157
158    let app = app::App::default().with_scheme(app::Scheme::Gtk);
159    let mut wind = Window::default().with_size(400, 300);
160    let mut but = Button::new(260, 255, 80, 40, "Get Items");
161    let _frame = Frame::new(20, 255, 160, 40, "Focus follow mouse");
162    let mut tree = TreeMouseFocus::new(5, 10, 190, 240, "");
163    tree.add(&path);
164
165    let mut items = tree.get_items().unwrap();
166    items.as_mut_slice()[0].set_label("/");
167
168    let mut tree2 = Tree::new(205, 10, 190, 240, "");
169    tree2.set_select_mode(TreeSelect::Multi);
170    tree2.add("First");
171    tree2.add("First/1st");
172    tree2.add("First/2nd/3rd");
173    tree2.add("Second");
174    tree2.add("Third");
175
176    tree2.set_when(fltk::enums::When::ReleaseAlways);
177
178    wind.make_resizable(true);
179    wind.show();
180
181    but.set_callback({
182        let tree2 = tree2.clone();
183        move |_| match tree2.get_selected_items() {
184            None => println!("No items selected"),
185            Some(vals) => print!(
186                "In total {} items selected:\n{}",
187                vals.len(),
188                vals.iter()
189                    .map(|i| tree2.item_pathname(i).unwrap() + "\n")
190                    .collect::<String>()
191            ),
192        }
193    });
194
195    app.run().unwrap();
196}
Source

pub fn get_items(&self) -> Option<Vec<TreeItem>>

Gets the all tree items

Examples found in repository?
examples/tree.rs (line 142)
141    fn get_items(&self) -> Option<Vec<TreeItem>> {
142        self.t_widget.get_items()
143    }
Source

pub fn open(&mut self, path: &str, do_callback: bool) -> Result<(), FltkError>

Opens a tree item, causing the children to be shown

§Errors

Errors on failure to open an item

Source

pub fn open_toggle(&mut self, item: &TreeItem, do_callback: bool)

Toggle the open state

Source

pub fn close(&mut self, path: &str, do_callback: bool) -> Result<(), FltkError>

Close a tree item, causing the children to be hidden

§Errors

Errors on failure to close an item

Source

pub fn is_open(&self, path: &str) -> bool

Returns whether an item is open

Source

pub fn is_close(&self, path: &str) -> bool

Returns whether an item is closed

Source

pub fn select(&mut self, path: &str, do_callback: bool) -> Result<(), FltkError>

Select a tree item

§Errors

Errors on failure to select an item

Source

pub fn select_toggle(&mut self, item: &TreeItem, do_callback: bool)

Toggle the select state of the specified

Source

pub fn deselect( &mut self, path: &str, do_callback: bool, ) -> Result<(), FltkError>

Deselect an item at path and determine whether to do the callback

§Errors

Errors on failure to deselect item

Source

pub fn deselect_all( &mut self, item: &TreeItem, do_callback: bool, ) -> Result<(), FltkError>

Deselect all items

§Errors

Errors on failure to deselect all items

Source

pub fn select_only( &mut self, selected_item: &TreeItem, do_callback: bool, ) -> Result<(), FltkError>

Select only the specified item, deselecting all others that might be selected.

§Errors

Errors on failure to select an item

Source

pub fn select_all( &mut self, item: &TreeItem, do_callback: bool, ) -> Result<(), FltkError>

Select all items

§Errors

Errors on failure to select an item

Source

pub fn extend_selection_dir( &mut self, from: &TreeItem, to: &TreeItem, direction_key: Key, val: TreeItemSelect, visible: bool, ) -> Result<(), FltkError>

Extend the selection between and including from and to in a certain direction

§Errors

Errors on failure to extend selection in direction

Source

pub fn extend_selection( &mut self, from: &TreeItem, to: &TreeItem, val: TreeItemSelect, visible: bool, ) -> Result<(), FltkError>

Extend the selection between and including from and to

§Errors

Errors on failure to extend selection

Source

pub fn set_item_focus(&mut self, item: &TreeItem)

Set the item that currently should have keyboard focus

Examples found in repository?
examples/tree.rs (line 116)
45    fn new(x: i32, y: i32, width: i32, height: i32, title: &'static str) -> Self {
46        let mut t_widget = Tree::new(x, y, width, height, title);
47        let previous_focus = Rc::new(RefCell::new(None::<TreeItem>));
48        let pfr = Rc::clone(&previous_focus);
49        t_widget.set_callback_reason(TreeReason::Selected);
50        t_widget.set_callback(|_t| println!("clicked an item"));
51        t_widget.handle(move |t, e| match e {
52            Event::Move => {
53                let (_, mouse_y) = app::event_coords();
54                let mut state = State::Undefined;
55                let mut pf = pfr.borrow_mut();
56                loop {
57                    match &*pf {
58                        Some(item) => {
59                            let item_y = item.y();
60                            match state {
61                                State::MovingUp => {
62                                    if verify_open_till_root(&pf) {
63                                        if mouse_y < item_y {
64                                            *pf = pf.as_ref().unwrap().prev();
65                                            continue;
66                                        };
67                                        break;
68                                    } else {
69                                        *pf = pf.as_ref().unwrap().prev();
70                                        continue;
71                                    }
72                                }
73                                State::MovingDown => {
74                                    if verify_open_till_root(&pf) {
75                                        if mouse_y > item_y + item.h() {
76                                            *pf = pf.as_ref().unwrap().next();
77                                            continue;
78                                        };
79                                        break;
80                                    } else {
81                                        *pf = pf.as_ref().unwrap().next();
82                                        continue;
83                                    }
84                                }
85                                State::Undefined => {
86                                    if mouse_y < item_y {
87                                        *pf = pf.as_ref().unwrap().prev();
88                                        state = State::MovingUp;
89                                        continue;
90                                    };
91                                    if mouse_y > item_y + item.h() {
92                                        *pf = pf.as_ref().unwrap().next();
93                                        state = State::MovingDown;
94                                        continue;
95                                    };
96                                    return true; // If in same range, don't update 'previous_focus'
97                                }
98                            }
99                        }
100                        // End up here if y is outside tree boundaries, or no tree item is present
101                        None => match &state {
102                            State::MovingUp | State::MovingDown => return true,
103                            State::Undefined => {
104                                *pf = t.first();
105                                state = State::MovingDown;
106                                if pf.is_none() {
107                                    return true;
108                                }
109                                continue;
110                            }
111                        },
112                    };
113                }
114                if verify_open_till_root(&pf) {
115                    t.take_focus().ok();
116                    t.set_item_focus(pf.as_ref().unwrap());
117                    println!("Set focus to item: {:?}", pf.as_ref().unwrap().label());
118                }
119                true
120            }
121            _ => false,
122        });
123        Self {
124            t_widget,
125            previous_focus,
126        }
127    }
Source

pub fn get_item_focus(&self) -> Option<TreeItem>

Get the item that currently has keyboard focus

Source

pub fn is_selected(&self, path: &str) -> bool

Returns whether an item is selected

Source

pub fn item_label_font(&self) -> Font

Gets the items’ label font

Source

pub fn set_item_label_font(&mut self, val: Font)

Sets the items’ label font

Source

pub fn item_label_size(&self) -> i32

Gets the items’ label size

Source

pub fn set_item_label_size(&mut self, val: i32)

Sets the items’ label size

Source

pub fn item_label_fgcolor(&self) -> Color

Gets the items’ foreground color

Source

pub fn set_item_label_fgcolor(&mut self, val: Color)

Sets the items’ foreground color

Source

pub fn item_label_bgcolor(&self) -> Color

Gets the items’ background color

Source

pub fn set_item_label_bgcolor(&mut self, val: Color)

Sets the items’ foreground color

Source

pub fn connector_color(&self) -> Color

Gets the items’ connector color

Source

pub fn set_connector_color(&mut self, val: Color)

Sets the items’ foreground color

Source

pub fn margin_left(&self) -> i32

Gets the left margin

Source

pub fn set_margin_left(&mut self, val: i32)

Sets the left margin

Source

pub fn margin_top(&self) -> i32

Gets the top margin

Source

pub fn set_margin_top(&mut self, val: i32)

Sets the top margin

Source

pub fn margin_bottom(&self) -> i32

Gets the bottom margin

Source

pub fn set_margin_bottom(&mut self, val: i32)

Sets the bottom margin

Source

pub fn line_spacing(&self) -> i32

Gets the line spacing

Source

pub fn set_line_spacing(&mut self, val: i32)

Sets the line spacing

Source

pub fn open_child_margin_bottom(&self) -> i32

Gets the open child bottom margin

Source

pub fn set_open_child_margin_bottom(&mut self, val: i32)

Sets the open child bottom margin

Source

pub fn user_icon_margin_left(&self) -> i32

Gets the user icon left margin

Source

pub fn set_user_icon_margin_left(&mut self, val: i32)

Sets the user icon left margin

Source

pub fn label_margin_left(&self) -> i32

Gets the label’s left margin

Source

pub fn set_label_margin_left(&mut self, val: i32)

Sets the label’s left margin

Source

pub fn widget_margin_left(&self) -> i32

Gets the widget’s left margin

Source

pub fn set_widget_margin_left(&mut self, val: i32)

Sets the widget’s left margin

Source

pub fn connector_width(&self) -> i32

Gets the connector’s width

Source

pub fn set_connector_width(&mut self, val: i32)

Sets the connector’s width

Source

pub fn user_icon(&self) -> Option<Box<dyn ImageExt>>

Gets the user icon

Source

pub fn set_user_icon<Img: ImageExt>(&mut self, image: Option<Img>)

Sets the user icon

Source

pub fn open_icon(&self) -> Option<Box<dyn ImageExt>>

Gets the open icon

Source

pub fn set_open_icon<Img: ImageExt>(&mut self, image: Option<Img>)

Sets the open icon

Source

pub fn close_icon(&self) -> Option<Box<dyn ImageExt>>

Gets the close icon

Source

pub fn set_close_icon<Img: ImageExt>(&mut self, image: Option<Img>)

Sets the close icon

Source

pub fn show_collapse(&self) -> bool

Returns true if the collapse icon is enabled, false if not.

Source

pub fn set_show_collapse(&mut self, flag: bool)

Sets whether the collapse icon is enabled

Source

pub fn show_root(&self) -> bool

Returns whether the root is shown

Source

pub fn set_show_root(&mut self, flag: bool)

Sets whether the root is shown

Source

pub fn connector_style(&self) -> TreeConnectorStyle

Gets the connector style

Source

pub fn set_connector_style(&mut self, val: TreeConnectorStyle)

Sets the connector style

Source

pub fn sort_order(&self) -> TreeSort

Gets the sort order

Source

pub fn set_sort_order(&mut self, val: TreeSort)

Sets the sort order

Source

pub fn select_frame(&self) -> FrameType

Gets the select frame

Source

pub fn set_select_frame(&mut self, val: FrameType)

Sets the select frame

Source

pub fn select_mode(&self) -> TreeSelect

Gets the Tree select mode

Source

pub fn set_select_mode(&mut self, val: TreeSelect)

Sets the Tree select mode

Examples found in repository?
examples/tree.rs (line 169)
146fn main() {
147    let path = env::current_dir().unwrap();
148    let path: String = path
149        .to_str()
150        .unwrap()
151        .chars()
152        .map(|c| match c {
153            '\\' => '/', // change window paths to posix paths
154            _ => c,
155        })
156        .collect();
157
158    let app = app::App::default().with_scheme(app::Scheme::Gtk);
159    let mut wind = Window::default().with_size(400, 300);
160    let mut but = Button::new(260, 255, 80, 40, "Get Items");
161    let _frame = Frame::new(20, 255, 160, 40, "Focus follow mouse");
162    let mut tree = TreeMouseFocus::new(5, 10, 190, 240, "");
163    tree.add(&path);
164
165    let mut items = tree.get_items().unwrap();
166    items.as_mut_slice()[0].set_label("/");
167
168    let mut tree2 = Tree::new(205, 10, 190, 240, "");
169    tree2.set_select_mode(TreeSelect::Multi);
170    tree2.add("First");
171    tree2.add("First/1st");
172    tree2.add("First/2nd/3rd");
173    tree2.add("Second");
174    tree2.add("Third");
175
176    tree2.set_when(fltk::enums::When::ReleaseAlways);
177
178    wind.make_resizable(true);
179    wind.show();
180
181    but.set_callback({
182        let tree2 = tree2.clone();
183        move |_| match tree2.get_selected_items() {
184            None => println!("No items selected"),
185            Some(vals) => print!(
186                "In total {} items selected:\n{}",
187                vals.len(),
188                vals.iter()
189                    .map(|i| tree2.item_pathname(i).unwrap() + "\n")
190                    .collect::<String>()
191            ),
192        }
193    });
194
195    app.run().unwrap();
196}
Source

pub fn item_reselect_mode(&self) -> TreeItemReselectMode

Gets the Tree item’s reselect mode

Source

pub fn set_item_reselect_mode(&mut self, mode: TreeItemReselectMode)

Sets the Tree item’s reselect mode

Source

pub fn item_draw_mode(&self) -> TreeItemDrawMode

Gets the Tree item’s draw mode

Source

pub fn set_item_draw_mode(&mut self, mode: TreeItemDrawMode)

Sets the Tree item’s draw mode

Source

pub fn calc_dimensions(&mut self)

Recalculate widget dimensions and scrollbar visibility, normally done automatically

Source

pub fn calc_tree(&mut self)

Recalculates the tree’s sizes and scrollbar visibility, normally done automatically

Source

pub fn recalc_tree(&mut self)

Recalculates the tree’s sizes and scrollbar visibility, normally done automatically

Source

pub fn displayed(&mut self, item: &TreeItem) -> bool

Returns whether an item is displayed

Source

pub fn show_item(&mut self, item: &TreeItem, y_offset: i32)

Shows an item

Source

pub fn show_item_top(&mut self, item: &TreeItem)

Adjust the vertical scrollbar so that item is visible

Source

pub fn show_item_middle(&mut self, item: &TreeItem)

Adjust the vertical scrollbar so that item is in the middle of the display

Source

pub fn show_item_bottom(&mut self, item: &TreeItem)

Adjust the vertical scrollbar so that the is at the bottom of the display.

Source

pub fn display(&mut self, item: &TreeItem)

Display the item

Source

pub fn vposition(&self) -> i32

Gets the vertical position of the item

Source

pub fn set_vposition(&mut self, pos: i32)

Sets the vertical position of the item

Source

pub fn hposition(&self) -> i32

Gets the horizontal position of the item

Source

pub fn set_hposition(&mut self, pos: i32)

Sets the horizontal position of the item

Source

pub fn is_scrollbar<W: WidgetExt>(&mut self, w: &W) -> bool

Returns whether the widget is a scrollbar

Source

pub fn scrollbar_size(&self) -> i32

Gets the scrollbar size

Source

pub fn set_scrollbar_size(&mut self, sz: i32)

Sets the scrollbar size

Source

pub fn is_vscroll_visible(&self) -> bool

Returns whether vertical scrolling is visible

Source

pub fn is_hscroll_visible(&self) -> bool

Returns whether horizontal scrolling is visible

Source

pub fn set_callback_item(&mut self, item: &TreeItem)

Set the callback item

Source

pub fn callback_item(&self) -> Option<TreeItem>

Get the callback item

Source

pub fn set_callback_reason(&mut self, reason: TreeReason)

Set the callback reason

Examples found in repository?
examples/tree.rs (line 49)
45    fn new(x: i32, y: i32, width: i32, height: i32, title: &'static str) -> Self {
46        let mut t_widget = Tree::new(x, y, width, height, title);
47        let previous_focus = Rc::new(RefCell::new(None::<TreeItem>));
48        let pfr = Rc::clone(&previous_focus);
49        t_widget.set_callback_reason(TreeReason::Selected);
50        t_widget.set_callback(|_t| println!("clicked an item"));
51        t_widget.handle(move |t, e| match e {
52            Event::Move => {
53                let (_, mouse_y) = app::event_coords();
54                let mut state = State::Undefined;
55                let mut pf = pfr.borrow_mut();
56                loop {
57                    match &*pf {
58                        Some(item) => {
59                            let item_y = item.y();
60                            match state {
61                                State::MovingUp => {
62                                    if verify_open_till_root(&pf) {
63                                        if mouse_y < item_y {
64                                            *pf = pf.as_ref().unwrap().prev();
65                                            continue;
66                                        };
67                                        break;
68                                    } else {
69                                        *pf = pf.as_ref().unwrap().prev();
70                                        continue;
71                                    }
72                                }
73                                State::MovingDown => {
74                                    if verify_open_till_root(&pf) {
75                                        if mouse_y > item_y + item.h() {
76                                            *pf = pf.as_ref().unwrap().next();
77                                            continue;
78                                        };
79                                        break;
80                                    } else {
81                                        *pf = pf.as_ref().unwrap().next();
82                                        continue;
83                                    }
84                                }
85                                State::Undefined => {
86                                    if mouse_y < item_y {
87                                        *pf = pf.as_ref().unwrap().prev();
88                                        state = State::MovingUp;
89                                        continue;
90                                    };
91                                    if mouse_y > item_y + item.h() {
92                                        *pf = pf.as_ref().unwrap().next();
93                                        state = State::MovingDown;
94                                        continue;
95                                    };
96                                    return true; // If in same range, don't update 'previous_focus'
97                                }
98                            }
99                        }
100                        // End up here if y is outside tree boundaries, or no tree item is present
101                        None => match &state {
102                            State::MovingUp | State::MovingDown => return true,
103                            State::Undefined => {
104                                *pf = t.first();
105                                state = State::MovingDown;
106                                if pf.is_none() {
107                                    return true;
108                                }
109                                continue;
110                            }
111                        },
112                    };
113                }
114                if verify_open_till_root(&pf) {
115                    t.take_focus().ok();
116                    t.set_item_focus(pf.as_ref().unwrap());
117                    println!("Set focus to item: {:?}", pf.as_ref().unwrap().label());
118                }
119                true
120            }
121            _ => false,
122        });
123        Self {
124            t_widget,
125            previous_focus,
126        }
127    }
Source

pub fn callback_reason(&self) -> TreeReason

Get the callback reason

Source

pub fn item_pathname(&self, item: &TreeItem) -> Result<String, FltkError>

Get an item’s pathname

Examples found in repository?
examples/tree.rs (line 189)
146fn main() {
147    let path = env::current_dir().unwrap();
148    let path: String = path
149        .to_str()
150        .unwrap()
151        .chars()
152        .map(|c| match c {
153            '\\' => '/', // change window paths to posix paths
154            _ => c,
155        })
156        .collect();
157
158    let app = app::App::default().with_scheme(app::Scheme::Gtk);
159    let mut wind = Window::default().with_size(400, 300);
160    let mut but = Button::new(260, 255, 80, 40, "Get Items");
161    let _frame = Frame::new(20, 255, 160, 40, "Focus follow mouse");
162    let mut tree = TreeMouseFocus::new(5, 10, 190, 240, "");
163    tree.add(&path);
164
165    let mut items = tree.get_items().unwrap();
166    items.as_mut_slice()[0].set_label("/");
167
168    let mut tree2 = Tree::new(205, 10, 190, 240, "");
169    tree2.set_select_mode(TreeSelect::Multi);
170    tree2.add("First");
171    tree2.add("First/1st");
172    tree2.add("First/2nd/3rd");
173    tree2.add("Second");
174    tree2.add("Third");
175
176    tree2.set_when(fltk::enums::When::ReleaseAlways);
177
178    wind.make_resizable(true);
179    wind.show();
180
181    but.set_callback({
182        let tree2 = tree2.clone();
183        move |_| match tree2.get_selected_items() {
184            None => println!("No items selected"),
185            Some(vals) => print!(
186                "In total {} items selected:\n{}",
187                vals.len(),
188                vals.iter()
189                    .map(|i| tree2.item_pathname(i).unwrap() + "\n")
190                    .collect::<String>()
191            ),
192        }
193    });
194
195    app.run().unwrap();
196}

Trait Implementations§

Source§

impl Clone for Tree

Source§

fn clone(&self) -> Tree

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Tree

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Tree

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl IntoIterator for Tree

Source§

type Item = TreeItem

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<Tree as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for Tree

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl WidgetBase for Tree

Source§

fn delete(wid: Self)

Deletes widgets and their children.
Source§

unsafe fn from_widget_ptr(ptr: *mut Fl_Widget) -> Self

transforms a widget pointer to a Widget, for internal use Read more
Source§

unsafe fn from_widget<W: WidgetExt>(w: W) -> Self

Get a widget from base widget Read more
Source§

fn handle<F: FnMut(&mut Self, Event) -> bool + 'static>(&mut self, cb: F)

Set a custom handler, where events are managed manually, akin to Fl_Widget::handle(int). Handled or ignored events should return true, unhandled events should return false. takes the widget as a closure argument. The ability to handle an event might depend on handling other events, as explained here
Source§

fn draw<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)

Set a custom draw method. takes the widget as a closure argument. macOS requires that WidgetBase::draw actually calls drawing functions
Source§

fn resize_callback<F: FnMut(&mut Self, i32, i32, i32, i32) + 'static>( &mut self, cb: F, )

Perform a callback on resize. Avoid resizing the parent or the same widget to avoid infinite recursion
Source§

unsafe fn assume_derived(&mut self)

Makes the widget derived Read more
Source§

fn from_dyn_widget<W: WidgetExt>(w: &W) -> Option<Self>

Cast a type-erased widget back to its original widget
Source§

fn from_dyn_widget_ptr(w: *mut Fl_Widget) -> Option<Self>

Cast a type-erased widget pointer back to its original widget
Source§

impl WidgetExt for Tree

Source§

fn set_label(&mut self, title: &str)

Sets the widget’s label. labels support special symbols preceded by an @ sign. and for the associated formatting.
Source§

fn unset_label(&mut self)

Unset a widget’s label
Source§

fn redraw(&mut self)

Redraws a widget, necessary for resizing and changing positions
Source§

fn show(&mut self)

Shows the widget
Source§

fn hide(&mut self)

Hides the widget
Source§

fn x(&self) -> i32

Returns the x coordinate of the widget
Source§

fn y(&self) -> i32

Returns the y coordinate of the widget
Source§

fn w(&self) -> i32

Returns the width of the widget
Source§

fn h(&self) -> i32

Returns the height of the widget
Source§

fn label(&self) -> Option<String>

Returns the label of the widget
Source§

fn measure_label(&self) -> (i32, i32)

Measures the label’s width and height
Source§

fn as_widget_ptr(&self) -> *mut Fl_Widget

transforms a widget to a base Fl_Widget, for internal use
Source§

fn activate(&mut self)

Activates the widget
Source§

fn deactivate(&mut self)

Deactivates the widget
Source§

fn redraw_label(&mut self)

Redraws the label of the widget
Source§

fn resize(&mut self, x: i32, y: i32, width: i32, height: i32)

Resizes and/or moves the widget, takes x, y, width and height
Source§

fn widget_resize(&mut self, x: i32, y: i32, width: i32, height: i32)

Does a simple resize ignoring class-specific resize functionality
Source§

fn tooltip(&self) -> Option<String>

Returns the tooltip text
Source§

fn set_tooltip(&mut self, txt: &str)

Sets the tooltip text
Source§

fn color(&self) -> Color

Returns the widget color
Source§

fn set_color(&mut self, color: Color)

Sets the widget’s color
Source§

fn label_color(&self) -> Color

Returns the widget label’s color
Source§

fn set_label_color(&mut self, color: Color)

Sets the widget label’s color
Source§

fn label_font(&self) -> Font

Returns the widget label’s font
Source§

fn set_label_font(&mut self, font: Font)

Sets the widget label’s font
Source§

fn label_size(&self) -> i32

Returns the widget label’s size
Source§

fn set_label_size(&mut self, sz: i32)

Sets the widget label’s size
Source§

fn label_type(&self) -> LabelType

Returns the widget label’s type
Source§

fn set_label_type(&mut self, typ: LabelType)

Sets the widget label’s type
Source§

fn frame(&self) -> FrameType

Returns the widget’s frame type
Source§

fn set_frame(&mut self, typ: FrameType)

Sets the widget’s frame type
Source§

fn changed(&self) -> bool

Returns whether the widget was changed
Source§

fn set_changed(&mut self)

Mark the widget as changed
Source§

fn clear_changed(&mut self)

Clears the changed status of the widget
Source§

fn align(&self) -> Align

Returns the alignment of the widget
Source§

fn set_align(&mut self, align: Align)

Sets the alignment of the widget
Source§

fn set_when(&mut self, trigger: When)

Sets the default callback trigger for a widget, equivalent to when()
Source§

fn when(&self) -> When

Return the callback trigger, equivalent to when()
Source§

fn parent(&self) -> Option<Group>

Returns the parent of the widget
Source§

fn selection_color(&self) -> Color

Gets the selection color of the widget
Source§

fn set_selection_color(&mut self, color: Color)

Sets the selection color of the widget
Source§

fn do_callback(&mut self)

Runs the already registered callback
Source§

fn window(&self) -> Option<Box<dyn WindowExt>>

Returns the direct window holding the widget
Source§

fn top_window(&self) -> Option<Box<dyn WindowExt>>

Returns the topmost window holding the widget
Source§

fn takes_events(&self) -> bool

Checks whether a widget is capable of taking events
Source§

fn take_focus(&mut self) -> Result<(), FltkError>

Make the widget take focus Read more
Source§

fn set_visible_focus(&mut self)

Set the widget to have visible focus
Source§

fn clear_visible_focus(&mut self)

Clear visible focus
Source§

fn visible_focus(&mut self, v: bool)

Set the visible focus using a flag
Source§

fn has_visible_focus(&self) -> bool

Return whether the widget has visible focus
Source§

fn has_focus(&self) -> bool

Return whether the widget has focus
Source§

fn was_deleted(&self) -> bool

Check if a widget was deleted
Source§

fn damage(&self) -> bool

Return whether the widget was damaged
Source§

fn set_damage(&mut self, flag: bool)

Signal the widget as damaged and it should be redrawn in the next event loop cycle
Source§

fn damage_type(&self) -> Damage

Return the damage mask
Source§

fn set_damage_type(&mut self, mask: Damage)

Signal the type of damage a widget received
Source§

fn set_damage_area(&mut self, mask: Damage, x: i32, y: i32, w: i32, h: i32)

Signal damage for an area inside the widget
Source§

fn clear_damage(&mut self)

Clear the damaged flag
Source§

fn as_window(&self) -> Option<Box<dyn WindowExt>>

Return the widget as a window if it’s a window
Source§

fn as_group(&self) -> Option<Group>

Return the widget as a group widget if it’s a group widget
Source§

fn inside<W: WidgetExt>(&self, wid: &W) -> bool

Checks whether the self widget is inside another widget
Source§

fn get_type<T: WidgetType>(&self) -> T

Returns the widget type when applicable
Source§

fn set_type<T: WidgetType>(&mut self, typ: T)

Sets the widget type
Source§

fn set_image<I: ImageExt>(&mut self, image: Option<I>)

Sets the image of the widget
Source§

fn set_image_scaled<I: ImageExt>(&mut self, image: Option<I>)

Sets the image of the widget scaled to the widget’s size
Source§

fn image(&self) -> Option<Box<dyn ImageExt>>

Gets the image associated with the widget
Source§

fn set_deimage<I: ImageExt>(&mut self, image: Option<I>)

Sets the deactivated image of the widget
Source§

fn set_deimage_scaled<I: ImageExt>(&mut self, image: Option<I>)

Sets the deactivated image of the widget scaled to the widget’s size
Source§

fn deimage(&self) -> Option<Box<dyn ImageExt>>

Gets the deactivated image associated with the widget
Source§

fn set_callback<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)

Sets the callback when the widget is triggered (clicks for example) takes the widget as a closure argument
Source§

fn emit<T: 'static + Clone + Send + Sync>(&mut self, sender: Sender<T>, msg: T)

Emits a message on callback using a sender
Source§

unsafe fn as_widget<W: WidgetBase>(&self) -> W

Upcast a WidgetExt to some widget type Read more
Source§

fn visible(&self) -> bool

Returns whether a widget is visible
Source§

fn visible_r(&self) -> bool

Returns whether a widget or any of its parents are visible (recursively)
Source§

fn is_same<W: WidgetExt>(&self, other: &W) -> bool

Return whether two widgets object point to the same widget
Source§

fn active(&self) -> bool

Returns whether a widget is active
Source§

fn active_r(&self) -> bool

Returns whether a widget or any of its parents are active (recursively)
Source§

fn handle_event(&mut self, event: Event) -> bool

Handle a specific event
Source§

fn is_derived(&self) -> bool

Check whether a widget is derived
Source§

fn as_base_widget(&self) -> Widget
where Self: Sized,

Upcast a WidgetExt to a Widget
Source§

impl WidgetProps for Tree

Source§

fn with_pos(self, x: i32, y: i32) -> Self

Initialize to position x, y

Source§

fn with_size(self, width: i32, height: i32) -> Self

Initialize to size width, height

Source§

fn with_label(self, title: &str) -> Self

Initialize with a label

Source§

fn with_align(self, align: Align) -> Self

Initialize with alignment

Source§

fn with_type<T: WidgetType>(self, typ: T) -> Self

Initialize with type

Source§

fn below_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self

Initialize at bottom of another widget

Source§

fn above_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self

Initialize above of another widget

Source§

fn right_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self

Initialize right of another widget

Source§

fn left_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self

Initialize left of another widget

Source§

fn center_of<W: WidgetExt>(self, w: &W) -> Self

Initialize center of another widget

Source§

fn center_x<W: WidgetExt>(self, w: &W) -> Self

Initialize center of another widget on the x axis

Source§

fn center_y<W: WidgetExt>(self, w: &W) -> Self

Initialize center of another widget on the y axis

Source§

fn center_of_parent(self) -> Self

Initialize center of parent

Source§

fn size_of<W: WidgetExt>(self, w: &W) -> Self

Initialize to the size of another widget

Source§

fn size_of_parent(self) -> Self

Initialize to the size of the parent

Source§

impl Eq for Tree

Source§

impl Send for Tree

Available on non-crate feature single-threaded only.
Source§

impl Sync for Tree

Available on non-crate feature single-threaded only.

Auto Trait Implementations§

§

impl Freeze for Tree

§

impl RefUnwindSafe for Tree

§

impl Unpin for Tree

§

impl UnwindSafe for Tree

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<W> WidgetId<W> for W
where W: WidgetExt + Clone + Send + Sync + 'static,

Source§

fn set_id(&mut self, id: &str)

Set the widget’s Id
Source§

fn with_id(self, id: &str) -> W

Construct a widget with an Id