Files
client/src/gui/indent_section.h
T

43 lines
1.8 KiB
C++

#pragma once
#include <algorithm>
#include <cmath>
#include "imgui.h"
#include "imgui_internal.h"
#include "theme.h"
namespace widgets {
inline float expand_step(float value, bool open, float dt) {
return theme::approach(value, open ? 1.f : 0.f, 1.f-std::exp(-14.f*(std::max)(0.f,dt)));
}
// Measure controls at their natural height, but reserve/clip only the revealed part.
// Keep everything in the category window so its scrolling and widget IDs stay intact.
template<class Render>
void indent_section(float width, float anchor_y, float amount, float& content_height, bool interactive, Render render) {
const auto start=ImGui::GetCursorScreenPos();
auto* window=ImGui::GetCurrentWindow();
const auto old_max=window->DC.CursorMaxPos, old_ideal=window->DC.IdealMaxPos;
const float reveal=content_height*amount;
ImGui::PushClipRect(start,{start.x+width,start.y+reveal},true);
ImGui::PushStyleVar(ImGuiStyleVar_Alpha,ImGui::GetStyle().Alpha*amount);
if (!interactive) ImGui::BeginDisabled();
ImGui::BeginGroup();
ImGui::Indent(14.f);
render((std::max)(1.f,width-14.f));
ImGui::Unindent(14.f);
ImGui::EndGroup();
content_height=ImGui::GetItemRectSize().y;
if (!interactive) ImGui::EndDisabled();
ImGui::PopStyleVar();
ImGui::PopClipRect();
const float height=content_height*amount;
window->DrawList->AddLine({start.x+6.f,anchor_y},{start.x+6.f,start.y+height},
theme::u32(theme::with_alpha(theme::hex(0x141414),amount)),3.f);
// Discard the full measurement's scroll extent, then submit the animated bounds.
window->DC.CursorMaxPos=old_max;
window->DC.IdealMaxPos=old_ideal;
ImGui::SetCursorScreenPos(start);
ImGui::Dummy({width,height});
}
}