1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 14:49:06 -04:00

Add UiStack::bg_color (#8020)

This lets you ask for the background color of a ui with
`ui.stack().bg_color()`
This commit is contained in:
Emil Ernerfeldt
2026-03-25 12:41:35 +01:00
committed by GitHub
parent 0887b54c93
commit e8f04292a9

View File

@@ -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