2022-12-06 16:12:59 +01:00
|
|
|
// Copyright 2022 System76 <info@system76.com>
|
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
|
|
|
|
|
use iced::Color;
|
2023-09-01 07:25:00 +02:00
|
|
|
use iced_core::Widget;
|
2022-12-06 16:12:59 +01:00
|
|
|
|
|
|
|
|
pub trait ElementExt {
|
|
|
|
|
#[must_use]
|
|
|
|
|
fn debug(self, debug: bool) -> Self;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-14 11:56:21 -04:00
|
|
|
impl<Message: 'static> ElementExt for crate::Element<'_, Message> {
|
2022-12-06 16:12:59 +01:00
|
|
|
fn debug(self, debug: bool) -> Self {
|
|
|
|
|
if debug {
|
|
|
|
|
self.explain(Color::WHITE)
|
|
|
|
|
} else {
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-03 21:35:35 +01:00
|
|
|
}
|
2023-09-01 07:25:00 +02:00
|
|
|
|
2023-09-13 16:06:05 +02:00
|
|
|
pub trait ColorExt {
|
|
|
|
|
/// Combines color with background to create appearance of transparency.
|
|
|
|
|
#[must_use]
|
|
|
|
|
fn blend_alpha(self, background: Self, alpha: f32) -> Self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ColorExt for iced::Color {
|
|
|
|
|
fn blend_alpha(self, background: Self, alpha: f32) -> Self {
|
2023-11-28 19:02:08 +00:00
|
|
|
Self {
|
2023-09-13 16:06:05 +02:00
|
|
|
a: 1.0,
|
2023-11-28 19:02:08 +00:00
|
|
|
r: (self.r - background.r).mul_add(alpha, background.r),
|
|
|
|
|
g: (self.g - background.g).mul_add(alpha, background.g),
|
|
|
|
|
b: (self.b - background.b).mul_add(alpha, background.b),
|
2023-09-13 16:06:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|