Skip to content

Commit

Permalink
If AutoResize is going to be used for a window we now explicitly set …
Browse files Browse the repository at this point in the history
…NoScrollbar. Furthermore we now don't use GetWindowContentRegionMax to position buttons on the right when using AutoResize because it can cause a loop. However if the width is set explicitly before the Begin, the content region can be used as the AutoResize cannot affect the width. Cleaned up more of the UI modals and made their title-bar style/sizing consistent.
  • Loading branch information
bluescan committed Oct 5, 2023
1 parent 34f95f2 commit e3f21a4
Show file tree
Hide file tree
Showing 15 changed files with 198 additions and 117 deletions.
16 changes: 10 additions & 6 deletions Src/ColourDialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ void Viewer::ShowPixelEditorOverlay(bool* popen)
{
tVector2 windowPos = GetDialogOrigin(DialogID::PixelEditor);
ImGui::SetNextWindowPos(windowPos, ImGuiCond_FirstUseEver);

// I imagine NoResize is implied by AlwaysAutoResize. However I have seen cases where
// a scrollbar width gets reserved even with AutoResize is on. This is why we're using
// NoScrollBar every time we use AutoResize.
ImGuiWindowFlags flags =
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize |
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing |
ImGuiWindowFlags_NoNav;
ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoScrollbar;

static bool live = true;
static tColourf floatCol = tColourf::black;
Expand Down Expand Up @@ -141,7 +145,7 @@ void Viewer::ShowChannelFilterOverlay(bool* popen)
ImGui::SetNextWindowPos(windowPos, ImGuiCond_FirstUseEver);
ImGuiWindowFlags flags =
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize |
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoNav;
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoScrollbar;

if (ImGui::Begin("Channel Filter", popen, flags))
{
Expand Down Expand Up @@ -330,7 +334,7 @@ void Viewer::DoLevelsModal(bool levelsPressed)
}

bool isOpenLevels = true;
if (!ImGui::BeginPopupModal("Adjust Levels", &isOpenLevels, ImGuiWindowFlags_AlwaysAutoResize))
if (!ImGui::BeginPopupModal("Adjust Levels", &isOpenLevels, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoScrollbar))
{
if (popupOpen)
{
Expand Down Expand Up @@ -630,10 +634,10 @@ void Viewer::DoLevelsModal(bool levelsPressed)
Viewer::SetWindowTitle();
ImGui::CloseCurrentPopup();
}

ImGui::SameLine();

ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x - buttonWidth);

float okOffset = Viewer::GetUIParamScaled(264.0f, 2.5f);
ImGui::SetCursorPosX(okOffset);
if (ImGui::IsWindowAppearing())
ImGui::SetKeyboardFocusHere();
if (Viewer::Button("OK", tVector2(buttonWidth, 0.0f)))
Expand Down
14 changes: 9 additions & 5 deletions Src/ContactSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ void Viewer::DoSaveContactSheetModal(bool saveContactSheetPressed)

// The unused isOpenContactSheet bool is just so we get a close button in ImGui. Returns false if popup not open.
bool isOpenContactSheet = true;
if (!ImGui::BeginPopupModal("Contact Sheet", &isOpenContactSheet, ImGuiWindowFlags_AlwaysAutoResize))
if (!ImGui::BeginPopupModal("Contact Sheet", &isOpenContactSheet, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoScrollbar))
return;

const ImGuiStyle& style = ImGui::GetStyle();
static int frameWidth = 256;
static int frameHeight = 256;
static bool anyImageNeedsResize = false;
Expand Down Expand Up @@ -143,7 +144,8 @@ void Viewer::DoSaveContactSheetModal(bool saveContactSheetPressed)
ImGui::SameLine();
if (ImGui::Button(hi, powSize))
frameHeight = hiP2H;
ImGui::SameLine(); ShowHelpMark("Single frame height in pixels.");
ImGui::SameLine();
ShowHelpMark("Single frame height in pixels.");

ImGui::SetNextItemWidth(itemWidth);
ImGui::InputInt("Columns", &numCols);
Expand Down Expand Up @@ -267,10 +269,12 @@ void Viewer::DoSaveContactSheetModal(bool saveContactSheetPressed)
ImGui::CloseCurrentPopup();
ImGui::SameLine();

ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x - buttonWidth);

tString outFile = destDir + tString(filename) + extensionWithDot;
bool closeThisModal = false;

float genButOffset = Viewer::GetUIParamScaled(324.0f, 2.5f);
ImGui::SetCursorPosX(genButOffset);

if (ImGui::IsWindowAppearing())
ImGui::SetKeyboardFocusHere();
if (Viewer::Button("Generate", tVector2(buttonWidth, 0.0f)) && (numImg >= 2))
Expand Down Expand Up @@ -298,7 +302,7 @@ void Viewer::DoSaveContactSheetModal(bool saveContactSheetPressed)

