-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
265 additions
and
37 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
bin/gn gen out/ios-arm64-angle --args='is_official_build=false target_cpu="arm64" skia_use_gl=true skia_use_metal=false is_trivial_abi=true target_os="ios"' | ||
bin/gn gen out/mac-arm64-angle --args='is_official_build=false target_cpu="arm64" skia_use_gl=true skia_use_metal=false is_trivial_abi=true skia_use_angle=true' |
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
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
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
|
||
#include <CALayer.h> | ||
#include <SkiaCtx.h> | ||
#include <include/core/SkFont.h> | ||
#include <include/core/SkTypeface.h> | ||
#include <modules/skparagraph/include/Paragraph.h> | ||
#include <modules/skparagraph/include/ParagraphBuilder.h> | ||
|
||
namespace NXKit { | ||
|
||
class CATextLayer: public CALayer { | ||
public: | ||
CATextLayer(); | ||
CATextLayer(CATextLayer* layer); | ||
virtual ~CATextLayer() = default; | ||
|
||
void draw(SkCanvas* context) override; | ||
std::shared_ptr<CALayer> copy() override; | ||
|
||
void setText(std::string text); | ||
[[nodiscard]] std::string text() const { return _text; } | ||
|
||
void setTextColor(UIColor textColor); | ||
[[nodiscard]] UIColor textColor() const { return _textColor; } | ||
private: | ||
std::string _text = "Furthermore, العربية نص جميل. द क्विक ब्राउन फ़ॉक्स jumps over the lazy 🐕."; | ||
UIColor _textColor = UIColor::black; | ||
|
||
// Skia | ||
sk_sp<SkTypeface> typeface; | ||
skia::textlayout::ParagraphStyle paraStyle; | ||
sk_sp<skia::textlayout::FontCollection> fontCollection; | ||
sk_sp<SkUnicode> unicode; | ||
std::unique_ptr<skia::textlayout::ParagraphBuilder> paragraphBuilder; | ||
std::unique_ptr<skia::textlayout::Paragraph> paragraph; | ||
|
||
void updateParagraph(); | ||
}; | ||
|
||
} |
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
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,15 +1,17 @@ | ||
#pragma once | ||
|
||
#include <UIView.h> | ||
#include <include/core/SkTypeface.h> | ||
|
||
namespace NXKit { | ||
|
||
class UILabel: public UIView { | ||
public: | ||
UILabel(); | ||
private: | ||
int _numberOfLines = 1; | ||
std::string _text; | ||
UIColor _textColor = UIColor::black; | ||
}; | ||
|
||
} | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include <CATextLayer.h> | ||
#include <modules/skunicode/include/SkUnicode_icu.h> | ||
|
||
using namespace NXKit; | ||
using namespace skia::textlayout; | ||
|
||
CATextLayer::CATextLayer(): CALayer() { | ||
auto fontMgr = SkiaCtx::main()->getFontMgr(); | ||
|
||
SkFontStyle fontStyle; | ||
typeface = SkiaCtx::main()->getFontMgr()->matchFamilyStyle(nullptr, fontStyle); | ||
|
||
fontCollection = sk_make_sp<FontCollection>(); | ||
fontCollection->setDefaultFontManager(SkiaCtx::main()->getFontMgr()); | ||
|
||
unicode = SkUnicodes::ICU::Make(); | ||
|
||
paragraphBuilder = ParagraphBuilder::make(paraStyle, fontCollection, unicode); | ||
updateParagraph(); | ||
} | ||
|
||
CATextLayer::CATextLayer(CATextLayer* layer): CALayer(layer) { | ||
typeface = layer->typeface; | ||
paraStyle = layer->paraStyle; | ||
fontCollection = layer->fontCollection; | ||
unicode = layer->unicode; | ||
|
||
paragraphBuilder = ParagraphBuilder::make(paraStyle, fontCollection, unicode); | ||
updateParagraph(); | ||
} | ||
|
||
std::shared_ptr<CALayer> CATextLayer::copy() { | ||
return new_shared<CATextLayer>(this); | ||
} | ||
|
||
void CATextLayer::draw(SkCanvas* context) { | ||
paragraph->layout(bounds().size.width); | ||
paragraph->paint(context, 0, 0); | ||
} | ||
|
||
void CATextLayer::setText(std::string text) { | ||
if (_text == text) return; | ||
_text = text; | ||
updateParagraph(); | ||
} | ||
|
||
void CATextLayer::setTextColor(UIColor textColor) { | ||
if (_textColor == textColor) return; | ||
_textColor = textColor; | ||
updateParagraph(); | ||
} | ||
|
||
void CATextLayer::updateParagraph() { | ||
paragraphBuilder->Reset(); | ||
|
||
SkPaint paint; | ||
paint.setAntiAlias(true); | ||
paint.setColor(_textColor.raw()); | ||
|
||
skia::textlayout::TextStyle style; | ||
style.setForegroundColor(paint); | ||
style.setTypeface(typeface); | ||
style.setFontSize(17); | ||
|
||
paraStyle.setTextStyle(style); | ||
paraStyle.setTextAlign(TextAlign::kRight); | ||
|
||
paragraphBuilder->addText(_text.c_str()); | ||
|
||
paragraph = paragraphBuilder->Build(); | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <UILabel.h> | ||
#include <CATextLayer.h> | ||
|
||
using namespace NXKit; | ||
|
||
UILabel::UILabel(): UIView(NXRect(), new_shared<CATextLayer>()) { | ||
|
||
} |
Oops, something went wrong.