ui::AnimatedIconSource¶
Header: winui/render/AnimatedVisualSource.hpp.
Derives from ui::AnimatedVisualSource.
AnimatedIcon's source interface: an AnimatedVisualSource with named markers, each mapping a state name (such as "PointerOver") to the normalized progress point of that state's pose. AnimatedIconControl::set_state() looks the requested state up here and animates toward its progress. A state with no matching marker leaves the current pose alone. The icon's color arrives as render_icon_frame()'s foreground.
Implement it: draw your icon in render_icon_frame() and hand it to an AnimatedIcon.
Example:
class PulseIcon final : public ui::AnimatedIconSource
{
public:
PulseIcon()
{
markers_["Normal"] = 0.0;
markers_["PointerOver"] = 0.5;
markers_["Pressed"] = 1.0;
}
[[nodiscard]] ui::Size natural_size() const override { return {24.0f, 24.0f}; }
[[nodiscard]] ui::Duration duration() const override { return ui::Duration{900.0}; }
void render_frame(ui::Renderer& r, const ui::Rect& b, double progress) const override
{
render_icon_frame(r, b, progress, ui::colors::Black);
}
void render_icon_frame(ui::Renderer& r, const ui::Rect& b, double progress,
const ui::Color& foreground) const override
{
const float radius = 12.0f * static_cast<float>(progress);
r.fill_ellipse(b.center(), radius, radius, foreground);
}
[[nodiscard]] const std::unordered_map<std::string, double>& markers() const override
{
return markers_;
}
private:
std::unordered_map<std::string, double> markers_;
};
static const PulseIcon pulse;
auto icon = std::make_unique<ui::AnimatedIconControl>();
icon->set_source(&pulse);
icon->set_state("PointerOver"); // animates from 0 toward 0.5
markers¶
State name to the normalized progress (0..1) its pose sits at. Transition segments such as NormalToPointerOver_Start/_End are markers too; AnimatedIcon prefers them.
render_icon_frame¶
virtual void render_icon_frame(Renderer& renderer, const Rect& bounds, double progress, const Color&) const
render_frame() in the icon's foreground color, which AnimatedIcon passes with every draw. The source doesn't store the color, because one source object is shared by every icon showing it. A source with no themable color keeps this default, which ignores foreground.