Add textFitWidth and textFitHeight Properties to Sprites (#2780)

Co-authored-by: Xiaolian Qin <xiaoq@microsoft.com>
This commit is contained in:
qqz003
2024-09-13 21:02:02 +08:00
committed by GitHub
parent 814e1015a8
commit cb38119451
58 changed files with 2116 additions and 103 deletions

View File

@@ -14,6 +14,12 @@ namespace style {
using ImageStretch = std::pair<float, float>;
using ImageStretches = std::vector<ImageStretch>;
enum class TextFit {
stretchOrShrink,
stretchOnly,
proportional
};
class ImageContent {
public:
float left;
@@ -34,15 +40,26 @@ public:
bool sdf,
ImageStretches stretchX = {},
ImageStretches stretchY = {},
const std::optional<ImageContent>& content = std::nullopt);
const std::optional<ImageContent>& content = std::nullopt,
const std::optional<TextFit>& textFitWidth = std::nullopt,
const std::optional<TextFit>& textFitHeight = std::nullopt);
Image(std::string id,
PremultipliedImage&& image,
float pixelRatio,
ImageStretches stretchX = {},
ImageStretches stretchY = {},
const std::optional<ImageContent>& content = std::nullopt)
: Image(std::move(id), std::move(image), pixelRatio, false, std::move(stretchX), std::move(stretchY), content) {
}
const std::optional<ImageContent>& content = std::nullopt,
const std::optional<TextFit>& textFitWidth = std::nullopt,
const std::optional<TextFit>& textFitHeight = std::nullopt)
: Image(std::move(id),
std::move(image),
pixelRatio,
false,
std::move(stretchX),
std::move(stretchY),
content,
textFitWidth,
textFitHeight) {}
Image(const Image&);
std::string getID() const;
@@ -63,6 +80,12 @@ public:
/// The space where text can be fit into this image.
const std::optional<ImageContent>& getContent() const;
/// The constraints on the horizontal scaling of the image when `icon-text-fit` is used
const std::optional<TextFit>& getTextFitWidth() const;
/// The constraints on the vertical scaling of the image when `icon-text-fit` is used
const std::optional<TextFit>& getTextFitHeight() const;
class Impl;
Immutable<Impl> baseImpl;
explicit Image(Immutable<Impl> baseImpl_)