ImGui::SetNextWindowSizeConstraints() 不按预期工作

huangapple go评论56阅读模式
英文:

ImGui::SetNextWindowSizeConstraints() not behaving as intended

问题

抱歉,代码部分不要翻译。以下是您要求的翻译内容:

"I'm trying to give my window a minimum size using ImGui::SetNextWindowSizeConstraints and putting it before the Begin() block as documented, like so:

void Widget::draw()
{
  ImGui::SetNextWindowSizeConstraints(ImVec2(500, 500), ImVec2(-1,-1));
  ImGui::SetNextWindowBgAlpha(m_opacity);
  
  if (ImGui::Begin("widget", true, ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoFocusOnAppearing))
  {
     //code for window here
  }
  ImGui::End();
}

Unfortunately, when I try to minimize my window, it still becomes smaller than the min_size of 500 pixels. Any idea why that might be happening?"

英文:

I'm trying to give my window a minimum size using ImGui::SetNextWindowSizeConstraints and putting it before the Begin() block as documented, like so:

void Widget::draw()
{
  ImGui::SetNextWindowSizeConstraints(ImVec2(500, 500), ImVec2(-1,-1));
  ImGui::SetNextWindowBgAlpha(m_opacity);
  
  if (ImGui::Begin("widget", true, ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoFocusOnAppearing))
  {
     //code for window here
  }
  ImGui::End();
}

Unfortunately, when I try to minimize my window, it still becomes smaller than the min_size of 500 pixels. Any idea why that might be happening?

答案1

得分: 1

我意识到这是因为我的窗口被停靠,而SetNextWindowSizeConstraints不适用于停靠的窗口。我找到的一个解决方法是在Begin()End()块之间使用以下代码:

ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(500, 500));

英文:

I realized this is because my windows were docked, and SetNextWindowSizeConstraints doesn't apply to docked windows. A workaround I've found is to use this code between the Begin() and End() blocks:

ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(500, 500));

huangapple
  • 本文由 发表于 2023年7月12日 22:46:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76671834.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定