Skip to content

Commit ade0a88

Browse files
committed
fix #567, plot aspect ratio can differ from that requested
1 parent f6e4000 commit ade0a88

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

QtSLiM/QtSLiMWindow.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5034,6 +5034,40 @@ QtSLiMGraphView_CustomPlot *QtSLiMWindow::eidos_createPlot(QString title, double
50345034

50355035
if (createdWindow)
50365036
QtSLiMMakeWindowVisibleAndExposed(graphWindow);
5037+
5038+
// BCH 11/16/2025: There is one tricky thing here, which is that in practice the plot window might not be allowed
5039+
// to be the requested size, due to screen constraints. We don't know that until we try. Before the call to
5040+
// the QtSLiMMakeWindowVisibleAndExposed() the window is still at the original size we requested (on macOS, at
5041+
// least). After that call, it has been constrained by whatever factors (screen size, dock/menubar, etc.) exist.
5042+
// We can't do anything about those constraints; but we do want to try to preserve the original aspect ratio
5043+
// requested by the user, and we emit a warning to the console. See https://github.com/MesserLab/SLiM/issues/567
5044+
double realized_width = customPlot->width(), realized_height = customPlot->height();
5045+
double trim_width = graphWindow->width() - realized_width, trim_height = graphWindow->height() - realized_height;
5046+
5047+
if ((realized_width != width) || (realized_height != height))
5048+
{
5049+
std::cout << "SLiMgui: the requested graph window size (" << width << ", " << height << ") was not attainable; the realized size was (" <<
5050+
realized_width << ", " << realized_height << "). Resizing to try to preserve the requested aspect ratio." << std::endl;
5051+
5052+
double requested_aspect_ratio = width / height;
5053+
double realized_aspect_ratio = realized_width / realized_height;
5054+
5055+
if (realized_aspect_ratio > requested_aspect_ratio)
5056+
{
5057+
// the width is, proportionally, larger than requested and needs to be reduced
5058+
double corrected_width = std::round(requested_aspect_ratio * realized_height + trim_width);
5059+
graphWindow->resize(corrected_width, graphWindow->height());
5060+
}
5061+
else if (realized_aspect_ratio < requested_aspect_ratio)
5062+
{
5063+
// the height is, proportionally, larger than requested and needs to be reduced
5064+
double corrected_height = std::round(realized_width / requested_aspect_ratio + trim_height);
5065+
graphWindow->resize(graphWindow->width(), corrected_height);
5066+
}
5067+
5068+
//std::cout << " requested aspect ratio " << requested_aspect_ratio << "; final aspect ratio after correction " <<
5069+
// (customPlot->width() / (double)customPlot->height()) << std::endl;
5070+
}
50375071
}
50385072
else
50395073
{

VERSIONS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ multitrait branch:
8888
specifically, this entails two changes:
8989
allow a singleton migration rate value, applied for all subpops given
9090
allow the destination subpop to be given as a source, iff all rates supplied are 0.0, to stop all migration: allSubpops.setMigrationRates(allSubpops, 0.0)
91+
fix #567, plot windows can have their aspect ratio distorted due to screen size and other constraints
9192

9293

9394
version 5.1 (Eidos version 4.1):

0 commit comments

Comments
 (0)