Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transition effect and animation in imGui #1857

Closed
coderboyisongithub opened this issue Jun 4, 2018 · 1 comment
Closed

Transition effect and animation in imGui #1857

coderboyisongithub opened this issue Jun 4, 2018 · 1 comment

Comments

@coderboyisongithub
Copy link

I am trying to do is when i hover my mouse over a histogram it should change its color but with transition,like fade_in,fade_out something like that how shall i do it?

@ocornut
Copy link
Owner

ocornut commented Jun 4, 2018

It's not easily possible at imgui level but you can do it as user code level. You would need to track hover-state and a timer for each ID you want to involve in the animation (e.g. map<id, float>) and manually update those timers. Say, you could store a 0.0..1.0 float per ID, make this float grow toward 1.0 on hover and go back toward 0.0 otherwise.

Something like this pseudo-code:
(untested, I'm just typing code in the reply here)

ImGuiID item_id = ImGui::GetID("label");
auto it = my_map.find(item_id);
float value = (it != my_map.end()) ? it->second : 0.0f;
PushStyleCol(...., lerp(saturate(value), color, color_hovered);
PlotHistogram();
if (IsItemHovered())
    value = min(value + io.DeltaTime * fade_in_speed, 1.0f);
else
   value = max(value - io.DeltaTime * fade_in_speed, 0.0f);
if (it != my_map.end())
   it->second = value;
else if (value > 0.0f)
  my_insert.insert(pair(id, value));
PopStyleCol();

Also see #1537 for inspiration.

@ocornut ocornut closed this as completed Jun 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants