void tab_controller_t::invoke() {
int start_x = base.m_window_pos.x + 100;
if (elements.m_tabs.empty())
return;
if (elements.m_cur_tab < 0 || elements.m_cur_tab >= elements.m_tabs.size())
elements.m_cur_tab = 0;
auto& current_tab = elements.m_tabs.at(elements.m_cur_tab);
int subtab_index = *current_tab.m_active;
if (subtab_index < 0 || subtab_index >= current_tab.subtab.size())
subtab_index = 0;
int subtab_start_y = base.m_window_pos.y + 40;
static int last_tab_index = -1;
for (auto& tab : elements.m_tabs) {
auto tab_pos = g_font.verdana.measure_size(tab.m_name);
if (g_utils.in_region(c_vector_2d(start_x, base.m_window_pos.y + 2), c_vector_2d(tab_pos.x, 20)) &&
ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
elements.m_last_tab = elements.m_cur_tab;
elements.m_cur_tab = tab.m_index;
if (elements.m_cur_tab != last_tab_index) {
for (auto& subtab : elements.m_tabs.at(elements.m_cur_tab).subtab)
*subtab.current_index = 0;
*current_tab.m_active = 0;
subtab_index = 0;
current_tab.subtab.at(subtab_index).content();
last_tab_index = elements.m_cur_tab;
}
}
if (tab.m_index == elements.m_cur_tab) {
for (auto& current_subtab : tab.subtab) {
g_render_engine->gradient(base.m_window_pos.x + 17, subtab_start_y, 102, 18,
c_color(17, 17, 17, 255 * g_content.m_window_i_alpha),
c_color(9, 9, 9, 255 * g_content.m_window_i_alpha), e_gradient_flags::vertical);
auto tabulia = g_anim_base.build(current_subtab.name + std::to_string(current_subtab.index) + "#subtab");
tabulia.animate(tabulia.m_value + 3.f * g_anim_base.delta_time(0.5) *
(*current_subtab.current_index == current_subtab.index && g_content.m_window_i_alpha > 0.f ? 1.f : -1.f));
g_render_engine->rect_filled(base.m_window_pos.x + 17, subtab_start_y, 1, 18,
base.m_theme.accent.modify_alpha(125 * g_content.m_window_i_alpha));
g_render_engine->rect_filled(base.m_window_pos.x + 17, subtab_start_y, 1, 18,
base.m_theme.accent.modify_alpha(255 * tabulia.m_value));
if (g_utils.in_region(c_vector_2d(base.m_window_pos.x + 17, subtab_start_y), c_vector_2d(102, 18)) &&
ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
if (*current_subtab.current_index != current_subtab.index) {
*current_subtab.current_index = current_subtab.index;
*tab.m_active = current_subtab.index;
subtab_index = current_subtab.index;
current_tab.subtab.at(subtab_index).content();
}
}
g_font.verdana.string(base.m_window_pos.x + 24, subtab_start_y + 2, current_subtab.name,
c_color(112, 112, 112, 255 * g_content.m_window_i_alpha)
.blend(base.m_theme.accent.modify_alpha(255 * tabulia.m_value), tabulia.m_value));
subtab_start_y += 21 * g_content.m_window_i_alpha;
}
}
auto tab_active = g_anim_base.build(tab.m_name + std::to_string(tab.m_index));
tab_active.animate(tab_active.m_value + 3.f * g_anim_base.delta_time(0.5) *
(tab.m_index == elements.m_cur_tab && g_content.m_window_i_alpha > 0.f ? 1.f : -1.f));
g_font.verdana.string(start_x, base.m_window_pos.y + 4, tab.m_name,
c_color(112, 112, 112, 255 * g_content.m_window_i_alpha)
.blend(base.m_theme.accent.modify_alpha(255 * tab_active.m_value), tab_active.m_value));
start_x += tab_pos.x + 20 * g_content.m_window_i_alpha;
}
if (subtab_index >= 0 && subtab_index < current_tab.subtab.size())
current_tab.subtab.at(subtab_index).content();
}