// The unused isOpen bool is just so we get a close button in ImGui.
bool isOpen = true;
if (ImGui::BeginPopupModal("Overwrite Contact Sheet File", &isOpen, ImGuiWindowFlags_AlwaysAutoResize))
if (ImGui::BeginPopupModal("Overwrite Contact Sheet File", &isOpen, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoScrollbar))
{
bool pressedOK = false, pressedCancel = false;
DoOverwriteFileModal(outFile, pressedOK, pressedCancel);
Expand Down
2 changes: 1 addition & 1 deletion Src/Crop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ void Viewer::ShowCropPopup(const tVector4& lrtb, const tVector2& uvoffset)
ImGuiWindowFlags flags =
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize |
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing |
ImGuiWindowFlags_NoNav;
ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoScrollbar;

if (ImGui::Begin("Crop", &CropMode, flags))
{
Expand Down
4 changes: 2 additions & 2 deletions Src/Details.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ void Viewer::ShowImageMetaDataOverlay(bool* popen)

ImGui::SetNextWindowPos(windowPos, ImGuiCond_Appearing);
ImGuiWindowFlags flags =
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav;
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoScrollbar |
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav;

if (ImGui::Begin("Meta Data", popen, flags))
{
Expand Down
97 changes: 68 additions & 29 deletions Src/Dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,29 +113,52 @@ void Viewer::DoDeleteFileModal(bool deleteFilePressed)

// The unused isOpenDeleteFile bool is just so we get a close button in ImGui.
bool isOpenDeleteFile = true;
if (!ImGui::BeginPopupModal("Delete File", &isOpenDeleteFile, ImGuiWindowFlags_AlwaysAutoResize))
if (!ImGui::BeginPopupModal("Delete File", &isOpenDeleteFile, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoScrollbar))
return;

float buttonWidth = Viewer::GetUIParamScaled(76.0f, 2.5f);
tString fullname = CurrImage->Filename;
tString file = tSystem::tGetFileName(fullname);
tString dir = tSystem::tGetDir(fullname);

// @wip
// Create a function based on the stuff in CalcTextSize that crops a string
// to a particular size based on the current font/scale. Something like
// tString CropStringToWidth(const tString& src, int width, bool ellipsis = true, bool keepStart = true)
// If ellipsis is true the returned string may strt or end with "...". The total width of the
// returned string (including the ellipsis) fits in width. If ellipsis is false it may fit a few more
// characters. If keepStart is true, the start of src will always be kept and the ellipsis, if requested
// and required, will be at the end. If keepStart is false, the end of src will always be kept, and the
// ellipsis, if requested and required, will be at the start of src. Could also support middle ellipsis.
//
// float maxPathWidth = Viewer::GetUIParamScaled(327.0f, 2.5f);
// float fileWidth = ImGui::CalcTextSize(file.Chr()).x;
// if (fileWidth > maxPathWidth)

ImGui::Text("Delete File");
ImGui::Indent(); ImGui::Text("%s", file.Chr()); ImGui::Unindent();
ImGui::Indent();
ImGui::Text("%s", file.Chr());
ImGui::Unindent();

ImGui::Text("In Folder");
ImGui::Indent(); ImGui::Text("%s", dir.Chr()); ImGui::Unindent();
ImGui::NewLine();
ImGui::Indent();
ImGui::Text("%s", dir.Chr());
ImGui::Unindent();

ImGuiStyle& style = ImGui::GetStyle();
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + style.ItemSpacing.y);
ImGui::Separator();

ImGui::NewLine();
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + style.ItemSpacing.y);
ImGui::Checkbox("Confirm file deletions in the future?", &profile.ConfirmDeletes);
ImGui::NewLine();
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + style.ItemSpacing.y);

if (Viewer::Button("Cancel", tVector2(buttonWidth, 0.0f)))
ImGui::CloseCurrentPopup();

ImGui::SameLine();
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x - buttonWidth);
float okOffset = Viewer::GetUIParamScaled(300.0f, 2.5f);
ImGui::SetCursorPosX(okOffset);

if (ImGui::IsWindowAppearing())
ImGui::SetKeyboardFocusHere();
Expand All @@ -156,7 +179,7 @@ void Viewer::DoDeleteFileNoRecycleModal(bool deleteFileNoRecycPressed)

// The unused isOpenPerm bool is just so we get a close button in ImGui.
bool isOpenPerm = true;
if (!ImGui::BeginPopupModal("Delete File Permanently", &isOpenPerm, ImGuiWindowFlags_AlwaysAutoResize))
if (!ImGui::BeginPopupModal("Delete File Permanently", &isOpenPerm, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoScrollbar))
return;

float buttonWidth = Viewer::GetUIParamScaled(76.0f, 2.5f);
Expand All @@ -165,22 +188,31 @@ void Viewer::DoDeleteFileNoRecycleModal(bool deleteFileNoRecycPressed)
tString file = tSystem::tGetFileName(fullname);
tString dir = tSystem::tGetDir(fullname);
ImGui::Text("Delete File");
ImGui::Indent(); ImGui::Text("%s", file.Chr()); ImGui::Unindent();
ImGui::Indent();
ImGui::Text("%s", file.Chr());
ImGui::Unindent();

