Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change children styles in style pass for Tab #175

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 25 additions & 37 deletions src/views/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ use floem_reactive::{as_child_of_current_scope, create_effect, Scope};
use smallvec::SmallVec;
use taffy::style::Display;

use crate::{context::UpdateCx, id::Id, style::DisplayProp, view::View};
use crate::{
context::{StyleCx, UpdateCx},
id::Id,
style::DisplayProp,
view::View,
};

use super::{apply_diff, diff, Diff, DiffOpAdd, FxIndexSet, HashRun};

Expand Down Expand Up @@ -150,41 +155,24 @@ impl<V: View + 'static, T> View for Tab<V, T> {
}
}

fn layout(&mut self, cx: &mut crate::context::LayoutCx) -> taffy::prelude::Node {
// FIXME: This should only layout the selected view.
cx.layout_node(self.id, true, |cx| {
let nodes = self
.children
.iter_mut()
.enumerate()
.filter_map(|(i, child)| {
let child_id = child.as_ref()?.0.id();
let child_view = cx.app_state_mut().view_state(child_id);
child_view.combined_style = child_view.style.clone().set(
DisplayProp,
if i != self.active {
// set display to none for non active child
Display::None
} else {
Display::Flex
},
);
let node = cx.layout_view(&mut child.as_mut()?.0);
Some(node)
})
.collect::<Vec<_>>();
nodes
})
}

fn paint(&mut self, cx: &mut crate::context::PaintCx) {
let child = if let Some(Some((child, _))) = self.children.get_mut(self.active) {
child
} else if let Some(Some((child, _))) = self.children.first_mut() {
child
} else {
return;
};
child.paint(cx);
fn style(&mut self, cx: &mut StyleCx<'_>) {
for (i, child) in self
.children
.iter_mut()
.enumerate()
.filter_map(|(i, child)| child.as_mut().map(|child| (i, &mut child.0)))
{
cx.style_view(child);
let child_view = cx.app_state_mut().view_state(child.id());
child_view.combined_style = child_view.combined_style.clone().set(
DisplayProp,
if i != self.active {
// set display to none for non active child
Display::None
} else {
Display::Flex
},
);
}
}
}