Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for choice of font for Graph Editor #2046

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions documents/DeveloperGuide/GraphEditor.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ The following are common command-line options for MaterialXGraphEditor, and a co
- `--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.
- `--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.
- `--captureFilename [FILENAME]` : Specify the filename to which the first rendered frame should be written
- `--font [FILE]` : Specify the name of the custom font file to use. If not specified the default font will be used"
- `--fontSize [SIZE]` : Specify font size to use for the custom font. If not specified a default of 18 will be used"

## Known Limitations

Expand Down
26 changes: 25 additions & 1 deletion source/MaterialXGraphEditor/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const std::string options =
" --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"
" --font [FILE] Specify the name of the custom font file to use. If not specified the default font will be used\n"
" --fontSize [SIZE] Specify font size to use for the custom font. If not specified a default of 18 will be used\n"
" --help Display the complete list of command-line options\n";

template <class T> void parseToken(std::string token, std::string type, T& res)
Expand Down Expand Up @@ -68,6 +70,8 @@ int main(int argc, char* const argv[])
int viewHeight = 256;
float uiScale = 0.0f;
std::string captureFilename;
std::string fontFilename;
int fontSize = 18;

for (size_t i = 0; i < tokens.size(); i++)
{
Expand Down Expand Up @@ -106,6 +110,18 @@ int main(int argc, char* const argv[])
{
parseToken(nextToken, "string", captureFilename);
}
else if (token == "--font")
{
parseToken(nextToken, "string", fontFilename);
}
else if (token == "--fontSize")
{
parseToken(nextToken, "integer", fontSize);
if (fontSize < 12)
{
fontSize = 12;
}
}
else if (token == "--help")
{
std::cout << " MaterialXGraphEditor version " << mx::getVersionString() << std::endl;
Expand Down Expand Up @@ -172,7 +188,15 @@ int main(int argc, char* const argv[])
io.IniFilename = NULL;
io.LogFilename = NULL;

io.Fonts->AddFontDefault();
ImFont* customFont = nullptr;
if (!fontFilename.empty())
{
customFont = io.Fonts->AddFontFromFileTTF(fontFilename.c_str(), fontSize);
}
if (!customFont)
{
io.Fonts->AddFontDefault();
}

// Setup Dear ImGui style
ImGui::StyleColorsDark();
Expand Down