pub struct Tree { /* private fields */ }
Expand description
Defines a tree widget
Implementations§
Source§impl Tree
impl Tree
Sourcepub fn new<'a, T: Into<Option<&'a str>>>(
x: i32,
y: i32,
width: i32,
height: i32,
title: T,
) -> Tree
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 screeny
- The y coordinate in the screenwidth
- The width of the widgetheigth
- The height of the widgettitle
- 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?
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}
Sourcepub fn default_fill() -> Self
pub fn default_fill() -> Self
Constructs a widget with the size of its parent
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 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}
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 first(&self) -> Option<TreeItem>
pub fn first(&self) -> Option<TreeItem>
Gets the first tree item
Examples found in repository?
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 }
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?
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}
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 deselect_all(
&mut self,
item: &TreeItem,
do_callback: bool,
) -> Result<(), FltkError>
pub fn deselect_all( &mut self, item: &TreeItem, do_callback: bool, ) -> Result<(), FltkError>
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>
Extend the selection between and including from
and to
§Errors
Errors on failure to extend selection
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 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 }
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?
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}
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 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 }
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?
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 IntoIterator for Tree
impl IntoIterator for Tree
Source§impl WidgetBase for Tree
impl WidgetBase for Tree
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 set_label(&mut self, title: &str)
fn set_label(&mut self, title: &str)
@
sign.
and for the associated formatting.Source§fn unset_label(&mut self)
fn unset_label(&mut self)
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_when(&mut self, trigger: When)
fn set_when(&mut self, trigger: When)
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§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§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 as_widget<W: WidgetBase>(&self) -> W
unsafe fn as_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 WidgetSource§impl WidgetProps for Tree
impl WidgetProps for Tree
Source§fn with_label(self, title: &str) -> Self
fn with_label(self, title: &str) -> Self
Initialize with a label
Source§fn with_align(self, align: Align) -> Self
fn with_align(self, align: Align) -> Self
Initialize with alignment
Source§fn with_type<T: WidgetType>(self, typ: T) -> Self
fn with_type<T: WidgetType>(self, typ: T) -> Self
Initialize with type
Source§fn below_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
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
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
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
fn left_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
Initialize left of another widget
Source§fn center_x<W: WidgetExt>(self, w: &W) -> Self
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
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
fn center_of_parent(self) -> Self
Initialize center of parent
Source§fn size_of_parent(self) -> Self
fn size_of_parent(self) -> Self
Initialize to the size of the parent
impl Eq for Tree
impl Send for Tree
single-threaded
only.impl Sync for Tree
single-threaded
only.