mirror of
https://github.com/ocornut/imgui.git
synced 2026-01-18 01:14:19 +00:00
Add minimize/maximize window flags
TODO: actual work of rendering window
This commit is contained in:
parent
a2366f9022
commit
dd15544751
4 changed files with 143 additions and 0 deletions
60
imgui.cpp
60
imgui.cpp
|
|
@ -6470,6 +6470,8 @@ void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& titl
|
|||
|
||||
const bool has_close_button = (p_open != NULL);
|
||||
const bool has_collapse_button = !(flags & ImGuiWindowFlags_NoCollapse) && (style.WindowMenuButtonPosition != ImGuiDir_None);
|
||||
const bool has_minimize_button = flags & ImGuiWindowFlags_Minimize;
|
||||
const bool has_maximize_button = flags & ImGuiWindowFlags_Maximize;
|
||||
|
||||
// Close & Collapse button are on the Menu NavLayer and don't default focus (unless there's nothing else on that layer)
|
||||
// FIXME-NAV: Might want (or not?) to set the equivalent of ImGuiButtonFlags_NoNavFocus so that mouse clicks on standard title bar items don't necessarily set nav/keyboard ref?
|
||||
|
|
@ -6483,12 +6485,24 @@ void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& titl
|
|||
float pad_r = style.FramePadding.x;
|
||||
float button_sz = g.FontSize;
|
||||
ImVec2 close_button_pos;
|
||||
ImVec2 minimize_button_pos;
|
||||
ImVec2 maximize_button_pos;
|
||||
ImVec2 collapse_button_pos;
|
||||
if (has_close_button)
|
||||
{
|
||||
close_button_pos = ImVec2(title_bar_rect.Max.x - pad_r - button_sz, title_bar_rect.Min.y + style.FramePadding.y);
|
||||
pad_r += button_sz + style.ItemInnerSpacing.x;
|
||||
}
|
||||
if (has_maximize)
|
||||
{
|
||||
maximize_button_pos = ImVec2(title_bar_rect.Max.x - pad_r - button_sz, title_bar_rect.Min.y + style.FramePadding.y);
|
||||
pad_r += button_sz + style.ItemInnerSpacing.x;
|
||||
}
|
||||
if (has_minimize)
|
||||
{
|
||||
minimize_button_pos = ImVec2(title_bar_rect.Max.x - pad_r - button_sz, title_bar_rect.Min.y + style.FramePadding.y);
|
||||
pad_r += button_sz + style.ItemInnerSpacing.x;
|
||||
}
|
||||
if (has_collapse_button && style.WindowMenuButtonPosition == ImGuiDir_Right)
|
||||
{
|
||||
collapse_button_pos = ImVec2(title_bar_rect.Max.x - pad_r - button_sz, title_bar_rect.Min.y + style.FramePadding.y);
|
||||
|
|
@ -6510,6 +6524,20 @@ void ImGui::RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& titl
|
|||
if (CloseButton(window->GetID("#CLOSE"), close_button_pos))
|
||||
*p_open = false;
|
||||
|
||||
// Maximize button
|
||||
if (has_maximize_button) {
|
||||
if (CloseButton(window->GetID("#MAXIMIZE"), maximize_button_pos, window->Maximized)) {
|
||||
window->WantMaximizeToggle = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Minimize button
|
||||
if (has_minimize_button) {
|
||||
if (CloseButton(window->GetID("#MINIMIZE"), minimize_button_pos, window->Minimized)) {
|
||||
window->WantMinimizeToggle = true;
|
||||
}
|
||||
}
|
||||
|
||||
window->DC.NavLayerCurrent = ImGuiNavLayer_Main;
|
||||
g.CurrentItemFlags = item_flags_backup;
|
||||
|
||||
|
|
@ -6924,6 +6952,26 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|||
}
|
||||
window->WantCollapseToggle = false;
|
||||
|
||||
if (flags & ImGuiWindowFlags_Maximize) {
|
||||
if (window->WantMaximizeToggle) {
|
||||
window->Maximized = !window->Maximized;
|
||||
MarkIniSettingsDirty(window);
|
||||
}
|
||||
} else {
|
||||
window->Maximized = false;
|
||||
}
|
||||
window->WantMaximizeToggle = false;
|
||||
|
||||
if (flags & ImGuiWindowFlags_Minimize) {
|
||||
if (window->WantMinimizeToggle) {
|
||||
window->Minimized = !window->Minimized;
|
||||
MarkIniSettingsDirty(window);
|
||||
}
|
||||
} else {
|
||||
window->Minimized = false;
|
||||
}
|
||||
window->WantMinimizeToggle = false;
|
||||
|
||||
// SIZE
|
||||
|
||||
// Outer Decoration Sizes
|
||||
|
|
@ -8033,6 +8081,18 @@ bool ImGui::IsWindowCollapsed()
|
|||
return window->Collapsed;
|
||||
}
|
||||
|
||||
bool ImGui::IsWindowMinimized()
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindowRead();
|
||||
return window->Minimized;
|
||||
}
|
||||
|
||||
bool ImGui::IsWindowMaximized()
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindowRead();
|
||||
return window->Maximized;
|
||||
}
|
||||
|
||||
bool ImGui::IsWindowAppearing()
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindowRead();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue