Skip to content

Commit

Permalink
Enable smooth transitions for Create Deck.
Browse files Browse the repository at this point in the history
Add the basic framework for being able to set smooth un/highlight
visual transitions for the `Create Deck` widget canvas.
  • Loading branch information
galegosimpatico committed Jan 14, 2018
1 parent 37cc4ea commit 14f5840
Showing 1 changed file with 44 additions and 7 deletions.
51 changes: 44 additions & 7 deletions data/objects/library_new_deck.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,32 @@

area: "{width: py(260), height: py(72)}",

highlighted: { type: "bool", default: false, set: "if(_data != value, [set(_data, value); render()])" },
highlighted: {
type: "bool",
default: false,
set: "
if (
_data != value,
[
set(_data, value)
;
render(false)
],
// else
debug(['library_new_deck#highlighted#set: this code should never run'])
)
"
},

_show_plus: { default: true },
_text: { default: "Create Deck" },

_font: { type: "string", init: "lib.font.regular_font" },

render: "def() ->commands
render: "def (bool creating) -> commands
[
map(range(transition_steps),
schedule(step + delay,
set(animation, {
id: 'fbo',
image: 'fbo',
Expand All @@ -29,8 +46,19 @@
c.fill(),
if(highlighted,
c.set_source_rgba(1.0, 1.0, 1.0, 1.0),
c.set_source_rgba(0.29, 0.33, 0.36, 1.0)),
c.set_source_rgba(
if (creating, 1.0, clamp(mix(.29, 1.0, (step + 1) / transition_steps_dec), .29, 1.0)),
if (creating, 1.0, clamp(mix(.33, 1.0, (step + 1) / transition_steps_dec), .33, 1.0)),
if (creating, 1.0, clamp(mix(.36, 1.0, (step + 1) / transition_steps_dec), .36, 1.0)),
1.0
),
c.set_source_rgba(
if (creating, .29, clamp(mix(1.0, .29, (step + 1) / transition_steps_dec), .29, 1.0)),
if (creating, .33, clamp(mix(1.0, .33, (step + 1) / transition_steps_dec), .33, 1.0)),
if (creating, .36, clamp(mix(1.0, .36, (step + 1) / transition_steps_dec), .36, 1.0)),
1.0
)
),
c.rectangle(0, area.height*0.1, area.width, area.height*0.8),
c.set_line_width(py(20)/10.0),
c.stroke(),
Expand Down Expand Up @@ -58,7 +86,16 @@
]),
}
where c = canvas()
),
) // set(animation, ...)
) // schedule(int, set(animation, ...))
// A little bit of syntactic sugar.
where step = value
) // map(range(...), schedule(int, set(animation, ...)))
// Casted to `decimal` for convenience.
where transition_steps_dec = transition_steps * 1.0
where transition_steps = 1
where delay = 0
,
set(x2, x2),
set(y, y)
]",
Expand All @@ -75,6 +112,6 @@
on_mouse_enter: "set(highlighted, true)",
on_mouse_leave: "set(highlighted, false)",

on_create: "render()",
on_type_updated: "render()",
on_create: "render(true)",
on_type_updated: "render(true)",
}

0 comments on commit 14f5840

Please sign in to comment.