Tree.last_visible_item

22 views
Skip to first unread message

Viraj Kanwade

unread,
Jul 15, 2024, 6:20:14 AM (12 days ago) Jul 15
to fltk.general
Hello,

As per the docs, https://www.fltk.org/doc-1.3/classFl__Tree.html#af39bab9126b8a96722336672b53634e6, Tree.last_visible_item returns last open(), visible item.

What is the definition of visible here?
If the tree root is collapsed/ not open, what should be the last_visible_item, the root or last item in the tree? 

Thanks

Greg Ercolano

unread,
Jul 15, 2024, 11:11:43 AM (12 days ago) Jul 15
to fltkg...@googlegroups.com

On 7/15/24 00:21, Viraj Kanwade wrote:

Hello,

As per the docs, https://www.fltk.org/doc-1.3/classFl__Tree.html#af39bab9126b8a96722336672b53634e6, Tree.last_visible_item returns last open(), visible item.

What is the definition of visible here?

    It's the last item that can currently be seen on the screen if you scroll to the bottom.

    first/next/last visible are methods for walking the visible items (the items not collapsed).


If the tree root is collapsed/ not open, what should be the last_visible_item, the root or last item in the tree?

    According to the docs, it returns 0 if there's no visible item:
Returns
    Last visible item in the tree, or 0 if none.


Viraj Kanwade

unread,
Jul 15, 2024, 1:24:42 PM (12 days ago) Jul 15
to fltk.general
Thank you for confirming that.

Currently I am using fltk-rs (FLTK rust binding). 

And I am facing an issue where the last_visible_item always returns the actual last item in the tree even if the parent is collapsed.

Not sure if it is an issue in fltk or fltk-rs.

Viraj Kanwade

unread,
Jul 15, 2024, 1:24:56 PM (12 days ago) Jul 15
to fltk.general
use fltk::{prelude::*, *};
use tree::TreeItem;


fn prep_tree(t: &mut tree::Tree) {
dbg!(t.calc_tree());

dbg!(t.is_vscroll_visible());

let ti: TreeItem = t.last_visible_item().unwrap();
dbg!(ti.clone());
dbg!(ti.label().unwrap());
dbg!(ti.y(), ti.h());
dbg!(ti.is_visible());

t.resize(t.x(), t.y(), t.w(), ti.y() + ti.h() + 2);
app::redraw();
}

struct MyTree {
t: tree::Tree,
}

impl MyTree {
pub fn default() -> Self {
let mut t = tree::Tree::default();
t.set_show_root(false);
t.set_callback(prep_tree);
Self {
t
}
}
pub fn end(&mut self) {
prep_tree(&mut self.t);
}
}

widget_extends!(MyTree, tree::Tree, t);

fn main() {
let a = app::App::default().with_scheme(app::Scheme::Gtk);
let mut win = window::Window::default().with_size(800, 600);

let mut row = group::Flex::default_fill().row();
let scroll = group::Scroll::default();
let mut col = group::Pack::default().with_type(group::PackType::Vertical);

let mut t = MyTree::default();
t.add("Branches");
t.add("Branches/main");
t.add("Branches/dev");
t.add("Branches/abc/def");
t.add("Branches/abc/pqr");
t.end();

col.end();
scroll.end();
scroll.resizable(&col);
row.fixed(&scroll, 200);
row.end();

win.end();
win.show_with_env_args();

col.resize(scroll.x(), scroll.y(), scroll.w(), scroll.h());

a.run().unwrap();
}


On Monday, July 15, 2024 at 8:11:43 AM UTC-7 er...@seriss.com wrote:

Greg Ercolano

unread,
Jul 15, 2024, 2:44:30 PM (12 days ago) Jul 15
to fltkg...@googlegroups.com

On 7/15/24 10:15, Viraj Kanwade wrote:

Thank you for confirming that.

Currently I am using fltk-rs (FLTK rust binding). 

And I am facing an issue where the last_visible_item always returns the actual last item in the tree even if the parent is collapsed.

Not sure if it is an issue in fltk or fltk-rs.

    Hmm, might be a bug in Fl_Tree::last_visible_item().

    I've opened issue#1012 to explore the problem.


Greg Ercolano

unread,
Jul 16, 2024, 12:53:40 PM (11 days ago) Jul 16
to fltkg...@googlegroups.com
    Viraj, I've suggested a fix in the form of a small patch in the issue linked above.
    If you could follow up inside the issue (or here if you don't have a github account)
    and I'll apply and close.

Viraj Kanwade

unread,
Jul 16, 2024, 4:55:44 PM (11 days ago) Jul 16
to fltk.general
Thank Greg
Reply all
Reply to author
Forward
0 new messages