diff --git a/crates/egui/src/ui_stack.rs b/crates/egui/src/ui_stack.rs index 07026c45b..0686dc086 100644 --- a/crates/egui/src/ui_stack.rs +++ b/crates/egui/src/ui_stack.rs @@ -1,6 +1,8 @@ use std::sync::Arc; use std::{any::Any, iter::FusedIterator}; +use epaint::Color32; + use crate::{Direction, Frame, Id, Rect}; /// What kind is this [`crate::Ui`]? @@ -253,6 +255,24 @@ impl UiStack { pub fn has_visible_frame(&self) -> bool { !self.info.frame.stroke.is_empty() } + + /// The background color of this [`Ui`]. + /// + /// This blend together all [`Frame::fill`] colors + /// up to the root. + #[inline] + pub fn bg_color(&self) -> Color32 { + let mut total = Color32::TRANSPARENT; + for node in self.iter() { + let fill = node.frame().fill; + if fill.is_opaque() { + return fill; + } else if fill != Color32::TRANSPARENT { + total = fill.blend(total); + } + } + total + } } // these methods act on the entire stack