-
Автор темы
- #1
hi
can anyone help me to make my legendware menu horizontal?
its vertical by default
i dont know how to work with imgui
just give me a little help i dont want to get spoon fooded XD
i know about coding
this is the maintab function
can anyone help me to make my legendware menu horizontal?
its vertical by default
i dont know how to work with imgui
just give me a little help i dont want to get spoon fooded XD
i know about coding
this is the maintab function
C++:
bool ImGui::MainTab(const char* label, ImFont* icon_font, const char* icon, bool active, const ImVec2& size_arg, ImGuiButtonFlags flags)
{
ImGuiWindow* window = GetCurrentWindow();
if (window->SkipItems)
return false;
ImGuiContext& g = *GImGui;
const ImGuiStyle& style = g.Style;
const ImGuiID id = window->GetID(label);
const ImVec2 label_size = CalcTextSize(label, NULL, true);
const ImVec2 icon_size = CalcTextSize(icon, NULL, true);
ImVec2 pos = window->DC.CursorPos;
if ((flags & ImGuiButtonFlags_AlignTextBaseLine) && style.FramePadding.y < window->DC.CurrLineTextBaseOffset) // Try to vertically align buttons that are smaller/have no padding so that text baseline matches (bit hacky, since it shouldn't be a flag)
pos.y += window->DC.CurrLineTextBaseOffset - style.FramePadding.y;
ImVec2 size = CalcItemSize(size_arg, label_size.x + style.FramePadding.x * 2.0f, label_size.y + style.FramePadding.y * 2.0f);
const ImRect bb(pos, pos + size);
ItemSize(size, style.FramePadding.y);
if (!ItemAdd(bb, id))
return false;
if (window->DC.ItemFlags & ImGuiItemFlags_ButtonRepeat)
flags |= ImGuiButtonFlags_Repeat;
bool hovered, held;
bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags);
// Render
const ImVec4 text_dis = ImVec4(10 / 255.f, 10 / 255.f, 10 / 255.f, 1.f);
const ImVec4 text_act = ImVec4(207 / 255.f, 66 / 255.f, 66 / 255.f, 1.f);
const ImVec4 icon_dis = ImVec4(10 / 255.f, 10 / 255.f, 10 / 255.f, 1.f);
const ImVec4 icon_act = ImVec4(207 / 255.f, 66 / 255.f, 66 / 255.f, 1.f);
float deltatime = 1.5f * ImGui::GetIO().DeltaTime;
static std::map<ImGuiID, ImVec4> text_animation;
auto it_text = text_animation.find(id);
if (it_text == text_animation.end())
{
text_animation.insert({ id, text_dis });
it_text = text_animation.find(id);
}
if (hovered || active)
{
ImVec4 to = text_act;
if (it_text->second.x != to.x)
{
if (it_text->second.x < to.x)
it_text->second.x = ImMin(it_text->second.x + deltatime, to.x);
else if (it_text->second.x > to.x)
it_text->second.x = ImMax(to.x, it_text->second.x - deltatime);
}
if (it_text->second.y != to.y)
{
if (it_text->second.y < to.y)
it_text->second.y = ImMin(it_text->second.y + deltatime, to.y);
else if (it_text->second.y > to.y)
it_text->second.y = ImMax(to.y, it_text->second.y - deltatime);
}
if (it_text->second.z != to.z)
{
if (it_text->second.z < to.z)
it_text->second.z = ImMin(it_text->second.z + deltatime, to.z);
else if (it_text->second.z > to.z)
it_text->second.z = ImMax(to.z, it_text->second.z - deltatime);
}
}
else
{
ImVec4 to = text_dis;
if (it_text->second.x != to.x)
{
if (it_text->second.x < to.x)
it_text->second.x = ImMin(it_text->second.x + deltatime, to.x);
else if (it_text->second.x > to.x)
it_text->second.x = ImMax(to.x, it_text->second.x - deltatime);
}
if (it_text->second.y != to.y)
{
if (it_text->second.y < to.y)
it_text->second.y = ImMin(it_text->second.y + deltatime, to.y);
else if (it_text->second.y > to.y)
it_text->second.y = ImMax(to.y, it_text->second.y - deltatime);
}
if (it_text->second.z != to.z)
{
if (it_text->second.z < to.z)
it_text->second.z = ImMin(it_text->second.z + deltatime, to.z);
else if (it_text->second.z > to.z)
it_text->second.z = ImMax(to.z, it_text->second.z - deltatime);
}
}
static std::map<ImGuiID, ImVec4> icon_animation;
auto it_icon = icon_animation.find(id);
if (it_icon == icon_animation.end())
{
icon_animation.insert({ id, icon_dis });
it_icon = icon_animation.find(id);
}
if (active)
{
ImVec4 to = icon_act;
if (it_icon->second.x != to.x)
{
if (it_icon->second.x < to.x)
it_icon->second.x = ImMin(it_icon->second.x + deltatime, to.x);
else if (it_icon->second.x > to.x)
it_icon->second.x = ImMax(to.x, it_icon->second.x - deltatime);
}
if (it_icon->second.y != to.y)
{
if (it_icon->second.y < to.y)
it_icon->second.y = ImMin(it_icon->second.y + deltatime, to.y);
else if (it_icon->second.y > to.y)
it_icon->second.y = ImMax(to.y, it_icon->second.y - deltatime);
}
if (it_icon->second.z != to.z)
{
if (it_icon->second.z < to.z)
it_icon->second.z = ImMin(it_icon->second.z + deltatime, to.z);
else if (it_icon->second.z > to.z)
it_icon->second.z = ImMax(to.z, it_icon->second.z - deltatime);
}
}
else
{
ImVec4 to = icon_dis;
if (it_icon->second.x != to.x)
{
if (it_icon->second.x < to.x)
it_icon->second.x = ImMin(it_icon->second.x + deltatime, to.x);
else if (it_icon->second.x > to.x)
it_icon->second.x = ImMax(to.x, it_icon->second.x - deltatime);
}
if (it_icon->second.y != to.y)
{
if (it_icon->second.y < to.y)
it_icon->second.y = ImMin(it_icon->second.y + deltatime, to.y);
else if (it_icon->second.y > to.y)
it_icon->second.y = ImMax(to.y, it_icon->second.y - deltatime);
}
if (it_icon->second.z != to.z)
{
if (it_icon->second.z < to.z)
it_icon->second.z = ImMin(it_icon->second.z + deltatime, to.z);
else if (it_icon->second.z > to.z)
it_icon->second.z = ImMax(to.z, it_icon->second.z - deltatime);
}
}
PushStyleColor(ImGuiCol_Text, it_icon->second);
PushFont(icon_font);
RenderTextClipped(bb.Min + ImVec2(size_arg.x * 0.05f, -3 * c_menu::get().dpi_scale), bb.Max, icon, NULL, &icon_size, ImVec2(0.f, 0.27f), &bb);
PopFont();
PopStyleColor();
PushStyleColor(ImGuiCol_Text, it_text->second);
RenderTextClipped(bb.Min + ImVec2(size_arg.x * 0.33f, (4 * c_menu::get().dpi_scale) - 4), bb.Max, label, NULL, &label_size, ImVec2(0.f, 0.41f), &bb);
PopStyleColor();
// Automatically close popups
//if (pressed && !(flags & ImGuiButtonFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup))
// CloseCurrentPopup();
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.LastItemStatusFlags);
return pressed;
}