Struct fltk::tree::Tree

source ·
pub struct Tree { /* private fields */ }
Expand description

Defines a tree widget

Implementations§

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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
    fn add(&mut self, path: &str) -> Option<TreeItem> {
        self.t_widget.add(path)
    }

    /// Caution, variable 'previous focus' must be set to None, as it
    /// otherwise could try to refer to an already freed memory location,
    /// when this TreeItem is removed.
    fn remove(&mut self, item: &TreeItem) -> Result<(), FltkError> {
        *self.previous_focus.borrow_mut() = None;
        self.t_widget.remove(item)
    }

    fn get_items(&self) -> Option<Vec<TreeItem>> {
        self.t_widget.get_items()
    }
}

fn main() {
    let path = env::current_dir().unwrap();
    let path: String = path
        .to_str()
        .unwrap()
        .chars()
        .enumerate()
        .map(|(_, c)| match c {
            '\\' => '/', // change window paths to posix paths
            _ => c,
        })
        .collect();

    let app = app::App::default().with_scheme(app::Scheme::Gtk);
    let mut wind = Window::default().with_size(400, 300);
    let mut but = Button::new(260, 255, 80, 40, "Get Items");
    let _frame = Frame::new(20, 255, 160, 40, "Focus follow mouse");
    let mut tree = TreeMouseFocus::new(5, 10, 190, 240, "");
    tree.add(&path);

    let mut items = tree.get_items().unwrap();
    items.as_mut_slice()[0].set_label("/");

    let mut tree2 = Tree::new(205, 10, 190, 240, "");
    tree2.set_select_mode(TreeSelect::Multi);
    tree2.add("First");
    tree2.add("First/1st");
    tree2.add("First/2nd/3rd");
    tree2.add("Second");
    tree2.add("Third");

    tree2.set_trigger(fltk::enums::CallbackTrigger::ReleaseAlways);

    wind.make_resizable(true);
    wind.show();

    but.set_callback({
        let tree2 = tree2.clone();
        move |_| match tree2.get_selected_items() {
            None => println!("No items selected"),
            Some(vals) => print!(
                "In total {} items selected:\n{}",
                vals.len(),
                vals.iter()
                    .map(|i| tree2.item_pathname(i).unwrap() + "\n")
                    .collect::<String>()
            ),
        }
    });

    app.run().unwrap();
}
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
137
138
139
    fn remove(&mut self, item: &TreeItem) -> Result<(), FltkError> {
        *self.previous_focus.borrow_mut() = None;
        self.t_widget.remove(item)
    }
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 set_item_clicked(&self) -> Option<TreeItem>

👎Deprecated since 1.2.21: use callback_item() instead

Set the item that was last clicked.

source

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

Gets the first tree item

