Skip to content

Commit

Permalink
Add uiScale option to the Graph Editor (#1586)
Browse files Browse the repository at this point in the history
The branch has an additional command line variable for MaterialXGraphEditor, --uiScale, that will override the automatic calculation and application of DPI scaling.

Using this flag on MacOS with a retina display, will result in a normal-sized UI.
  • Loading branch information
virokannas authored Jun 28, 2024
1 parent 9b4b66e commit 8e050bf
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions source/MaterialXGraphEditor/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const std::string options =
" --mesh [FILENAME] Specify the filename of the OBJ or glTF mesh to be displayed in the graph editor\n"
" --path [FILEPATH] Specify an additional data search path location (e.g. '/projects/MaterialX'). This absolute path will be queried when locating data libraries, XInclude references, and referenced images.\n"
" --library [FILEPATH] Specify an additional data library folder (e.g. 'vendorlib', 'studiolib'). This relative path will be appended to each location in the data search path when loading data libraries.\n"
" --uiScale [FACTOR] Manually specify a UI scaling factor\n"
" --captureFilename [FILENAME] Specify the filename to which the first rendered frame should be written\n"
" --help Display the complete list of command-line options\n";

Expand Down Expand Up @@ -65,6 +66,7 @@ int main(int argc, char* const argv[])
mx::FilePathVec libraryFolders;
int viewWidth = 256;
int viewHeight = 256;
float uiScale = 0.0f;
std::string captureFilename;

for (size_t i = 0; i < tokens.size(); i++)
Expand Down Expand Up @@ -96,6 +98,10 @@ int main(int argc, char* const argv[])
{
parseToken(nextToken, "integer", viewHeight);
}
else if (token == "--uiScale")
{
parseToken(nextToken, "float", uiScale);
}
else if (token == "--captureFilename")
{
parseToken(nextToken, "string", captureFilename);
Expand Down Expand Up @@ -199,9 +205,12 @@ int main(int argc, char* const argv[])
float xscale = 1.0f, yscale = 1.0f;
glfwGetMonitorContentScale(monitor, &xscale, &yscale);
ImGuiStyle& style = ImGui::GetStyle();
float dpiScale = xscale > yscale ? xscale : yscale;
style.ScaleAllSizes(dpiScale);
graph->setFontScale(dpiScale);
if (uiScale <= 0.0f)
{
uiScale = (xscale > yscale) ? xscale : yscale;
}
style.ScaleAllSizes(uiScale);
graph->setFontScale(uiScale);
}

// Create editor config and context.
Expand Down

0 comments on commit 8e050bf

Please sign in to comment.