Something went wrong. Try again.
art software for the rest of us
drawing paint image sdl art
Something went wrong. Try again.
C++
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495#include "Panel.h"#include "../ManagementContext/StyleManagmentContext.h"#include "../ImGui.h"#include "MaterialIcons.h"#include "../ManagementContext/PanelManagementContext.h"#include <imgui.h>
bool Panel::beginCustomWindow(std::string title){ if (state == DETACHED && PanelManagementContext::GetMode() != DEFAULT) { return false; } if (!ImGui::Begin(title.c_str(), (bool*)&state, ImGuiWindowFlags_NoTitleBar | (state == DETACHED ? 0 : ImGuiWindowFlags_NoResize))) { ImGui::End(); return false; } isWindowActive = ImGui::IsItemActive(); ImGui::Text(title.c_str(), nullptr); ImGui::SameLine(); ImGui::PushFont(DearImGuiApp::MaterialIcons, 24.0f); StyleManagmentContext::Push(NOBORDER);
ImVec2 cursor = ImGui::GetCursorScreenPos(); ImVec2 avail = ImGui::GetContentRegionAvail(); cursor.x += avail.x - 72.0f; cursor.y -= 2.0f;
ImGui::SetCursorScreenPos(cursor); if (state == OPEN) { if (ImGui::SmallButton(ICON_MS_OPEN_IN_NEW)) { state = DETACHED; PanelManagementContext::PopMode(); } ImGui::SameLine(); // Detach } else { if (ImGui::SmallButton(ICON_MS_REOPEN_WINDOW)) { state = OPEN; PanelManagementContext::PushMode(CONFIGURE); } ImGui::SameLine(); // Reattach }
cursor.x += 36.0f; ImGui::SetCursorScreenPos(cursor); if (ImGui::SmallButton(ICON_MS_CLOSE)) { PanelManagementContext::Close(this); } cursor = ImGui::GetCursorScreenPos(); cursor.y -= 2.0f; ImGui::SetCursorScreenPos(cursor); StyleManagmentContext::Pop(); ImGui::PopFont(); StyleManagmentContext::Push(BASECONTENTS); ImGui::SetNextWindowSize(ImGui::GetContentRegionAvail(), ImGuiCond_None); if (!ImGui::BeginChild((title + "Contents").c_str(), ImVec2(0, 0), ImGuiChildFlags_AutoResizeX | ImGuiChildFlags_AutoResizeY | ImGuiChildFlags_Borders | ImGuiChildFlags_NavFlattened)) { ImGui::EndChild(); StyleManagmentContext::Pop(); return false; } return true;}
void Panel::endCustomWindow(){ if (state == OPEN && ImGui::IsMouseReleased(ImGuiMouseButton_Left) && !ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows)) { PanelManagementContext::Close(this); } if (state == OPEN && ImGui::IsMouseDragging(ImGuiMouseButton_Left) && isWindowActive && ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows)) { state = DETACHED; PanelManagementContext::PopMode(); } ImGui::EndChild(); StyleManagmentContext::Pop(); ImGui::End();}
void Panel::Toggle(){ switch (state) { case CLOSED: state = OPEN; break; default: case OPEN: state = CLOSED; break; }}
PanelState Panel::GetState(){ return state;}