Examples found in repository?
examples/tree.rs (line 104)
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
    fn new(x: i32, y: i32, width: i32, height: i32, title: &'static str) -> Self {
        let mut t_widget = Tree::new(x, y, width, height, title);
        let previous_focus = Rc::new(RefCell::new(None::<TreeItem>));
        let pfr = Rc::clone(&previous_focus);
        t_widget.set_callback_reason(TreeReason::Selected);
        t_widget.set_callback(|_t| println!("clicked an item"));
        t_widget.handle(move |t, e| match e {
            Event::Move => {
                let (_, mouse_y) = app::event_coords();
                let mut state = State::Undefined;
                let mut pf = pfr.borrow_mut();
                loop {
                    match &*pf {
                        Some(item) => {
                            let item_y = item.y();
                            match state {
                                State::MovingUp => {
                                    if verify_open_till_root(&pf) {
                                        if mouse_y < item_y {
                                            *pf = pf.as_ref().unwrap().prev();
                                            continue;
                                        };
                                        break;
                                    } else {
                                        *pf = pf.as_ref().unwrap().prev();
                                        continue;
                                    }
                                }
                                State::MovingDown => {
                                    if verify_open_till_root(&pf) {
                                        if mouse_y > item_y + item.h() {
                                            *pf = pf.as_ref().unwrap().next();
                                            continue;
                                        };
                                        break;
                                    } else {
                                        *pf = pf.as_ref().unwrap().next();
                                        continue;
                                    }
                                }
                                State::Undefined => {
                                    if mouse_y < item_y {
                                        *pf = pf.as_ref().unwrap().prev();
                                        state = State::MovingUp;
                                        continue;
                                    };
                                    if mouse_y > item_y + item.h() {
                                        *pf = pf.as_ref().unwrap().next();
                                        state = State::MovingDown;
                                        continue;
                                    };
                                    return true; // If in same range, don't update 'previous_focus'
                                }
                            }
                        }
                        // End up here if y is outside tree boundaries, or no tree item is present
                        None => match &state {
                            State::MovingUp | State::MovingDown => return true,
                            State::Undefined => {
                                *pf = t.first();
                                state = State::MovingDown;
                                if pf.is_none() {
                                    return true;
                                }
                                continue;
                            }
                        },
                    };
                }
                if verify_open_till_root(&pf) {
                    t.take_focus().ok();
                    t.set_item_focus(pf.as_ref().unwrap());
                    println!("Set focus to item: {:?}", pf.as_ref().unwrap().label());
                }
                true
            }
            _ => false,
        });
        Self {
            t_widget,
            previous_focus,
        }
    }
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 184)
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
fn main() {
    let path = env::current_dir().unwrap();
    let path: String = path
        .to_str()
        .unwrap()
        .chars()
        .enumerate()
        .map(|(_, c)| match c {
            '\\' => '/', // change window paths to posix paths
            _ => c,
        })
        .collect();

    let app = app::App::default().with_scheme(app::Scheme::Gtk);
    let mut wind = Window::default().with_size(400, 300);
    let mut but = Button::new(260, 255, 80, 40, "Get Items");
    let _frame = Frame::new(20, 255, 160, 40, "Focus follow mouse");
    let mut tree = TreeMouseFocus::new(5, 10, 190, 240, "");
    tree.add(&path);

    let mut items = tree.get_items().unwrap();
    items.as_mut_slice()[0].set_label("/");

    let mut tree2 = Tree::new(205, 10, 190, 240, "");
    tree2.set_select_mode(TreeSelect::Multi);
    tree2.add("First");
    tree2.add("First/1st");
    tree2.add("First/2nd/3rd");
    tree2.add("Second");
    tree2.add("Third");

    tree2.set_trigger(fltk::enums::CallbackTrigger::ReleaseAlways);

    wind.make_resizable(true);
    wind.show();

    but.set_callback({
        let tree2 = tree2.clone();
        move |_| match tree2.get_selected_items() {
            None => println!("No items selected"),
            Some(vals) => print!(
                "In total {} items selected:\n{}",
                vals.len(),
                vals.iter()
                    .map(|i| tree2.item_pathname(i).unwrap() + "\n")
                    .collect::<String>()
            ),
        }
    });

    app.run().unwrap();
}
source

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

Gets the all tree items

Examples found in repository?
examples/tree.rs (line 142)
141
142
143
    fn get_items(&self) -> Option<Vec<TreeItem>> {
        self.t_widget.get_items()
    }
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
    fn new(x: i32, y: i32, width: i32, height: i32, title: &'static str) -> Self {
        let mut t_widget = Tree::new(x, y, width, height, title);
        let previous_focus = Rc::new(RefCell::new(None::<TreeItem>));
        let pfr = Rc::clone(&previous_focus);
        t_widget.set_callback_reason(TreeReason::Selected);
        t_widget.set_callback(|_t| println!("clicked an item"));
        t_widget.handle(move |t, e| match e {
            Event::Move => {
                let (_, mouse_y) = app::event_coords();
                let mut state = State::Undefined;
                let mut pf = pfr.borrow_mut();
                loop {
                    match &*pf {
                        Some(item) => {
                            let item_y = item.y();
                            match state {
                                State::MovingUp => {
                                    if verify_open_till_root(&pf) {
                                        if mouse_y < item_y {
                                            *pf = pf.as_ref().unwrap().prev();
                                            continue;
                                        };
                                        break;
                                    } else {
                                        *pf = pf.as_ref().unwrap().prev();
                                        continue;
                                    }
                                }
                                State::MovingDown => {
                                    if verify_open_till_root(&pf) {
                                        if mouse_y > item_y + item.h() {
                                            *pf = pf.as_ref().unwrap().next();
                                            continue;
                                        };
                                        break;
                                    } else {
                                        *pf = pf.as_ref().unwrap().next();
                                        continue;
                                    }
                                }
                                State::Undefined => {
                                    if mouse_y < item_y {
                                        *pf = pf.as_ref().unwrap().prev();
                                        state = State::MovingUp;
                                        continue;
                                    };
                                    if mouse_y > item_y + item.h() {
                                        *pf = pf.as_ref().unwrap().next();
                                        state = State::MovingDown;
                                        continue;
                                    };
                                    return true; // If in same range, don't update 'previous_focus'
                                }
                            }
                        }
                        // End up here if y is outside tree boundaries, or no tree item is present
                        None => match &state {
                            State::MovingUp | State::MovingDown => return true,
                            State::Undefined => {
                                *pf = t.first();
                                state = State::MovingDown;
                                if pf.is_none() {
                                    return true;
                                }
                                continue;
                            }
                        },
                    };
                }
                if verify_open_till_root(&pf) {
                    t.take_focus().ok();
                    t.set_item_focus(pf.as_ref().unwrap());
                    println!("Set focus to item: {:?}", pf.as_ref().unwrap().label());
                }
                true
            }
            _ => false,
        });
        Self {
            t_widget,
            previous_focus,
        }
    }
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 170)
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
fn main() {
    let path = env::current_dir().unwrap();
    let path: String = path
        .to_str()
        .unwrap()
        .chars()
        .enumerate()
        .map(|(_, c)| match c {
            '\\' => '/', // change window paths to posix paths
            _ => c,
        })
        .collect();

    let app = app::App::default().with_scheme(app::Scheme::Gtk);
    let mut wind = Window::default().with_size(400, 300);
    let mut but = Button::new(260, 255, 80, 40, "Get Items");
    let _frame = Frame::new(20, 255, 160, 40, "Focus follow mouse");
    let mut tree = TreeMouseFocus::new(5, 10, 190, 240, "");
    tree.add(&path);

    let mut items = tree.get_items().unwrap();
    items.as_mut_slice()[0].set_label("/");

    let mut tree2 = Tree::new(205, 10, 190, 240, "");
    tree2.set_select_mode(TreeSelect::Multi);
    tree2.add("First");
    tree2.add("First/1st");
    tree2.add("First/2nd/3rd");
    tree2.add("Second");
    tree2.add("Third");

    tree2.set_trigger(fltk::enums::CallbackTrigger::ReleaseAlways);

    wind.make_resizable(true);
    wind.show();

    but.set_callback({
        let tree2 = tree2.clone();
        move |_| match tree2.get_selected_items() {
            None => println!("No items selected"),
            Some(vals) => print!(
                "In total {} items selected:\n{}",
                vals.len(),
                vals.iter()
                    .map(|i| tree2.item_pathname(i).unwrap() + "\n")
                    .collect::<String>()
            ),
        }
    });

    app.run().unwrap();
}
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
    fn new(x: i32, y: i32, width: i32, height: i32, title: &'static str) -> Self {
        let mut t_widget = Tree::new(x, y, width, height, title);
        let previous_focus = Rc::new(RefCell::new(None::<TreeItem>));
        let pfr = Rc::clone(&previous_focus);
        t_widget.set_callback_reason(TreeReason::Selected);
        t_widget.set_callback(|_t| println!("clicked an item"));
        t_widget.handle(move |t, e| match e {
            Event::Move => {
                let (_, mouse_y) = app::event_coords();
                let mut state = State::Undefined;
                let mut pf = pfr.borrow_mut();
                loop {
                    match &*pf {
                        Some(item) => {
                            let item_y = item.y();
                            match state {
                                State::MovingUp => {
                                    if verify_open_till_root(&pf) {
                                        if mouse_y < item_y {
                                            *pf = pf.as_ref().unwrap().prev();
                                            continue;
                                        };
                                        break;
                                    } else {
                                        *pf = pf.as_ref().unwrap().prev();
                                        continue;
                                    }
                                }
                                State::MovingDown => {
                                    if verify_open_till_root(&pf) {
                                        if mouse_y > item_y + item.h() {
                                            *pf = pf.as_ref().unwrap().next();
                                            continue;
                                        };
                                        break;
                                    } else {
                                        *pf = pf.as_ref().unwrap().next();
                                        continue;
                                    }
                                }
                                State::Undefined => {
                                    if mouse_y < item_y {
                                        *pf = pf.as_ref().unwrap().prev();
                                        state = State::MovingUp;
                                        continue;
                                    };
                                    if mouse_y > item_y + item.h() {
                                        *pf = pf.as_ref().unwrap().next();
                                        state = State::MovingDown;
                                        continue;
                                    };
                                    return true; // If in same range, don't update 'previous_focus'
                                }
                            }
                        }
                        // End up here if y is outside tree boundaries, or no tree item is present
                        None => match &state {
                            State::MovingUp | State::MovingDown => return true,
                            State::Undefined => {
                                *pf = t.first();
                                state = State::MovingDown;
                                if pf.is_none() {
                                    return true;
                                }
                                continue;
                            }
                        },
                    };
                }
                if verify_open_till_root(&pf) {
                    t.take_focus().ok();
                    t.set_item_focus(pf.as_ref().unwrap());
                    println!("Set focus to item: {:?}", pf.as_ref().unwrap().label());
                }
                true
            }
            _ => false,
        });
        Self {
            t_widget,
            previous_focus,
        }
    }
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 190)
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
fn main() {
    let path = env::current_dir().unwrap();
    let path: String = path
        .to_str()
        .unwrap()
        .chars()
        .enumerate()
        .map(|(_, c)| match c {
            '\\' => '/', // change window paths to posix paths
            _ => c,
        })
        .collect();

    let app = app::App::default().with_scheme(app::Scheme::Gtk);
    let mut wind = Window::default().with_size(400, 300);
    let mut but = Button::new(260, 255, 80, 40, "Get Items");
    let _frame = Frame::new(20, 255, 160, 40, "Focus follow mouse");
    let mut tree = TreeMouseFocus::new(5, 10, 190, 240, "");
    tree.add(&path);

    let mut items = tree.get_items().unwrap();
    items.as_mut_slice()[0].set_label("/");

    let mut tree2 = Tree::new(205, 10, 190, 240, "");
    tree2.set_select_mode(TreeSelect::Multi);
    tree2.add("First");
    tree2.add("First/1st");
    tree2.add("First/2nd/3rd");
    tree2.add("Second");
    tree2.add("Third");

    tree2.set_trigger(fltk::enums::CallbackTrigger::ReleaseAlways);

    wind.make_resizable(true);
    wind.show();

    but.set_callback({
        let tree2 = tree2.clone();
        move |_| match tree2.get_selected_items() {
            None => println!("No items selected"),
            Some(vals) => print!(
                "In total {} items selected:\n{}",
                vals.len(),
                vals.iter()
                    .map(|i| tree2.item_pathname(i).unwrap() + "\n")
                    .collect::<String>()
            ),
        }
    });

    app.run().unwrap();
}

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

§

type Item = TreeItem

The type of the elements being iterated over.
§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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 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 Read more
source§

fn default_fill() -> Self

Constructs a widget with the size of its parent
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 center_x<W: WidgetExt>(self, w: &W) -> Self

Initialize center of another widget

source§

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

Initialize center of another widget

source§

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

Initialize to a 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_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§

fn set_pos(&mut self, x: i32, y: i32)

Set to position x, y
source§

fn set_size(&mut self, width: i32, height: i32)

Set to dimensions width and height
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 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 width(&self) -> i32

Returns the width of the widget
source§

fn height(&self) -> i32

Returns the height 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) -> 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_trigger(&mut self, trigger: CallbackTrigger)

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

fn trigger(&self) -> CallbackTrigger

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§

unsafe fn image_mut(&self) -> Option<&mut Image>

Get a reference type of the widget’s image Read more
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§

unsafe fn deimage_mut(&self) -> Option<&mut Image>

Get a reference type of the widget’s deactivated image Read more
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 into_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 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> 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,

§

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>,

§

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>,

§

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 + Send + Sync + Clone + '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