Skip to content

Commit 864fb24

Browse files
committed
unbreak DPI modification, clean up window widths
1 parent 76b69ad commit 864fb24

File tree

2 files changed

+41
-15
lines changed

2 files changed

+41
-15
lines changed

include/polyscope/polyscope.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ void drawStructuresDelayed();
200200
// Called to check any options that might have been changed and perform appropriate updates. Users generally should not
201201
// need to call this directly.
202202
void processLazyProperties();
203+
void processLazyPropertiesOutsideOfImGui();
203204

204205

205206
} // namespace polyscope

src/polyscope.cpp

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ bool unshowRequested = false;
4848
float imguiStackMargin = 10;
4949
float lastWindowHeightPolyscope = 200;
5050
float lastWindowHeightUser = 200;
51-
constexpr float LEFT_WINDOWS_WIDTH = 305;
52-
constexpr float RIGHT_WINDOWS_WIDTH = 500;
53-
float leftWindowsWidth = LEFT_WINDOWS_WIDTH;
54-
float rightWindowsWidth = RIGHT_WINDOWS_WIDTH;
51+
constexpr float INITIAL_LEFT_WINDOWS_WIDTH = 305;
52+
constexpr float INITIAL_RIGHT_WINDOWS_WIDTH = 500;
53+
float leftWindowsWidth = -1.;
54+
float rightWindowsWidth = -1.;
5555

5656
auto lastMainLoopIterTime = std::chrono::steady_clock::now();
5757

@@ -133,6 +133,17 @@ void writePrefsFile() {
133133
o << std::setw(4) << prefsJSON << std::endl;
134134
}
135135

136+
void setInitialWindowWidths() {
137+
leftWindowsWidth = INITIAL_LEFT_WINDOWS_WIDTH * options::uiScale;
138+
rightWindowsWidth = INITIAL_RIGHT_WINDOWS_WIDTH * options::uiScale;
139+
}
140+
141+
void ensureWindowWidthsSet() {
142+
if (leftWindowsWidth <= 0. || rightWindowsWidth <= 0.) {
143+
setInitialWindowWidths();
144+
}
145+
}
146+
136147
// Helper to get a structure map
137148

138149
std::map<std::string, std::unique_ptr<Structure>>& getStructureMapCreateIfNeeded(std::string typeName) {
@@ -539,6 +550,7 @@ void purgeWidgets() {
539550
}
540551

541552
void userGuiBegin() {
553+
ensureWindowWidthsSet();
542554

543555
ImVec2 userGuiLoc;
544556
if (options::userGuiIsOnRightSide) {
@@ -563,7 +575,7 @@ void userGuiBegin() {
563575
void userGuiEnd() {
564576

565577
if (options::userGuiIsOnRightSide) {
566-
rightWindowsWidth = RIGHT_WINDOWS_WIDTH * options::uiScale;
578+
rightWindowsWidth = INITIAL_RIGHT_WINDOWS_WIDTH * options::uiScale;
567579
lastWindowHeightUser = imguiStackMargin + ImGui::GetWindowHeight();
568580
} else {
569581
lastWindowHeightUser = 0;
@@ -575,6 +587,7 @@ void userGuiEnd() {
575587
} // namespace
576588

577589
void buildPolyscopeGui() {
590+
ensureWindowWidthsSet();
578591

579592
// Create window
580593
static bool showPolyscopeWindow = true;
@@ -688,12 +701,14 @@ void buildPolyscopeGui() {
688701

689702

690703
lastWindowHeightPolyscope = imguiStackMargin + ImGui::GetWindowHeight();
691-
leftWindowsWidth = LEFT_WINDOWS_WIDTH * options::uiScale;
704+
leftWindowsWidth = ImGui::GetWindowWidth();
692705

693706
ImGui::End();
694707
}
695708

696709
void buildStructureGui() {
710+
ensureWindowWidthsSet();
711+
697712
// Create window
698713
static bool showStructureWindow = true;
699714

@@ -757,12 +772,14 @@ void buildStructureGui() {
757772
ImGui::PopID();
758773
}
759774

760-
leftWindowsWidth = LEFT_WINDOWS_WIDTH * options::uiScale;
775+
leftWindowsWidth = ImGui::GetWindowWidth();
761776

762777
ImGui::End();
763778
}
764779

765780
void buildPickGui() {
781+
ensureWindowWidthsSet();
782+
766783
if (haveSelection()) {
767784

768785
ImGui::SetNextWindowPos(ImVec2(view::windowWidth - (rightWindowsWidth + imguiStackMargin),
@@ -789,7 +806,7 @@ void buildPickGui() {
789806
ImGui::TextUnformatted("ERROR: INVALID STRUCTURE");
790807
}
791808

792-
rightWindowsWidth = RIGHT_WINDOWS_WIDTH * options::uiScale;
809+
rightWindowsWidth = ImGui::GetWindowWidth();
793810
ImGui::End();
794811
}
795812
}
@@ -901,6 +918,7 @@ void draw(bool withUI, bool withContextCallback) {
901918
void mainLoopIteration() {
902919

903920
processLazyProperties();
921+
processLazyPropertiesOutsideOfImGui();
904922

905923
render::engine->makeContextCurrent();
906924
render::engine->updateWindowSize();
@@ -1277,7 +1295,9 @@ void processLazyProperties() {
12771295
//
12781296
// This function is a workaround which polls for changes to options settings, and performs any necessary additional
12791297
// work.
1280-
1298+
//
1299+
// There is a second function processLazyPropertiesOutsideOfImGui() which handles a few more that can only be set
1300+
// at limited times when an ImGui frame is not active.
12811301

12821302
// transparency mode
12831303
if (lazy::transparencyMode != options::transparencyMode) {
@@ -1297,12 +1317,6 @@ void processLazyProperties() {
12971317
render::engine->setSSAAFactor(options::ssaaFactor);
12981318
}
12991319

1300-
// uiScale
1301-
if (lazy::uiScale != options::uiScale) {
1302-
lazy::uiScale = options::uiScale;
1303-
render::engine->configureImGui();
1304-
}
1305-
13061320
// ground plane
13071321
if (lazy::groundPlaneEnabled != options::groundPlaneEnabled || lazy::groundPlaneMode != options::groundPlaneMode) {
13081322
lazy::groundPlaneEnabled = options::groundPlaneEnabled;
@@ -1328,6 +1342,17 @@ void processLazyProperties() {
13281342
}
13291343
};
13301344

1345+
void processLazyPropertiesOutsideOfImGui() {
1346+
// Like processLazyProperties, but this one handles properties which cannot be changed mid-ImGui frame
1347+
1348+
// uiScale
1349+
if (lazy::uiScale != options::uiScale) {
1350+
lazy::uiScale = options::uiScale;
1351+
render::engine->configureImGui();
1352+
setInitialWindowWidths();
1353+
}
1354+
}
1355+
13311356
void updateStructureExtents() {
13321357

13331358
if (!options::automaticallyComputeSceneExtents) {

0 commit comments

Comments
 (0)