Color Emoji fonts are now displayed correctly in monospaced fonts (they will have the right size and color).

Several improvements have been done to avoid losing performance when rendering non-monospaced text over monospaced fonts.
Exposed properties to UICodeEditor (PropertyId::EnableCodeEditorFlags, PropertyId::DisableCodeEditorFlags, PropertyId::LineWrapMode, PropertyId::LineWrapType).
Event::OnSizeChange event is now reported AFTER onSizeChange event has been processed by the widget that changed its size.
UIApplication now loads a monospaced font if found.
Fixes in String::readBySeparator.
This commit is contained in:
Martín Lucas Golini
2025-02-27 00:20:26 -03:00
parent a7c389a042
commit a08148bc57
16 changed files with 322 additions and 86 deletions

View File

@@ -78,8 +78,13 @@ class EE_API FontTrueType : public Font {
bool isColorEmojiFont() const;
/** @return True if the font identifies itself as a monospace font and currently does not hold
* any non-monospaced glyph (from a fallback font) */
bool isMonospace() const;
/** @return True if the font identifies itself as a monospace font */
bool isIdentifiedAsMonospace() const;
bool isScalable() const;
bool isEmojiFont() const;

View File

@@ -21,6 +21,10 @@ class EE_API Text {
Shadow = 1 << 4 ///< Draw a shadow below the text
};
enum DrawHints {
AllAscii = 1 << 0,
};
static std::string styleFlagToString( const Uint32& flags );
static Uint32 stringToStyleFlag( const std::string& str );
@@ -43,19 +47,22 @@ class EE_API Text {
const Color& fontColor, Uint32 style = 0, Float outlineThickness = 0.f,
const Color& outlineColor = Color::Black,
const Color& shadowColor = Color::Black,
const Vector2f& shadowOffset = { 1, 1 }, const Uint32& tabWidth = 4 );
const Vector2f& shadowOffset = { 1, 1 }, const Uint32& tabWidth = 4,
Uint32 textDrawHints = 0 );
static Sizef draw( const String& string, const Vector2f& pos, const FontStyleConfig& config,
const Uint32& tabWidth = 4 );
const Uint32& tabWidth = 4, Uint32 textDrawHints = 0 );
static Sizef draw( const String::View& string, const Vector2f& pos, Font* font, Float fontSize,
const Color& fontColor, Uint32 style = 0, Float outlineThickness = 0.f,
const Color& outlineColor = Color::Black,
const Color& shadowColor = Color::Black,
const Vector2f& shadowOffset = { 1, 1 }, const Uint32& tabWidth = 4 );
const Vector2f& shadowOffset = { 1, 1 }, const Uint32& tabWidth = 4,
Uint32 textDrawHints = 0 );
static Sizef draw( const String::View& string, const Vector2f& pos,
const FontStyleConfig& config, const Uint32& tabWidth = 4 );
const FontStyleConfig& config, const Uint32& tabWidth = 4,
Uint32 textDrawHints = 0 );
static void drawUnderline( const Vector2f& pos, Float width, Font* font, Float fontSize,
const Color& fontColor, const Uint32& style, Float outlineThickness,
@@ -63,9 +70,9 @@ class EE_API Text {
const Vector2f& shadowOffset );
static void drawStrikeThrough( const Vector2f& pos, Float width, Font* font, Float fontSize,
const Color& fontColor, const Uint32& style,
Float outlineThickness, const Color& outlineColor,
const Color& shadowColor, const Vector2f& shadowOffset );
const Color& fontColor, const Uint32& style,
Float outlineThickness, const Color& outlineColor,
const Color& shadowColor, const Vector2f& shadowOffset );
static Int32 findCharacterFromPos( const Vector2i& pos, bool returnNearest, Font* font,
const Uint32& fontSize, const String& string,
@@ -312,11 +319,12 @@ class EE_API Text {
const Color& fontColor, Uint32 style = 0, Float outlineThickness = 0.f,
const Color& outlineColor = Color::Black,
const Color& shadowColor = Color::Black,
const Vector2f& shadowOffset = { 1, 1 }, const Uint32& tabWidth = 4 );
const Vector2f& shadowOffset = { 1, 1 }, const Uint32& tabWidth = 4,
Uint32 textDrawHints = 0 );
template <typename StringType>
static Sizef draw( const StringType& string, const Vector2f& pos, const FontStyleConfig& config,
const Uint32& tabWidth = 4 );
const Uint32& tabWidth = 4, Uint32 textDrawHints = 0 );
template <typename StringType>
static std::size_t findLastCharPosWithinLength( Font* font, const Uint32& fontSize,

View File

@@ -4,6 +4,7 @@
#include <eepp/scene/node.hpp>
#include <eepp/system/translator.hpp>
#include <eepp/window/cursor.hpp>
#include <unordered_set>
namespace EE { namespace Graphics {
class FrameBuffer;
@@ -114,7 +115,7 @@ class EE_API SceneNode : public Node {
protected:
friend class Node;
typedef UnorderedSet<Node*> CloseList;
typedef std::unordered_set<Node*> CloseList;
EE::Window::Window* mWindow;
ActionManager* mActionManager;

View File

@@ -220,6 +220,10 @@ enum class PropertyId : Uint32 {
RowValign = String::hash( "row-valign" ),
TextOverflow = String::hash( "text-overflow" ),
CheckMode = String::hash( "check-mode" ),
EnableCodeEditorFlags = String::hash( "enable-editor-flags" ),
DisableCodeEditorFlags = String::hash( "disable-editor-flags" ),
LineWrapMode = String::hash( "line-wrap-mode" ),
LineWrapType = String::hash( "line-wrap-type" ),
};
enum class PropertyType : Uint32 {

View File

@@ -64,6 +64,8 @@ class EE_API TextDocumentLine {
std::string toUtf8() const { return mText.toUtf8(); }
bool isAscii() const { return ( mFlags & AllAscii ) != 0; }
protected:
String mText;
String::HashType mHash;

View File

@@ -27,6 +27,9 @@ class EE_API UIApplication {
//! The default base font for the UI. If not provided it will load NotoSans-Regular ( will
//! look at "assets/fonts/NotoSans-Regular.ttf" )
Font* baseFont{ nullptr };
//! The default base monospace font for the UI. If not provided it will load DejaVuSansMono
//! ( will look at "assets/fonts/DejaVuSansMono.ttf" )
Font* monospaceFont{ nullptr };
//! The style sheet path is the path of the base UI theme stylesheet ( will look at
//! "assets/ui/breeze.css" by default )
std::optional<std::string> baseStyleSheetPath;

View File

@@ -1096,7 +1096,12 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client {
template <typename StringType> size_t characterWidth( const StringType& str ) const;
template <typename StringType> Float getTextWidth( const StringType& text ) const;
template <typename StringType>
Float getTextWidth( const StringType& text, bool fromMonospaceLine ) const;
Float getTextWidth( const String& text, bool fromMonospaceLine ) const;
Float getTextWidth( const String::View& text, bool fromMonospaceLine ) const;
void updateIMELocation();
@@ -1113,6 +1118,12 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client {
bool isNotMonospace() const;
void flashCursor();
void setCodeEditorFlags( std::string flags, bool enable );
std::string getCodeEditorFlags( bool enabled ) const;
bool isMonospaceLine( Int64 lineIndex ) const;
};
}} // namespace EE::UI