MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / shortenPath

Function shortenPath

src/openrct2/drawing/Drawing.String.cpp:836–860  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

834 }
835
836 u8string shortenPath(const u8string& path, int32_t availableWidth, FontStyle fontStyle)
837 {
838 if (getStringWidth(path, fontStyle) <= availableWidth)
839 {
840 return path;
841 }
842
843 u8string shortenedPath = u8"...";
844
845 size_t begin = 0;
846 while (begin < path.size())
847 {
848 begin = path.find_first_of(*PATH_SEPARATOR, begin + 1);
849 if (begin == path.npos)
850 break;
851
852 shortenedPath = u8"..." + path.substr(begin);
853 if (getStringWidth(shortenedPath, fontStyle) <= availableWidth)
854 {
855 return shortenedPath;
856 }
857 }
858
859 return shortenedPath;
860 }
861} // namespace OpenRCT2::Drawing

Callers 3

onDrawMethod · 0.85
onDrawMethod · 0.85
onDrawMethod · 0.85

Calls 2

getStringWidthFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected