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

pull box shadow from extractor #631

Merged
merged 2 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
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
28 changes: 12 additions & 16 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ impl<'a> PaintCx<'a> {
self.set_z_index(z_index);
}

paint_bg(self, &style, &view_style_props, size);
paint_bg(self, &view_style_props, size);

view.borrow_mut().paint(self);
paint_border(self, &layout_props, &view_style_props, size);
Expand Down Expand Up @@ -1042,27 +1042,23 @@ impl<'a> PaintCx<'a> {

let style = view_state.borrow().combined_style.clone();
let mut view_style_props = view_state.borrow().view_style_props.clone();
let style =
if let Some(dragging_style) = view_state.borrow().dragging_style.clone() {
let style = style.apply(dragging_style);
let mut _new_frame = false;
view_style_props.read_explicit(
&style,
&style,
&Instant::now(),
&mut _new_frame,
);
style
} else {
style
};
if let Some(dragging_style) = view_state.borrow().dragging_style.clone() {
let style = style.apply(dragging_style);
let mut _new_frame = false;
view_style_props.read_explicit(
&style,
&style,
&Instant::now(),
&mut _new_frame,
);
}
let layout_props = view_state.borrow().layout_props.clone();

// Important: If any method early exit points are added in this
// code block, they MUST call CURRENT_DRAG_PAINTING_ID.take() before
// returning.
CURRENT_DRAG_PAINTING_ID.set(Some(id));
paint_bg(self, &style, &view_style_props, size);
paint_bg(self, &view_style_props, size);

view.borrow_mut().paint(self);
paint_border(self, &layout_props, &view_style_props, size);
Expand Down
22 changes: 11 additions & 11 deletions src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use crate::{
context::{ComputeLayoutCx, EventCx, LayoutCx, PaintCx, StyleCx, UpdateCx},
event::{Event, EventPropagation},
id::ViewId,
style::{BoxShadowProp, LayoutProps, Style, StyleClassRef},
style::{LayoutProps, Style, StyleClassRef},
view_state::ViewStyleProps,
views::{dyn_view, DynamicView},
};
Expand Down Expand Up @@ -378,12 +378,7 @@ pub fn default_compute_layout(id: ViewId, cx: &mut ComputeLayoutCx) -> Option<Re
layout_rect
}

pub(crate) fn paint_bg(
cx: &mut PaintCx,
computed_style: &Style,
style: &ViewStyleProps,
size: Size,
) {
pub(crate) fn paint_bg(cx: &mut PaintCx, style: &ViewStyleProps, size: Size) {
let radius = match style.border_radius() {
crate::unit::PxPct::Px(px) => px,
crate::unit::PxPct::Pct(pct) => size.min_side() * (pct / 100.),
Expand All @@ -401,7 +396,7 @@ pub(crate) fn paint_bg(
};
cx.fill(&circle, &bg, 0.0);
} else {
paint_box_shadow(cx, computed_style, rect, Some(radius));
paint_box_shadow(cx, style, rect, Some(radius));
let bg = match style.background() {
Some(color) => color,
None => return,
Expand All @@ -410,7 +405,7 @@ pub(crate) fn paint_bg(
cx.fill(&rounded_rect, &bg, 0.0);
}
} else {
paint_box_shadow(cx, computed_style, size.to_rect(), None);
paint_box_shadow(cx, style, size.to_rect(), None);
let bg = match style.background() {
Some(color) => color,
None => return,
Expand All @@ -419,8 +414,13 @@ pub(crate) fn paint_bg(
}
}

fn paint_box_shadow(cx: &mut PaintCx, style: &Style, rect: Rect, rect_radius: Option<f64>) {
if let Some(shadow) = style.get(BoxShadowProp).as_ref() {
fn paint_box_shadow(
cx: &mut PaintCx,
style: &ViewStyleProps,
rect: Rect,
rect_radius: Option<f64>,
) {
if let Some(shadow) = &style.shadow() {
let min = rect.size().min_side();
let h_offset = match shadow.h_offset {
crate::unit::PxPct::Px(px) => px,
Expand Down
5 changes: 3 additions & 2 deletions src/view_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::{
prop_extractor,
responsive::ScreenSizeBp,
style::{
Background, BorderColor, BorderRadius, LayoutProps, Outline, OutlineColor, Style,
StyleClassRef, StyleSelectors,
Background, BorderColor, BorderRadius, BoxShadowProp, LayoutProps, Outline, OutlineColor,
Style, StyleClassRef, StyleSelectors,
},
};
use bitflags::bitflags;
Expand Down Expand Up @@ -72,6 +72,7 @@ prop_extractor! {
pub outline_color: OutlineColor,
pub border_color: BorderColor,
pub background: Background,
pub shadow: BoxShadowProp,
}
}

Expand Down