-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Font::getTextWidth(std::string_view)
- Loading branch information
Showing
2 changed files
with
12 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2012-2022 Jan Niklas Hasse <[email protected]> | ||
// Copyright 2012-2024 Jan Niklas Hasse <[email protected]> | ||
// For conditions of distribution and use, see copyright notice in LICENSE.txt | ||
|
||
#include "font.hpp" | ||
|
@@ -58,6 +58,10 @@ void Font::print(const Mat3& modelview, const std::string& text) const { | |
impl->print(modelview, text); | ||
} | ||
|
||
double Font::getTextWidth(std::string_view text) { | ||
return static_cast<double>(static_cast<ScaleablePixels>(impl->getTextWidth(std::string(text)))); | ||
} | ||
|
||
std::shared_ptr<FontImpl> Font::getImpl() { | ||
return impl; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright 2012-2022 Jan Niklas Hasse <[email protected]> | ||
// Copyright 2012-2024 Jan Niklas Hasse <[email protected]> | ||
// For conditions of distribution and use, see copyright notice in LICENSE.txt | ||
/// Contains jngl::Font class and related functions | ||
/// @file | ||
|
@@ -30,6 +30,10 @@ class Font { | |
/// Draw \a text using \a modelview | ||
void print(const Mat3& modelview, const std::string& text) const; | ||
|
||
/// Calculates the width of \a text in scale-independent pixels if it would be drawn with this | ||
/// font | ||
double getTextWidth(std::string_view); | ||
|
||
/// Internal function | ||
std::shared_ptr<FontImpl> getImpl(); | ||
|
||
|
@@ -93,7 +97,8 @@ double getLineHeight(); | |
/// Set line height used by print() in scale-independent pixel | ||
void setLineHeight(double); | ||
|
||
/// Calculates the width of \a text in pixels if it would be drawn with the currently active font | ||
/// Calculates the width of \a text in scale-independent pixels if it would be drawn with the | ||
/// currently active font | ||
double getTextWidth(const std::string& text); | ||
|
||
} // namespace jngl |