Makepad アニメーションスキル は何をしますか?
バージョン: makepad-widgets (dev ブランチ) | 最終更新: 2026-01-19
アップデートを確認: https://crates.io/crates/makepad-widgets
あなたは Makepad アニメーションの専門家です。以下の方法でユーザーを支援します:
- コードを書く: 以下のパターンに従ってアニメーションコードを生成します
- 質問に答える: ステート、トランジション、タイムラインについて説明します
ドキュメント
詳細なドキュメントについては、ローカルファイルを参照してください:
./references/animation-system.md- 完全なアニメーションリファレンス
高度なパターン
プロダクション対応のアニメーションパターンについては、_base/ ディレクトリを参照してください:
| パターン | 説明 |
|---|---|
| 06-animator-basics | アニメーターの基礎 |
| 07-easing-functions | イージングとタイミング |
| 08-keyframe-animation | 複雑なキーフレーム |
重要: ドキュメントの完全性チェック
質問に答える前に、Claude は以下を実行する必要があります:
- 上記の関連リファレンスファイルを読む
- ファイルの読み取りに失敗した場合、またはファイルが空の場合:
- ユーザーに通知: 「ローカルドキュメントが不完全です。
/sync-crate-skills makepad --forceを実行してドキュメントを更新することをお勧めします」 - SKILL.md のパターンと組み込みの知識に基づいて回答する
- ユーザーに通知: 「ローカルドキュメントが不完全です。
- リファレンスファイルが存在する場合は、その内容を回答に組み込む
主要パターン
1. 基本ホバーアニメーション
<Button> {
text: "Hover Me"
animator: {
hover = {
default: off
off = {
from: { all: Forward { duration: 0.15 } }
apply: {
draw_bg: { color: #333333 }
}
}
on = {
from: { all: Forward { duration: 0.15 } }
apply: {
draw_bg: { color: #555555 }
}
}
}
}
}
2. マルチステートアニメーション
<View> {
animator: {
hover = {
default: off
off = {
from: { all: Forward { duration: 0.2 } }
apply: { draw_bg: { color: #222222 } }
}
on = {
from: { all: Forward { duration: 0.2 } }
apply: { draw_bg: { color: #444444 } }
}
}
pressed = {
default: off
off = {
from: { all: Forward { duration: 0.1 } }
apply: { draw_bg: { scale: 1.0 } }
}
on = {
from: { all: Forward { duration: 0.1 } }
apply: { draw_bg: { scale: 0.95 } }
}
}
}
}
3. フォーカスステートアニメーション
<TextInput> {
animator: {
focus = {
default: off
off = {
from: { all: Forward { duration: 0.2 } }
apply: {
draw_bg: {
border_color: #444444
border_size: 1.0
}
}
}
on = {
from: { all: Forward { duration: 0.2 } }
apply: {
draw_bg: {
border_color: #0066CC
border_size: 2.0
}
}
}
}
}
}
4. 無効ステート
<Button> {
animator: {
disabled = {
default: off
off = {
from: { all: Snap }
apply: {
draw_bg: { color: #0066CC }
draw_text: { color: #FFFFFF }
}
}
on = {
from: { all: Snap }
apply: {
draw_bg: { color: #333333 }
draw_text: { color: #666666 }
}
}
}
}
}
アニメーター構造
| プロパティ | 説明 |
|---|---|
animator | アニメーションのルートコンテナ |
{state} = | ステート定義 (hover, pressed, focus, disabled) |
default: | 初期ステート値 |
{value} = | ステート値の定義 (on, off, custom) |
from: | トランジションタイムライン |
apply: | アニメーションするプロパティ |
タイムラインタイプ (Play 列挙型)
| タイプ | 説明 |
|---|---|
Forward { duration: f64 } | 線形フォワードアニメーション |
Snap | 即時変更、トランジションなし |
Reverse { duration: f64, end: f64 } | リバースアニメーション |
Loop { duration: f64, end: f64 } | ループアニメーション |
BounceLoop { duration: f64, end: f64 } | バウンスループアニメーション |
イージング関数 (Ease 列挙型)
// 基本
Linear
// 二次
InQuad, OutQuad, InOutQuad
// 三次
InCubic, OutCubic, InOutCubic
// 四次
InQuart, OutQuart, InOutQuart
// 五次
InQuint, OutQuint, InOutQuint
// 正弦波
InSine, OutSine, InOutSine
// 指数
InExp, OutExp, InOutExp
// 円形
InCirc, OutCirc, InOutCirc
// 弾性
InElastic, OutElastic, InOutElastic
// バック
InBack, OutBack, InOutBack
// バウンス
InBounce, OutBounce, InOutBounce
// カスタム
ExpDecay { d1: f64, d2: f64 }
Bezier { cp0: f64, cp1: f64, cp2: f64, cp3: f64 }
Pow { begin: f64, end: f64 }
イージングの使用
from: {
all: Ease { duration: 0.3, ease: InOutQuad }
}
一般的なステート
| ステート | 値 | トリガー |
|---|---|---|
hover | on, off | マウスが入る/出る |
pressed / down | on, off | マウス押す/離す |
focus | on, off | フォーカスを得る/失う |
disabled | on, off | ウィジェット有効/無効 |
selected | on, off | 選択の変更 |
アニメーション可能なプロパティ
ほとんどの draw_* シェーダーユニフォームはアニメーション可能です:
- 色:
color,border_color,shadow_color - サイズ:
border_size,border_radius,shadow_radius - 変形:
scale,rotation,offset - 不透明度:
opacity
コードを書くとき
- 常に
default:で初期ステートを設定する - スムーズなトランジションには
Forwardを使用する - 即時ステート変更(無効など)には
Snapを使用する - 応答性を高めるため、継続時間は短く(0.1〜0.3秒)保つ
draw_bg,draw_textなどでシェーダーユニフォームをアニメーションする
Rust API (AnimatorImpl トレイト)
pub trait AnimatorImpl {
// ステートにアニメーション
fn animator_play(&mut self, cx: &mut Cx, state: &[LiveId; 2]);
// ステートにカット(アニメーションなし)
fn animator_cut(&mut self, cx: &mut Cx, state: &[LiveId; 2]);
// 現在のステートを確認
fn animator_in_state(&self, cx: &Cx, state: &[LiveId; 2]) -> bool;
}
// 使用例
fn handle_event(&mut self, cx: &mut Cx, event: &Event, scope: &mut Scope) {
match event.hits(cx, self.area()) {
Hit::FingerHoverIn(_) => {
self.animator_play(cx, id!(hover.on));
}
Hit::FingerHoverOut(_) => {
self.animator_play(cx, id!(hover.off));
}
Hit::FingerDown(_) => {
self.animator_play(cx, id!(pressed.on));
}
Hit::FingerUp(_) => {
self.animator_play(cx, id!(pressed.off));
}
_ => {}
}
}
質問に答えるとき
- ステートは独立しており、複数のステートを同時にアクティブにできます
- アニメーションは、ステートがその値に達したときにプロパティを適用します
fromは「どのように」アニメーションするかを定義し、applyは「何を」アニメーションするかを定義します- Makepad は古い値と新しい値の間を自動的に補間します
- Rust でアニメーションステートを参照するには
id!(state.value)マクロを使用します