pub struct Tree { /* private fields */ }
Expand description
Defines a tree widget
Implementations§
source§impl Tree
impl Tree
sourcepub fn set_root_label(&mut self, new_label: &str)
pub fn set_root_label(&mut self, new_label: &str)
Sets the root label
sourcepub fn add(&mut self, path: &str) -> Option<TreeItem>
pub fn add(&mut self, path: &str) -> Option<TreeItem>
Adds a TreeItem
Examples found in repository?
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();
}
sourcepub fn insert_above(&mut self, above: &TreeItem, name: &str) -> Option<TreeItem>
pub fn insert_above(&mut self, above: &TreeItem, name: &str) -> Option<TreeItem>
Inserts a TreeItem
above another tree item
sourcepub fn insert(
&mut self,
item: &TreeItem,
name: &str,
pos: i32
) -> Option<TreeItem>
pub fn insert( &mut self, item: &TreeItem, name: &str, pos: i32 ) -> Option<TreeItem>
Inserts a TreeItem
at a position pos
sourcepub fn clear_children(&mut self, item: &TreeItem)
pub fn clear_children(&mut self, item: &TreeItem)
Clears all children
sourcepub fn find_clicked(&self, yonly: bool) -> Option<TreeItem>
pub fn find_clicked(&self, yonly: bool) -> Option<TreeItem>
finds a clicked item
sourcepub fn set_item_clicked(&self) -> Option<TreeItem>
👎Deprecated since 1.2.21: use callback_item() instead
pub fn set_item_clicked(&self) -> Option<TreeItem>
Set the item that was last clicked.
sourcepub fn first(&self) -> Option<TreeItem>
pub fn first(&self) -> Option<TreeItem>
Gets the first tree item
Examples found in repository?
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,
}
}
sourcepub fn first_visible_item(&self) -> Option<TreeItem>
pub fn first_visible_item(&self) -> Option<TreeItem>
Gets the first visible tree item
sourcepub fn last_visible_item(&self) -> Option<TreeItem>
pub fn last_visible_item(&self) -> Option<TreeItem>
Gets the last visible tree item
sourcepub fn next_visible_item(
&self,
start: &TreeItem,
direction_key: Key
) -> Option<TreeItem>
pub fn next_visible_item( &self, start: &TreeItem, direction_key: Key ) -> Option<TreeItem>
Gets the next visible tree item
sourcepub fn first_selected_item(&self) -> Option<TreeItem>
pub fn first_selected_item(&self) -> Option<TreeItem>
Gets the first selected tree item
sourcepub fn last_selected_item(&self) -> Option<TreeItem>
pub fn last_selected_item(&self) -> Option<TreeItem>
Gets the last selected tree item
sourcepub fn next_item(
&self,
item: &TreeItem,
direction_key: Key,
visible: bool
) -> Option<TreeItem>
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
sourcepub fn next_selected_item(
&mut self,
item: &TreeItem,
direction_key: Key
) -> Option<TreeItem>
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
sourcepub fn get_selected_items(&self) -> Option<Vec<TreeItem>>
pub fn get_selected_items(&self) -> Option<Vec<TreeItem>>
Gets the selected tree items
Examples found in repository?
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();
}
sourcepub fn open_toggle(&mut self, item: &TreeItem, do_callback: bool)
pub fn open_toggle(&mut self, item: &TreeItem, do_callback: bool)
Toggle the open state
sourcepub fn select_toggle(&mut self, item: &TreeItem, do_callback: bool)
pub fn select_toggle(&mut self, item: &TreeItem, do_callback: bool)
Toggle the select state of the specified
sourcepub fn deselect(
&mut self,
path: &str,
do_callback: bool
) -> Result<(), FltkError>
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
sourcepub fn select_only(
&mut self,
selected_item: &TreeItem,
do_callback: bool
) -> Result<(), FltkError>
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
sourcepub fn extend_selection_dir(
&mut self,
from: &TreeItem,
to: &TreeItem,
direction_key: Key,
val: TreeItemSelect,
visible: bool
) -> Result<(), FltkError>
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
sourcepub fn extend_selection(
&mut self,
from: &TreeItem,
to: &TreeItem,
val: TreeItemSelect,
visible: bool
) -> Result<(), FltkError>
pub fn extend_selection( &mut self, from: &TreeItem, to: &TreeItem, val: TreeItemSelect, visible: bool ) -> Result<(), FltkError>
sourcepub fn set_item_focus(&mut self, item: &TreeItem)
pub fn set_item_focus(&mut self, item: &TreeItem)
Set the item that currently should have keyboard focus
Examples found in repository?
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,
}
}
sourcepub fn get_item_focus(&self) -> Option<TreeItem>
pub fn get_item_focus(&self) -> Option<TreeItem>
Get the item that currently has keyboard focus
sourcepub fn is_selected(&self, path: &str) -> bool
pub fn is_selected(&self, path: &str) -> bool
Returns whether an item is selected
sourcepub fn item_label_font(&self) -> Font
pub fn item_label_font(&self) -> Font
Gets the items’ label font
sourcepub fn set_item_label_font(&mut self, val: Font)
pub fn set_item_label_font(&mut self, val: Font)
Sets the items’ label font
sourcepub fn item_label_size(&self) -> i32
pub fn item_label_size(&self) -> i32
Gets the items’ label size
sourcepub fn set_item_label_size(&mut self, val: i32)
pub fn set_item_label_size(&mut self, val: i32)
Sets the items’ label size
sourcepub fn item_label_fgcolor(&self) -> Color
pub fn item_label_fgcolor(&self) -> Color
Gets the items’ foreground color
sourcepub fn set_item_label_fgcolor(&mut self, val: Color)
pub fn set_item_label_fgcolor(&mut self, val: Color)
Sets the items’ foreground color
sourcepub fn item_label_bgcolor(&self) -> Color
pub fn item_label_bgcolor(&self) -> Color
Gets the items’ background color
sourcepub fn set_item_label_bgcolor(&mut self, val: Color)
pub fn set_item_label_bgcolor(&mut self, val: Color)
Sets the items’ foreground color
sourcepub fn connector_color(&self) -> Color
pub fn connector_color(&self) -> Color
Gets the items’ connector color
sourcepub fn set_connector_color(&mut self, val: Color)
pub fn set_connector_color(&mut self, val: Color)
Sets the items’ foreground color
sourcepub fn margin_left(&self) -> i32
pub fn margin_left(&self) -> i32
Gets the left margin
sourcepub fn set_margin_left(&mut self, val: i32)
pub fn set_margin_left(&mut self, val: i32)
Sets the left margin
sourcepub fn margin_top(&self) -> i32
pub fn margin_top(&self) -> i32
Gets the top margin
sourcepub fn set_margin_top(&mut self, val: i32)
pub fn set_margin_top(&mut self, val: i32)
Sets the top margin
sourcepub fn margin_bottom(&self) -> i32
pub fn margin_bottom(&self) -> i32
Gets the bottom margin
sourcepub fn set_margin_bottom(&mut self, val: i32)
pub fn set_margin_bottom(&mut self, val: i32)
Sets the bottom margin
sourcepub fn line_spacing(&self) -> i32
pub fn line_spacing(&self) -> i32
Gets the line spacing
sourcepub fn set_line_spacing(&mut self, val: i32)
pub fn set_line_spacing(&mut self, val: i32)
Sets the line spacing
sourcepub fn open_child_margin_bottom(&self) -> i32
pub fn open_child_margin_bottom(&self) -> i32
Gets the open child bottom margin
sourcepub fn set_open_child_margin_bottom(&mut self, val: i32)
pub fn set_open_child_margin_bottom(&mut self, val: i32)
Sets the open child bottom margin
sourcepub fn user_icon_margin_left(&self) -> i32
pub fn user_icon_margin_left(&self) -> i32
Gets the user icon left margin
sourcepub fn set_user_icon_margin_left(&mut self, val: i32)
pub fn set_user_icon_margin_left(&mut self, val: i32)
Sets the user icon left margin
sourcepub fn label_margin_left(&self) -> i32
pub fn label_margin_left(&self) -> i32
Gets the label’s left margin
sourcepub fn set_label_margin_left(&mut self, val: i32)
pub fn set_label_margin_left(&mut self, val: i32)
Sets the label’s left margin
sourcepub fn widget_margin_left(&self) -> i32
pub fn widget_margin_left(&self) -> i32
Gets the widget’s left margin
sourcepub fn set_widget_margin_left(&mut self, val: i32)
pub fn set_widget_margin_left(&mut self, val: i32)
Sets the widget’s left margin
sourcepub fn connector_width(&self) -> i32
pub fn connector_width(&self) -> i32
Gets the connector’s width
sourcepub fn set_connector_width(&mut self, val: i32)
pub fn set_connector_width(&mut self, val: i32)
Sets the connector’s width
sourcepub fn set_user_icon<Img: ImageExt>(&mut self, image: Option<Img>)
pub fn set_user_icon<Img: ImageExt>(&mut self, image: Option<Img>)
Sets the user icon
sourcepub fn set_open_icon<Img: ImageExt>(&mut self, image: Option<Img>)
pub fn set_open_icon<Img: ImageExt>(&mut self, image: Option<Img>)
Sets the open icon
sourcepub fn close_icon(&self) -> Option<Box<dyn ImageExt>>
pub fn close_icon(&self) -> Option<Box<dyn ImageExt>>
Gets the close icon
sourcepub fn set_close_icon<Img: ImageExt>(&mut self, image: Option<Img>)
pub fn set_close_icon<Img: ImageExt>(&mut self, image: Option<Img>)
Sets the close icon
sourcepub fn show_collapse(&self) -> bool
pub fn show_collapse(&self) -> bool
Returns true if the collapse icon is enabled, false if not.
sourcepub fn set_show_collapse(&mut self, flag: bool)
pub fn set_show_collapse(&mut self, flag: bool)
Sets whether the collapse icon is enabled
sourcepub fn set_show_root(&mut self, flag: bool)
pub fn set_show_root(&mut self, flag: bool)
Sets whether the root is shown
sourcepub fn connector_style(&self) -> TreeConnectorStyle
pub fn connector_style(&self) -> TreeConnectorStyle
Gets the connector style
sourcepub fn set_connector_style(&mut self, val: TreeConnectorStyle)
pub fn set_connector_style(&mut self, val: TreeConnectorStyle)
Sets the connector style
sourcepub fn sort_order(&self) -> TreeSort
pub fn sort_order(&self) -> TreeSort
Gets the sort order
sourcepub fn set_sort_order(&mut self, val: TreeSort)
pub fn set_sort_order(&mut self, val: TreeSort)
Sets the sort order
sourcepub fn select_frame(&self) -> FrameType
pub fn select_frame(&self) -> FrameType
Gets the select frame
sourcepub fn set_select_frame(&mut self, val: FrameType)
pub fn set_select_frame(&mut self, val: FrameType)
Sets the select frame
sourcepub fn select_mode(&self) -> TreeSelect
pub fn select_mode(&self) -> TreeSelect
Gets the Tree select mode
sourcepub fn set_select_mode(&mut self, val: TreeSelect)
pub fn set_select_mode(&mut self, val: TreeSelect)
Sets the Tree select mode
Examples found in repository?
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();
}
sourcepub fn item_reselect_mode(&self) -> TreeItemReselectMode
pub fn item_reselect_mode(&self) -> TreeItemReselectMode
Gets the Tree item’s reselect mode
sourcepub fn set_item_reselect_mode(&mut self, mode: TreeItemReselectMode)
pub fn set_item_reselect_mode(&mut self, mode: TreeItemReselectMode)
Sets the Tree item’s reselect mode
sourcepub fn item_draw_mode(&self) -> TreeItemDrawMode
pub fn item_draw_mode(&self) -> TreeItemDrawMode
Gets the Tree item’s draw mode
sourcepub fn set_item_draw_mode(&mut self, mode: TreeItemDrawMode)
pub fn set_item_draw_mode(&mut self, mode: TreeItemDrawMode)
Sets the Tree item’s draw mode
sourcepub fn calc_dimensions(&mut self)
pub fn calc_dimensions(&mut self)
Recalculate widget dimensions and scrollbar visibility, normally done automatically
sourcepub fn calc_tree(&mut self)
pub fn calc_tree(&mut self)
Recalculates the tree’s sizes and scrollbar visibility, normally done automatically
sourcepub fn recalc_tree(&mut self)
pub fn recalc_tree(&mut self)
Recalculates the tree’s sizes and scrollbar visibility, normally done automatically
sourcepub fn show_item_top(&mut self, item: &TreeItem)
pub fn show_item_top(&mut self, item: &TreeItem)
Adjust the vertical scrollbar so that item
is visible
sourcepub fn show_item_middle(&mut self, item: &TreeItem)
pub fn show_item_middle(&mut self, item: &TreeItem)
Adjust the vertical scrollbar so that item
is in the middle of the display
sourcepub fn show_item_bottom(&mut self, item: &TreeItem)
pub fn show_item_bottom(&mut self, item: &TreeItem)
Adjust the vertical scrollbar so that the is at the bottom of the display.
sourcepub fn set_vposition(&mut self, pos: i32)
pub fn set_vposition(&mut self, pos: i32)
Sets the vertical position of the item
sourcepub fn set_hposition(&mut self, pos: i32)
pub fn set_hposition(&mut self, pos: i32)
Sets the horizontal position of the item
sourcepub fn is_scrollbar<W: WidgetExt>(&mut self, w: &W) -> bool
pub fn is_scrollbar<W: WidgetExt>(&mut self, w: &W) -> bool
Returns whether the widget is a scrollbar
sourcepub fn scrollbar_size(&self) -> i32
pub fn scrollbar_size(&self) -> i32
Gets the scrollbar size
sourcepub fn set_scrollbar_size(&mut self, sz: i32)
pub fn set_scrollbar_size(&mut self, sz: i32)
Sets the scrollbar size
sourcepub fn is_vscroll_visible(&self) -> bool
pub fn is_vscroll_visible(&self) -> bool
Returns whether vertical scrolling is visible
sourcepub fn is_hscroll_visible(&self) -> bool
pub fn is_hscroll_visible(&self) -> bool
Returns whether horizontal scrolling is visible
sourcepub fn set_callback_item(&mut self, item: &TreeItem)
pub fn set_callback_item(&mut self, item: &TreeItem)
Set the callback item
sourcepub fn callback_item(&self) -> Option<TreeItem>
pub fn callback_item(&self) -> Option<TreeItem>
Get the callback item
sourcepub fn set_callback_reason(&mut self, reason: TreeReason)
pub fn set_callback_reason(&mut self, reason: TreeReason)
Set the callback reason
Examples found in repository?
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,
}
}
sourcepub fn callback_reason(&self) -> TreeReason
pub fn callback_reason(&self) -> TreeReason
Get the callback reason
sourcepub fn item_pathname(&self, item: &TreeItem) -> Result<String, FltkError>
pub fn item_pathname(&self, item: &TreeItem) -> Result<String, FltkError>
Get an item’s pathname
Examples found in repository?
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 IntoIterator for Tree
impl IntoIterator for Tree
source§impl PartialEq for Tree
impl PartialEq for Tree
source§impl WidgetBase for Tree
impl WidgetBase for Tree
source§fn new<'a, T: Into<Option<&'a str>>>(
x: i32,
y: i32,
width: i32,
height: i32,
title: T
) -> Tree
fn new<'a, T: Into<Option<&'a str>>>( x: i32, y: i32, width: i32, height: i32, title: T ) -> Tree
source§fn default_fill() -> Self
fn default_fill() -> Self
source§unsafe fn from_widget_ptr(ptr: *mut Fl_Widget) -> Self
unsafe fn from_widget_ptr(ptr: *mut Fl_Widget) -> Self
source§unsafe fn from_widget<W: WidgetExt>(w: W) -> Self
unsafe fn from_widget<W: WidgetExt>(w: W) -> Self
source§fn handle<F: FnMut(&mut Self, Event) -> bool + 'static>(&mut self, cb: F)
fn handle<F: FnMut(&mut Self, Event) -> bool + 'static>(&mut self, cb: F)
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 heresource§fn draw<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
fn draw<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
WidgetBase::draw
actually calls drawing functionssource§fn resize_callback<F: FnMut(&mut Self, i32, i32, i32, i32) + 'static>(
&mut self,
cb: F
)
fn resize_callback<F: FnMut(&mut Self, i32, i32, i32, i32) + 'static>( &mut self, cb: F )
source§unsafe fn assume_derived(&mut self)
unsafe fn assume_derived(&mut self)
source§impl WidgetExt for Tree
impl WidgetExt for Tree
source§fn with_label(self, title: &str) -> Self
fn with_label(self, title: &str) -> Self
source§fn with_align(self, align: Align) -> Self
fn with_align(self, align: Align) -> Self
source§fn with_type<T: WidgetType>(self, typ: T) -> Self
fn with_type<T: WidgetType>(self, typ: T) -> Self
source§fn below_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
fn below_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
source§fn above_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
fn above_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
source§fn right_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
fn right_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
source§fn left_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
fn left_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
source§fn center_of_parent(self) -> Self
fn center_of_parent(self) -> Self
source§fn size_of_parent(self) -> Self
fn size_of_parent(self) -> Self
source§fn set_label(&mut self, title: &str)
fn set_label(&mut self, title: &str)
@
sign.
and for the associated formatting.source§fn measure_label(&self) -> (i32, i32)
fn measure_label(&self) -> (i32, i32)
source§fn as_widget_ptr(&self) -> *mut Fl_Widget
fn as_widget_ptr(&self) -> *mut Fl_Widget
Fl_Widget
, for internal usesource§fn deactivate(&mut self)
fn deactivate(&mut self)
source§fn redraw_label(&mut self)
fn redraw_label(&mut self)
source§fn resize(&mut self, x: i32, y: i32, width: i32, height: i32)
fn resize(&mut self, x: i32, y: i32, width: i32, height: i32)
source§fn widget_resize(&mut self, x: i32, y: i32, width: i32, height: i32)
fn widget_resize(&mut self, x: i32, y: i32, width: i32, height: i32)
source§fn set_tooltip(&mut self, txt: &str)
fn set_tooltip(&mut self, txt: &str)
source§fn label_color(&self) -> Color
fn label_color(&self) -> Color
source§fn set_label_color(&mut self, color: Color)
fn set_label_color(&mut self, color: Color)
source§fn label_font(&self) -> Font
fn label_font(&self) -> Font
source§fn set_label_font(&mut self, font: Font)
fn set_label_font(&mut self, font: Font)
source§fn label_size(&self) -> i32
fn label_size(&self) -> i32
source§fn set_label_size(&mut self, sz: i32)
fn set_label_size(&mut self, sz: i32)
source§fn label_type(&self) -> LabelType
fn label_type(&self) -> LabelType
source§fn set_label_type(&mut self, typ: LabelType)
fn set_label_type(&mut self, typ: LabelType)
source§fn set_changed(&mut self)
fn set_changed(&mut self)
source§fn clear_changed(&mut self)
fn clear_changed(&mut self)
source§fn set_trigger(&mut self, trigger: CallbackTrigger)
fn set_trigger(&mut self, trigger: CallbackTrigger)
when()
source§fn trigger(&self) -> CallbackTrigger
fn trigger(&self) -> CallbackTrigger
when()
source§fn selection_color(&self) -> Color
fn selection_color(&self) -> Color
source§fn set_selection_color(&mut self, color: Color)
fn set_selection_color(&mut self, color: Color)
source§fn do_callback(&mut self)
fn do_callback(&mut self)
source§fn top_window(&self) -> Option<Box<dyn WindowExt>>
fn top_window(&self) -> Option<Box<dyn WindowExt>>
source§fn takes_events(&self) -> bool
fn takes_events(&self) -> bool
source§fn set_visible_focus(&mut self)
fn set_visible_focus(&mut self)
source§fn clear_visible_focus(&mut self)
fn clear_visible_focus(&mut self)
source§fn visible_focus(&mut self, v: bool)
fn visible_focus(&mut self, v: bool)
source§fn has_visible_focus(&self) -> bool
fn has_visible_focus(&self) -> bool
source§fn was_deleted(&self) -> bool
fn was_deleted(&self) -> bool
source§fn set_damage(&mut self, flag: bool)
fn set_damage(&mut self, flag: bool)
source§fn damage_type(&self) -> Damage
fn damage_type(&self) -> Damage
source§fn set_damage_type(&mut self, mask: Damage)
fn set_damage_type(&mut self, mask: Damage)
source§fn set_damage_area(&mut self, mask: Damage, x: i32, y: i32, w: i32, h: i32)
fn set_damage_area(&mut self, mask: Damage, x: i32, y: i32, w: i32, h: i32)
source§fn clear_damage(&mut self)
fn clear_damage(&mut self)
source§fn as_window(&self) -> Option<Box<dyn WindowExt>>
fn as_window(&self) -> Option<Box<dyn WindowExt>>
source§fn as_group(&self) -> Option<Group>
fn as_group(&self) -> Option<Group>
source§fn inside<W: WidgetExt>(&self, wid: &W) -> bool
fn inside<W: WidgetExt>(&self, wid: &W) -> bool
source§fn get_type<T: WidgetType>(&self) -> T
fn get_type<T: WidgetType>(&self) -> T
source§fn set_type<T: WidgetType>(&mut self, typ: T)
fn set_type<T: WidgetType>(&mut self, typ: T)
source§fn set_image_scaled<I: ImageExt>(&mut self, image: Option<I>)
fn set_image_scaled<I: ImageExt>(&mut self, image: Option<I>)
source§unsafe fn image_mut(&self) -> Option<&mut Image>
unsafe fn image_mut(&self) -> Option<&mut Image>
source§fn set_deimage<I: ImageExt>(&mut self, image: Option<I>)
fn set_deimage<I: ImageExt>(&mut self, image: Option<I>)
source§fn set_deimage_scaled<I: ImageExt>(&mut self, image: Option<I>)
fn set_deimage_scaled<I: ImageExt>(&mut self, image: Option<I>)
source§fn deimage(&self) -> Option<Box<dyn ImageExt>>
fn deimage(&self) -> Option<Box<dyn ImageExt>>
source§unsafe fn deimage_mut(&self) -> Option<&mut Image>
unsafe fn deimage_mut(&self) -> Option<&mut Image>
source§fn set_callback<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
fn set_callback<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
source§fn emit<T: 'static + Clone + Send + Sync>(&mut self, sender: Sender<T>, msg: T)
fn emit<T: 'static + Clone + Send + Sync>(&mut self, sender: Sender<T>, msg: T)
source§unsafe fn into_widget<W: WidgetBase>(&self) -> W
unsafe fn into_widget<W: WidgetBase>(&self) -> W
WidgetExt
to some widget type Read moresource§fn visible_r(&self) -> bool
fn visible_r(&self) -> bool
source§fn is_same<W: WidgetExt>(&self, other: &W) -> bool
fn is_same<W: WidgetExt>(&self, other: &W) -> bool
source§fn active_r(&self) -> bool
fn active_r(&self) -> bool
source§fn handle_event(&mut self, event: Event) -> bool
fn handle_event(&mut self, event: Event) -> bool
source§fn is_derived(&self) -> bool
fn is_derived(&self) -> bool
source§fn as_base_widget(&self) -> Widgetwhere
Self: Sized,
fn as_base_widget(&self) -> Widgetwhere
Self: Sized,
WidgetExt
to a Widgetimpl Eq for Tree
impl Send for Tree
single-threaded
only.impl Sync for Tree
single-threaded
only.