Open pombadev opened 2 years ago
I'm pretty new to rust, but i think this is to do with how the buttons are added to the TabBar of the TabPanel. The TabBar isn't public so i can't see how to set the active button easily, but i have a work around below.
Problem: Adding a tab using the "add_tab/with_tab" methods always sets the active TabBar Button to the last button. https://github.com/deinstapel/cursive-tabs/blob/52e94cb6bc686a209127ce7bf9b7087a2d602ba2/src/bar.rs#L121-L138
Adding a tab using the "add_tab_at" method with an index (pos) sets the active TabBarButton to that index. https://github.com/deinstapel/cursive-tabs/blob/52e94cb6bc686a209127ce7bf9b7087a2d602ba2/src/bar.rs#L189-L205 Workaround: Add the desired active tab after you've added the other tabs. This will set it's TabBar Button to be active. Of course you'll need the "add_tab_at" method so the panel will need to be mutable.
let mut panel = TabPanel::new().with_tab(TextView::new(TAB_1).with_name("1"))
.with_tab(TextView::new(TAB_2).with_name("2"))
.with_tab(TextView::new(TAB_3).with_name("3"))
.with_tab(PaddedView::lrtb(2, 2, 1, 1, TextArea::new()).with_name("4"))
.with_bar_alignment(Align::End);
panel.add_tab_at(TextView::new(TAB_0).with_name("0"), 0);
panel.set_active_tab("0").unwrap_or_else(|_| {
panic!("Could not set the first tab as active tab! This is probably an issue with the implementation in the lib. Please report!");
});
How to focus on a tab panel's internal component, instead of one of the tabs?
For example, I have a text editor, I hope to focus on it, instead of the containing tab panel.
Thanks
Hello, I'm following the example verbatim.
https://github.com/deinstapel/cursive-tabs/blob/52e94cb6bc686a209127ce7bf9b7087a2d602ba2/examples/fullscreen.rs#L1-L60
The active tab name is not highlighted initially even though active tab is being set.
https://github.com/deinstapel/cursive-tabs/blob/52e94cb6bc686a209127ce7bf9b7087a2d602ba2/examples/fullscreen.rs#L34
Image to illustrate potential bug and expected behavior.
Could be the same issue as #4
Package info:
cursive-tabs = "0.7.0"