libcosmic/cosmic/cosmic_theme/palette/blend/trait.BlendWith.html
2026-04-18 20:11:25 +00:00

37 lines
No EOL
12 KiB
HTML

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Blending with a custom blend function."><title>BlendWith in cosmic::cosmic_theme::palette::blend - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../../static.files/rustdoc-aa0817cf.css"><meta name="rustdoc-vars" data-root-path="../../../../" data-static-root-path="../../../../static.files/" data-current-crate="cosmic" data-themes="" data-resource-suffix="" data-rustdoc-version="1.90.0-nightly (3048886e5 2025-07-30)" data-channel="nightly" data-search-js="search-fa3e91e5.js" data-settings-js="settings-5514c975.js" ><script src="../../../../static.files/storage-68b7e25d.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../../static.files/main-eebb9057.js"></script><noscript><link rel="stylesheet" href="../../../../static.files/noscript-32bb7600.css"></noscript><link rel="alternate icon" type="image/png" href="../../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../../cosmic/index.html">cosmic</a><span class="version">1.0.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Blend<wbr>With</a></h2><h3><a href="#required-associated-types">Required Associated Types</a></h3><ul class="block"><li><a href="#associatedtype.Color" title="Color">Color</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.blend_with" title="blend_with">blend_with</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In cosmic::<wbr>cosmic_<wbr>theme::<wbr>palette::<wbr>blend</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../../index.html">cosmic</a>::<wbr><a href="../../index.html">cosmic_theme</a>::<wbr><a href="../index.html">palette</a>::<wbr><a href="index.html">blend</a></div><h1>Trait <span class="trait">BlendWith</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="https://docs.rs/palette/0.7.6/src/palette/blend/blend_with.rs.html#11">Source</a> </span></div><pre class="rust item-decl"><code>pub trait BlendWith {
type <a href="#associatedtype.Color" class="associatedtype">Color</a>: <a class="trait" href="trait.Premultiply.html" title="trait cosmic::cosmic_theme::palette::blend::Premultiply">Premultiply</a>;
// Required method
fn <a href="#tymethod.blend_with" class="fn">blend_with</a>&lt;F&gt;(self, destination: Self, blend_function: F) -&gt; Self
<span class="where">where F: <a class="trait" href="trait.BlendFunction.html" title="trait cosmic::cosmic_theme::palette::blend::BlendFunction">BlendFunction</a>&lt;Self::<a class="associatedtype" href="trait.BlendWith.html#associatedtype.Color" title="type cosmic::cosmic_theme::palette::blend::BlendWith::Color">Color</a>&gt;</span>;
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Blending with a custom blend function.</p>
<p>This is a convenience trait that makes it possible to use <a href="trait.BlendFunction.html" title="trait cosmic::cosmic_theme::palette::blend::BlendFunction"><code>BlendFunction</code></a>
via a method on the source color. This makes custom blending more similar to
how the <a href="trait.Compose.html" title="trait cosmic::cosmic_theme::palette::blend::Compose"><code>Compose</code></a> and <a href="trait.Blend.html" title="trait cosmic::cosmic_theme::palette::blend::Blend"><code>Blend</code></a> are used,
including automatic pre-multiplication.</p>
</div></details><h2 id="required-associated-types" class="section-header">Required Associated Types<a href="#required-associated-types" class="anchor">§</a></h2><div class="methods"><details class="toggle" open><summary><section id="associatedtype.Color" class="method"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/blend/blend_with.rs.html#13">Source</a><h4 class="code-header">type <a href="#associatedtype.Color" class="associatedtype">Color</a>: <a class="trait" href="trait.Premultiply.html" title="trait cosmic::cosmic_theme::palette::blend::Premultiply">Premultiply</a></h4></section></summary><div class="docblock"><p>The base color type of <code>Self</code>.</p>
</div></details></div><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.blend_with" class="method"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/blend/blend_with.rs.html#37-39">Source</a><h4 class="code-header">fn <a href="#tymethod.blend_with" class="fn">blend_with</a>&lt;F&gt;(self, destination: Self, blend_function: F) -&gt; Self<div class="where">where
F: <a class="trait" href="trait.BlendFunction.html" title="trait cosmic::cosmic_theme::palette::blend::BlendFunction">BlendFunction</a>&lt;Self::<a class="associatedtype" href="trait.BlendWith.html#associatedtype.Color" title="type cosmic::cosmic_theme::palette::blend::BlendWith::Color">Color</a>&gt;,</div></h4></section></summary><div class="docblock"><p>Blend self, as the source color, with <code>destination</code>, using
<code>blend_function</code>. Anything that implements <a href="trait.BlendFunction.html" title="trait cosmic::cosmic_theme::palette::blend::BlendFunction"><code>BlendFunction</code></a> is
acceptable, including functions and closures.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>palette::{LinSrgb, LinSrgba};
<span class="kw">use </span>palette::blend::{BlendWith, PreAlpha};
<span class="kw">type </span>PreRgba = PreAlpha&lt;LinSrgb&lt;f32&gt;&gt;;
<span class="kw">fn </span>blend_mode(a: PreRgba, b: PreRgba) -&gt; PreRgba {
PreAlpha {
color: LinSrgb::new(a.red * b.green, a.green * b.blue, a.blue * b.red),
alpha: a.alpha * b.alpha,
}
}
<span class="kw">let </span>a = LinSrgba::new(<span class="number">0.2</span>, <span class="number">0.5</span>, <span class="number">0.1</span>, <span class="number">0.8</span>);
<span class="kw">let </span>b = LinSrgba::new(<span class="number">0.6</span>, <span class="number">0.3</span>, <span class="number">0.5</span>, <span class="number">0.1</span>);
<span class="kw">let </span>c = a.blend_with(b, blend_mode);</code></pre></div>
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/nightly/reference/items/traits.html#dyn-compatibility">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><details class="toggle implementors-toggle"><summary><section id="impl-BlendWith-for-PreAlpha%3CC%3E" class="impl"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/blend/blend_with.rs.html#42-44">Source</a><a href="#impl-BlendWith-for-PreAlpha%3CC%3E" class="anchor">§</a><h3 class="code-header">impl&lt;C&gt; <a class="trait" href="trait.BlendWith.html" title="trait cosmic::cosmic_theme::palette::blend::BlendWith">BlendWith</a> for <a class="struct" href="../alpha/struct.PreAlpha.html" title="struct cosmic::cosmic_theme::palette::alpha::PreAlpha">PreAlpha</a>&lt;C&gt;<div class="where">where
C: <a class="trait" href="trait.Premultiply.html" title="trait cosmic::cosmic_theme::palette::blend::Premultiply">Premultiply</a>,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.Color-1" class="associatedtype trait-impl"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/blend/blend_with.rs.html#46">Source</a><a href="#associatedtype.Color-1" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Color" class="associatedtype">Color</a> = C</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-BlendWith-for-Alpha%3CC,+%3CC+as+Premultiply%3E::Scalar%3E" class="impl"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/blend/blend_with.rs.html#57-59">Source</a><a href="#impl-BlendWith-for-Alpha%3CC,+%3CC+as+Premultiply%3E::Scalar%3E" class="anchor">§</a><h3 class="code-header">impl&lt;C&gt; <a class="trait" href="trait.BlendWith.html" title="trait cosmic::cosmic_theme::palette::blend::BlendWith">BlendWith</a> for <a class="struct" href="../struct.Alpha.html" title="struct cosmic::cosmic_theme::palette::Alpha">Alpha</a>&lt;C, &lt;C as <a class="trait" href="trait.Premultiply.html" title="trait cosmic::cosmic_theme::palette::blend::Premultiply">Premultiply</a>&gt;::<a class="associatedtype" href="trait.Premultiply.html#associatedtype.Scalar" title="type cosmic::cosmic_theme::palette::blend::Premultiply::Scalar">Scalar</a>&gt;<div class="where">where
C: <a class="trait" href="trait.Premultiply.html" title="trait cosmic::cosmic_theme::palette::blend::Premultiply">Premultiply</a>,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.Color-2" class="associatedtype trait-impl"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/blend/blend_with.rs.html#61">Source</a><a href="#associatedtype.Color-2" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Color" class="associatedtype">Color</a> = C</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-BlendWith-for-C" class="impl"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/blend/blend_with.rs.html#73-76">Source</a><a href="#impl-BlendWith-for-C" class="anchor">§</a><h3 class="code-header">impl&lt;C&gt; <a class="trait" href="trait.BlendWith.html" title="trait cosmic::cosmic_theme::palette::blend::BlendWith">BlendWith</a> for C<div class="where">where
C: <a class="trait" href="trait.Premultiply.html" title="trait cosmic::cosmic_theme::palette::blend::Premultiply">Premultiply</a>,
&lt;C as <a class="trait" href="trait.Premultiply.html" title="trait cosmic::cosmic_theme::palette::blend::Premultiply">Premultiply</a>&gt;::<a class="associatedtype" href="trait.Premultiply.html#associatedtype.Scalar" title="type cosmic::cosmic_theme::palette::blend::Premultiply::Scalar">Scalar</a>: <a class="trait" href="../stimulus/trait.Stimulus.html" title="trait cosmic::cosmic_theme::palette::stimulus::Stimulus">Stimulus</a>,</div></h3></section></summary><div class="impl-items"><section id="associatedtype.Color-3" class="associatedtype trait-impl"><a class="src rightside" href="https://docs.rs/palette/0.7.6/src/palette/blend/blend_with.rs.html#78">Source</a><a href="#associatedtype.Color-3" class="anchor">§</a><h4 class="code-header">type <a href="#associatedtype.Color" class="associatedtype">Color</a> = C</h4></section></div></details></div><script src="../../../../trait.impl/palette/blend/blend_with/trait.BlendWith.js" data-ignore-extern-crates="palette" async></script></section></div></main></body></html>