Add Flex with_reversed_paint_order & initially move face piles to left

Co-Authored-By: Petros Amoiridis <petros@zed.dev>
This commit is contained in:
Julia 2023-02-01 19:18:23 -05:00
parent a5fd0250ab
commit 28786a3c18
2 changed files with 26 additions and 6 deletions

View file

@ -87,6 +87,9 @@ impl View for CollabTitlebarItem {
left_container.add_child(self.render_toggle_collaborator_list_button(&theme, cx)); left_container.add_child(self.render_toggle_collaborator_list_button(&theme, cx));
} }
left_container.add_children(self.render_current_user(&workspace, &theme, cx));
left_container.add_children(self.render_collaborators(&workspace, &theme, cx));
let mut right_container = Flex::row(); let mut right_container = Flex::row();
right_container.add_children(self.render_toggle_screen_sharing_button(&theme, cx)); right_container.add_children(self.render_toggle_screen_sharing_button(&theme, cx));
@ -100,8 +103,6 @@ impl View for CollabTitlebarItem {
right_container.add_child(self.render_toggle_contacts_button(&theme, cx)); right_container.add_child(self.render_toggle_contacts_button(&theme, cx));
} }
} }
right_container.add_children(self.render_collaborators(&workspace, &theme, cx));
right_container.add_children(self.render_current_user(&workspace, &theme, cx));
right_container.add_children(self.render_connection_status(&workspace, cx)); right_container.add_children(self.render_connection_status(&workspace, cx));
Stack::new() Stack::new()
@ -506,7 +507,7 @@ impl CollabTitlebarItem {
.get(&participant.peer_id) .get(&participant.peer_id)
.map(|collaborator| collaborator.replica_id); .map(|collaborator| collaborator.replica_id);
let user = participant.user.clone(); let user = participant.user.clone();
Some(self.render_avatar( Some(self.render_face_pile(
&user, &user,
replica_id, replica_id,
Some(( Some((
@ -535,7 +536,7 @@ impl CollabTitlebarItem {
let replica_id = workspace.read(cx).project().read(cx).replica_id(); let replica_id = workspace.read(cx).project().read(cx).replica_id();
let status = *workspace.read(cx).client().status().borrow(); let status = *workspace.read(cx).client().status().borrow();
if let Some(user) = user { if let Some(user) = user {
Some(self.render_avatar(&user, Some(replica_id), None, workspace, theme, cx)) Some(self.render_face_pile(&user, Some(replica_id), None, workspace, theme, cx))
} else if matches!(status, client::Status::UpgradeRequired) { } else if matches!(status, client::Status::UpgradeRequired) {
None None
} else { } else {
@ -559,7 +560,7 @@ impl CollabTitlebarItem {
} }
} }
fn render_avatar( fn render_face_pile(
&self, &self,
user: &User, user: &User,
replica_id: Option<ReplicaId>, replica_id: Option<ReplicaId>,

View file

@ -20,6 +20,7 @@ struct ScrollState {
pub struct Flex { pub struct Flex {
axis: Axis, axis: Axis,
paint_reversed: bool,
children: Vec<ElementBox>, children: Vec<ElementBox>,
scroll_state: Option<(ElementStateHandle<Rc<ScrollState>>, usize)>, scroll_state: Option<(ElementStateHandle<Rc<ScrollState>>, usize)>,
} }
@ -28,6 +29,7 @@ impl Flex {
pub fn new(axis: Axis) -> Self { pub fn new(axis: Axis) -> Self {
Self { Self {
axis, axis,
paint_reversed: false,
children: Default::default(), children: Default::default(),
scroll_state: None, scroll_state: None,
} }
@ -41,6 +43,11 @@ impl Flex {
Self::new(Axis::Vertical) Self::new(Axis::Vertical)
} }
pub fn with_reversed_paint_order(mut self) -> Self {
self.paint_reversed = true;
self
}
pub fn scrollable<Tag, V>( pub fn scrollable<Tag, V>(
mut self, mut self,
element_id: usize, element_id: usize,
@ -296,7 +303,7 @@ impl Element for Flex {
} }
} }
for child in &mut self.children { let mut child_action = |child: &mut ElementBox| {
if remaining_space > 0. { if remaining_space > 0. {
if let Some(metadata) = child.metadata::<FlexParentData>() { if let Some(metadata) = child.metadata::<FlexParentData>() {
if metadata.float { if metadata.float {
@ -308,11 +315,23 @@ impl Element for Flex {
} }
} }
} }
child.paint(child_origin, visible_bounds, cx); child.paint(child_origin, visible_bounds, cx);
match self.axis { match self.axis {
Axis::Horizontal => child_origin += vec2f(child.size().x(), 0.0), Axis::Horizontal => child_origin += vec2f(child.size().x(), 0.0),
Axis::Vertical => child_origin += vec2f(0.0, child.size().y()), Axis::Vertical => child_origin += vec2f(0.0, child.size().y()),
} }
};
if self.paint_reversed {
for child in self.children.iter_mut().rev() {
child_action(child);
}
} else {
for child in &mut self.children {
child_action(child);
}
} }
if overflowing { if overflowing {