ocornut / ocornut/imgui

Window Hovering fading animation

Open
#1,925 12 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

tricks & tips
Dominant language
C++
Stars
76.3k
Forks
12k
Avg merge
40m
Merged PRs (30d)
1

Description

It has been commented several times.
Here is a proof of concept that it can be done without any ImGui modification

action

This Lua code could be done with a class in C++ or a lambda function and provide us a function that when called from the window to be hovered returns a value in animated variation between two values

-- duration, min desired value, max desired value
local function HoverActionFactory(dur,minv,maxv)

	minv = minv or 0
	maxv = maxv or 1
	local range = maxv - minv
	local lastFrameHovered = false
	local actionTime = 0
	local actionUP = false
	local iniVal = 0
	local currVal = 0
	
	local function SetAction(dir)
		lastFrameHovered = dir
		actionTime = 0
		actionUP = dir
		iniVal = currVal
	end

	local function HoverAction()
		if ig.IsWindowHovered(imgui.ImGuiHoveredFlags_AllowWhenBlockedByPopup + imgui.ImGuiHoveredFlags_AllowWhenBlockedByActiveItem) then
			if not lastFrameHovered then SetAction(true) end
		elseif lastFrameHovered then
			SetAction(false)
		end
		local fac = actionTime/dur
		fac = actionUP and fac or -fac
		currVal = math.min(1,math.max(0,iniVal + fac))
		actionTime = actionTime + ig.GetIO().DeltaTime
		return minv + range*currVal
	end
	return HoverAction
end

To use it just use the HoverActionFactory as in

-- 0.5 sec transition from 0.001 to 1
local HoverAction = HoverActionFactory(0.5,0.0001,1)

And after ImGui::Begin

ig.PushStyleVarFloat(imgui.ImGuiStyleVar_Alpha, HoverAction())

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the issue's HoverActionFactory proof of concept and the named ImGui::Begin, ImGui::PushStyleVarFloat, ImGui::IsWindowHovered, and ImGui::GetIO entry points. Review how window hover state and style alpha are exposed, then define and validate a reusable transition API whose completion supports fading between the requested minimum and maximum values.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.