mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[Impeller] libImpeller: Allow setting ellipses. (#169610)
Fixes https://github.com/flutter/flutter/issues/168750 <img width="1136" alt="Screenshot 2025-05-28 at 11 41 24 AM" src="https://github.com/user-attachments/assets/d421783b-9e04-46e1-aa0c-236c3f546e11" />
This commit is contained in:
parent
ed68dd8c22
commit
09c7f4fa5b
@ -1159,6 +1159,12 @@ void ImpellerParagraphStyleSetLocale(ImpellerParagraphStyle paragraph_style,
|
||||
GetPeer(paragraph_style)->SetLocale(ReadString(locale));
|
||||
}
|
||||
|
||||
IMPELLER_EXTERN_C
|
||||
void ImpellerParagraphStyleSetEllipsis(ImpellerParagraphStyle paragraph_style,
|
||||
const char* ellipsis) {
|
||||
GetPeer(paragraph_style)->SetEllipsis(ReadString(ellipsis));
|
||||
}
|
||||
|
||||
IMPELLER_EXTERN_C
|
||||
void ImpellerDisplayListBuilderDrawParagraph(ImpellerDisplayListBuilder builder,
|
||||
ImpellerParagraph paragraph,
|
||||
|
||||
@ -2472,6 +2472,18 @@ void ImpellerParagraphStyleSetLocale(
|
||||
ImpellerParagraphStyle IMPELLER_NONNULL paragraph_style,
|
||||
const char* IMPELLER_NONNULL locale);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// @brief Set the UTF-8 string to use as the ellipsis. Pass `nullptr` to
|
||||
/// clear the setting to default.
|
||||
///
|
||||
/// @param[in] paragraph_style The paragraph style.
|
||||
/// @param[in] data The ellipsis string UTF-8 data, or null.
|
||||
///
|
||||
IMPELLER_EXPORT
|
||||
void ImpellerParagraphStyleSetEllipsis(
|
||||
ImpellerParagraphStyle IMPELLER_NONNULL paragraph_style,
|
||||
const char* IMPELLER_NULLABLE ellipsis);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Paragraph Builder
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@ -168,6 +168,7 @@ struct Proc {
|
||||
PROC(ImpellerParagraphStyleRelease) \
|
||||
PROC(ImpellerParagraphStyleRetain) \
|
||||
PROC(ImpellerParagraphStyleSetBackground) \
|
||||
PROC(ImpellerParagraphStyleSetEllipsis) \
|
||||
PROC(ImpellerParagraphStyleSetFontFamily) \
|
||||
PROC(ImpellerParagraphStyleSetFontSize) \
|
||||
PROC(ImpellerParagraphStyleSetFontStyle) \
|
||||
@ -1088,6 +1089,14 @@ class ParagraphStyle
|
||||
return *this;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// @see ImpellerParagraphStyleSetEllipsis
|
||||
///
|
||||
ParagraphStyle& SetEllipsis(const char* ellipsis) {
|
||||
gGlobalProcTable.ImpellerParagraphStyleSetEllipsis(Get(), ellipsis);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// @see ImpellerParagraphStyleSetMaxLines
|
||||
///
|
||||
|
||||
@ -631,4 +631,29 @@ TEST_P(InteropPlaygroundTest, CanGetPathBounds) {
|
||||
ASSERT_EQ(bounds.height, 100);
|
||||
}
|
||||
|
||||
TEST_P(InteropPlaygroundTest, CanControlEllipses) {
|
||||
hpp::TypographyContext context;
|
||||
auto style = hpp::ParagraphStyle{};
|
||||
style.SetFontSize(50);
|
||||
style.SetForeground(hpp::Paint{}.SetColor({.red = 1.0, .alpha = 1.0}));
|
||||
const auto text = std::string{"The quick brown fox jumped over the lazy dog"};
|
||||
style.SetEllipsis("🐶");
|
||||
auto para1 =
|
||||
hpp::ParagraphBuilder{context}.PushStyle(style).AddText(text).Build(250);
|
||||
style.SetForeground(hpp::Paint{}.SetColor({.green = 1.0, .alpha = 1.0}));
|
||||
style.SetEllipsis(nullptr);
|
||||
auto para2 =
|
||||
hpp::ParagraphBuilder{context}.PushStyle(style).AddText(text).Build(250);
|
||||
auto dl = hpp::DisplayListBuilder{}
|
||||
.DrawParagraph(para1, {100, 100})
|
||||
.DrawParagraph(para2, {100, 200})
|
||||
.Build();
|
||||
ASSERT_TRUE(
|
||||
OpenPlaygroundHere([&](const auto& context, const auto& surface) -> bool {
|
||||
hpp::Surface window(surface.GetC());
|
||||
window.Draw(dl);
|
||||
return true;
|
||||
}));
|
||||
}
|
||||
|
||||
} // namespace impeller::interop::testing
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
|
||||
#include "impeller/toolkit/interop/paragraph_style.h"
|
||||
|
||||
#include "flutter/fml/string_conversion.h"
|
||||
|
||||
namespace impeller::interop {
|
||||
|
||||
ParagraphStyle::ParagraphStyle() = default;
|
||||
@ -84,4 +86,12 @@ void ParagraphStyle::SetTextDecoration(
|
||||
decoration_ = decoration;
|
||||
}
|
||||
|
||||
void ParagraphStyle::SetEllipsis(const std::string& string) {
|
||||
if (string.empty()) {
|
||||
style_.ellipsis = {};
|
||||
return;
|
||||
}
|
||||
style_.ellipsis = fml::Utf8ToUtf16(string);
|
||||
}
|
||||
|
||||
} // namespace impeller::interop
|
||||
|
||||
@ -48,6 +48,8 @@ class ParagraphStyle final
|
||||
|
||||
void SetLocale(std::string locale);
|
||||
|
||||
void SetEllipsis(const std::string& string);
|
||||
|
||||
txt::TextStyle CreateTextStyle() const;
|
||||
|
||||
const txt::ParagraphStyle& GetParagraphStyle() const;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user