ImGui::Text("In Folder");
ImGui::Indent(); ImGui::Text("%s", dir.Chr()); ImGui::Unindent();
ImGui::NewLine();
ImGui::Indent();
ImGui::Text("%s", dir.Chr());
ImGui::Unindent();

ImGuiStyle& style = ImGui::GetStyle();
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + style.ItemSpacing.y);
ImGui::Separator();
ImGui::NewLine();
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + style.ItemSpacing.y);

ImGui::Text("This operation cannot be undone. The file\nwill be deleted permanently.");
ImGui::NewLine();
ImGui::Text("This cannot be undone. File deletion will be permanent.");
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 2.0f*style.ItemSpacing.y);

if (Viewer::Button("Cancel", tVector2(buttonWidth, 0.0f)))
ImGui::CloseCurrentPopup();

ImGui::SetItemDefaultFocus();
ImGui::SameLine();
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x - buttonWidth);

float okOffset = Viewer::GetUIParamScaled(300.0f, 2.5f);
ImGui::SetCursorPosX(okOffset);

if (ImGui::IsWindowAppearing())
ImGui::SetKeyboardFocusHere();
Expand All @@ -197,16 +229,16 @@ void Viewer::DoDeleteFileNoRecycleModal(bool deleteFileNoRecycPressed)
void Viewer::DoSnapMessageNoFileBrowseModal(bool justPressed)
{
if (justPressed)
ImGui::OpenPopup("Message_NoFileBrowse");
ImGui::OpenPopup("Snap Message##NoFileBrowse");

// The unused isMessage bool is just so we get a close button in ImGui. Returns false if popup not open.
bool isMessage = true;
if
(
!ImGui::BeginPopupModal
(
"Message_NoFileBrowse", &isMessage,
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove
"Snap Message##NoFileBrowse", &isMessage,
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize
)
)
{
Expand All @@ -218,11 +250,14 @@ void Viewer::DoSnapMessageNoFileBrowseModal(bool justPressed)
(
"The Snap version of Tacent View does not\n"
"support opening Nautilus or Dolphin.\n\n"
"Please use the deb install or compile if\n"
"you need the feature on Linux."
"Please use the deb install or build from\n"
"source if you need this feature on Linux."
);
ImGui::NewLine();
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x - buttonWidth);

float okOffset = Viewer::GetUIParamScaled(170.0f, 2.5f);
ImGui::SetCursorPosX(okOffset);

if (ImGui::Button("OK", tVector2(buttonWidth, 0.0f)))
ImGui::CloseCurrentPopup();

Expand All @@ -233,16 +268,16 @@ void Viewer::DoSnapMessageNoFileBrowseModal(bool justPressed)
void Viewer::DoSnapMessageNoFrameTransModal(bool justPressed)
{
if (justPressed)
ImGui::OpenPopup("Message_NoFrameTrans");
ImGui::OpenPopup("Snap Message##NoTransparentWorkArea");

// The unused isMessage bool is just so we get a close button in ImGui. Returns false if popup not open.
bool isMessage = true;
if
(
!ImGui::BeginPopupModal
(
"Message_NoFrameTrans", &isMessage,
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove
"Snap Message##NoTransparentWorkArea", &isMessage,
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize
)
)
{
Expand All @@ -254,11 +289,13 @@ void Viewer::DoSnapMessageNoFrameTransModal(bool justPressed)
(
"The Snap version of Tacent View does not\n"
"support transparent work area.\n\n"
"Please use the deb install or compile if\n"
"you need the feature on Linux."
"Please use the deb install or build from\n"
"source if you need this feature on Linux."
);
ImGui::NewLine();
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x - buttonWidth);

float okOffset = Viewer::GetUIParamScaled(170.0f, 2.5f);
ImGui::SetCursorPosX(okOffset);
if (ImGui::Button("OK", tVector2(buttonWidth, 0.0f)))
ImGui::CloseCurrentPopup();

Expand All @@ -273,7 +310,7 @@ void Viewer::DoRenameModal(bool renamePressed)

// The unused isOpenRen bool is just so we get a close button in ImGui.
bool isOpenRen = true;
if (!ImGui::BeginPopupModal("Rename File", &isOpenRen, ImGuiWindowFlags_AlwaysAutoResize))
if (!ImGui::BeginPopupModal("Rename File", &isOpenRen, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoScrollbar))
return;

float buttonWidth = Viewer::GetUIParamScaled(76.0f, 2.5f);
Expand All @@ -293,7 +330,9 @@ void Viewer::DoRenameModal(bool renamePressed)
ImGui::CloseCurrentPopup();

ImGui::SameLine();
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x - buttonWidth);

float okOffset = Viewer::GetUIParamScaled(165.0f, 2.5f);
ImGui::SetCursorPosX(okOffset);

if (ImGui::IsWindowAppearing())
ImGui::SetKeyboardFocusHere();
Expand Down
Loading

0 comments on commit e3f21a4

Please sign in to comment.