Skip to content

Commit

Permalink
UILabel fix trait collection update
Browse files Browse the repository at this point in the history
  • Loading branch information
XITRIX committed Dec 19, 2024
1 parent 37fdbc2 commit 70bc23b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
8 changes: 8 additions & 0 deletions Submodules/UIKit/include/UIColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@

namespace NXKit {

#define UIColorThemed(lightColor, darkColor) \
UIColor([](auto collection) {\
if (collection->userInterfaceStyle() == UIUserInterfaceStyle::dark) \
return darkColor; \
else \
return lightColor;\
})

class UIColor {
public:
UIColor();
Expand Down
3 changes: 2 additions & 1 deletion Submodules/UIKit/include/UILabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ class UILabel: public UIView {
[[nodiscard]] NXFloat fontWeight() const { return _fontWeight; }

NXSize sizeThatFits(NXSize size) override;
void traitCollectionDidChange(std::shared_ptr<UITraitCollection> previousTraitCollection) override;

private:
int _numberOfLines = 1;
NXFloat _fontSize = 17;
NXFloat _fontWeight = SkFontStyle::kNormal_Weight;
NSTextAlignment _textAlignment = NSTextAlignment::left;
std::string _text = "Furthermore, العربية نص جميل. द क्विक ब्राउन फ़ॉक्स jumps over the lazy 🐕.";
UIColor _textColor = UIColor::black;
UIColor _textColor = UIColor::label;

sk_sp<SkUnicode> unicode;
std::unique_ptr<skia::textlayout::Paragraph> paragraph;
Expand Down
8 changes: 0 additions & 8 deletions Submodules/UIKit/lib/UIColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@

using namespace NXKit;

#define UIColorThemed(lightColor, darkColor) \
UIColor([](auto collection) {\
if (collection->userInterfaceStyle() == UIUserInterfaceStyle::dark) \
return darkColor; \
else \
return lightColor;\
})

// Transparent
UIColor UIColor::clear = UIColor(0, 0, 0, 0);

Expand Down
5 changes: 5 additions & 0 deletions Submodules/UIKit/lib/UILabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ NXSize UILabel::sizeThatFits(NXSize size) {
return { rWidth, height };
}

void UILabel::traitCollectionDidChange(std::shared_ptr<UITraitCollection> previousTraitCollection) {
UIView::traitCollectionDidChange(previousTraitCollection);
setNeedsLayout();
}

void UILabel::draw() {
updateParagraph();

Expand Down
4 changes: 2 additions & 2 deletions app/Screens/TestViewController/TestViewController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void TestViewController::loadView() {
// animateBlur(blur);

bottomBar = new_shared<UIView>();
bottomBar->setBackgroundColor(UIColor::gray);
bottomBar->setBackgroundColor(UIColor::secondarySystemBackground);
rootView->addSubview(bottomBar);

label2 = new_shared<UILabel>();
Expand Down Expand Up @@ -155,7 +155,7 @@ void TestViewController::loadView() {
blur->setFrame({ 80, 200, 240, 240 });
rootView->addSubview(blur);
blur->layer()->setCornerRadius(12);
blur->setBackgroundTintColor(0x60DDDDDD);
blur->setBackgroundTintColor(UIColorThemed(UIColor(0x60DDDDDD), UIColor(0x60404040)));

blur->addSubview(dragMeViewLabel);

Expand Down

0 comments on commit 70bc23b

Please sign in to comment.