tabs: add drag-to-reorder and pinned tabs
This commit is contained in:
@@ -288,6 +288,15 @@ impl Gallery {
|
||||
.variant(TabsVariant::Pill)
|
||||
.overflow_scroll(true)
|
||||
.selected(selected)
|
||||
.draggable(true)
|
||||
.on_reorder({
|
||||
let gallery = gallery.clone();
|
||||
move |from, to, _, cx| {
|
||||
gallery
|
||||
.update(cx, |gallery, cx| gallery.reorder_demo(from, to, cx))
|
||||
.log_err();
|
||||
}
|
||||
})
|
||||
.tabs({
|
||||
let tabs = self.tabs.clone();
|
||||
let kinds: Vec<Option<SharedString>> = self
|
||||
@@ -299,7 +308,9 @@ impl Gallery {
|
||||
tabs.iter()
|
||||
.zip(kinds.iter())
|
||||
.map(|(id, kind)| {
|
||||
let tab = Tab::new(id.clone(), Self::label_of(id)).closeable(true);
|
||||
let tab = Tab::new(id.clone(), Self::label_of(id))
|
||||
.closeable(true)
|
||||
.pinned(id.as_ref() == "welcome");
|
||||
match kind {
|
||||
Some(kind) => tab.kind(kind.clone()),
|
||||
None => tab,
|
||||
@@ -458,6 +469,17 @@ impl Gallery {
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// Moves the demo tab at `from` to occupy `to`, both indices into the
|
||||
/// open tabs as they were before the move.
|
||||
fn reorder_demo(&mut self, from: usize, to: usize, cx: &mut Context<Self>) {
|
||||
if from >= self.tabs.len() || to >= self.tabs.len() || from == to {
|
||||
return;
|
||||
}
|
||||
let tab = self.tabs.remove(from);
|
||||
self.tabs.insert(to, tab);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// Creates the view behind a demo tab.
|
||||
fn create_view(
|
||||
&self,
|
||||
|
||||
Reference in New Issue
Block a user