Skip to content

Commit

Permalink
LayoutSubviews fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
XITRIX committed Dec 16, 2024
1 parent f138896 commit fdb57c9
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 43 deletions.
38 changes: 19 additions & 19 deletions Submodules/UIKit/include/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,39 +58,39 @@ struct NXRect {

NXRect();
NXRect(NXPoint origin, NXSize size);
NXRect(float x, float y, float width, float height);
NXRect(NXFloat x, NXFloat y, NXFloat width, NXFloat height);

float width() const;
float height() const;
NXFloat width() const;
NXFloat height() const;

float minX() const;
float midX() const;
float maxX() const;
NXFloat minX() const;
NXFloat midX() const;
NXFloat maxX() const;

float minY() const;
float midY() const;
float maxY() const;
NXFloat minY() const;
NXFloat midY() const;
NXFloat maxY() const;

void setWidth(float newValue);
void setHeight(float newValue);
void setWidth(NXFloat newValue);
void setHeight(NXFloat newValue);

void setMinX(float newValue);
void setMidX(float newValue);
void setMaxX(float newValue);
void setMinX(NXFloat newValue);
void setMidX(NXFloat newValue);
void setMaxX(NXFloat newValue);

void setMinY(float newValue);
void setMidY(float newValue);
void setMaxY(float newValue);
void setMinY(NXFloat newValue);
void setMidY(NXFloat newValue);
void setMaxY(NXFloat newValue);

bool contains(NXPoint point);
bool intersects(const NXRect& other) const;
NXRect& offsetBy(const NXPoint& offset);
NXRect& offsetBy(const float& offsetX, const float& offsetY);
NXRect& offsetBy(const NXFloat& offsetX, const NXFloat& offsetY);

bool operator==(const NXRect& rhs) const;
NXRect operator+(const NXRect& rhs) const;
NXRect operator-(const NXRect& rhs) const;
NXRect operator*(const float& rhs) const;
NXRect operator*(const NXFloat& rhs) const;

NXRect applying(NXAffineTransform transform);
NXRect applying(NXTransform3D transform);
Expand Down
44 changes: 22 additions & 22 deletions Submodules/UIKit/lib/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
using namespace NXKit;

// MARK: - PRIVATE -
float min(NXFloat a, NXFloat b, NXFloat c, NXFloat d) {
NXFloat min(NXFloat a, NXFloat b, NXFloat c, NXFloat d) {
auto minValue = (a < b) ? a : b;
minValue = (minValue < c) ? minValue : c;
minValue = (minValue < d) ? minValue : d;
return minValue;
}

float max(NXFloat a, NXFloat b, NXFloat c, NXFloat d) {
NXFloat max(NXFloat a, NXFloat b, NXFloat c, NXFloat d) {
auto maxValue = (a > b) ? a : b;
maxValue = (maxValue > c) ? maxValue : c;
maxValue = (maxValue > d) ? maxValue : d;
return maxValue;
}

float isEqual(NXFloat val1, NXFloat val2) {
NXFloat isEqual(NXFloat val1, NXFloat val2) {
if (isnan(val1) && isnan(val2))
return true;
return val1 == val2;
Expand Down Expand Up @@ -145,29 +145,29 @@ bool NXSize::valid() {
// MARK: - RECT -
NXRect::NXRect(): origin(), size() { }
NXRect::NXRect(NXPoint origin, NXSize size): origin(origin), size(size) { }
NXRect::NXRect(float x, float y, float width, float height): origin(x, y), size(width, height) { }
NXRect::NXRect(NXFloat x, NXFloat y, NXFloat width, NXFloat height): origin(x, y), size(width, height) { }

float NXRect::width() const { return size.width; }
float NXRect::height() const { return size.height; }
NXFloat NXRect::width() const { return size.width; }
NXFloat NXRect::height() const { return size.height; }

float NXRect::minX() const { return origin.x; }
float NXRect::midX() const { return origin.x + size.width / 2; }
float NXRect::maxX() const { return origin.x + size.width; }
NXFloat NXRect::minX() const { return origin.x; }
NXFloat NXRect::midX() const { return origin.x + size.width / 2; }
NXFloat NXRect::maxX() const { return origin.x + size.width; }

float NXRect::minY() const { return origin.y; }
float NXRect::midY() const { return origin.y + size.height / 2; }
float NXRect::maxY() const { return origin.y + size.height; }
NXFloat NXRect::minY() const { return origin.y; }
NXFloat NXRect::midY() const { return origin.y + size.height / 2; }
NXFloat NXRect::maxY() const { return origin.y + size.height; }

void NXRect::setWidth(float newValue) { size.width = newValue; }
void NXRect::setHeight(float newValue) { size.height = newValue; }
void NXRect::setWidth(NXFloat newValue) { size.width = newValue; }
void NXRect::setHeight(NXFloat newValue) { size.height = newValue; }

void NXRect::setMinX(float newValue) { origin.x = newValue; }
void NXRect::setMidX(float newValue) { origin.x = newValue - (size.width / 2); }
void NXRect::setMaxX(float newValue) { origin.x = newValue - size.width; }
void NXRect::setMinX(NXFloat newValue) { origin.x = newValue; }
void NXRect::setMidX(NXFloat newValue) { origin.x = newValue - (size.width / 2); }
void NXRect::setMaxX(NXFloat newValue) { origin.x = newValue - size.width; }

void NXRect::setMinY(float newValue) { origin.y = newValue; }
void NXRect::setMidY(float newValue) { origin.y = newValue - (size.height / 2); }
void NXRect::setMaxY(float newValue) { origin.y = newValue - size.height; }
void NXRect::setMinY(NXFloat newValue) { origin.y = newValue; }
void NXRect::setMidY(NXFloat newValue) { origin.y = newValue - (size.height / 2); }
void NXRect::setMaxY(NXFloat newValue) { origin.y = newValue - size.height; }

bool NXRect::contains(NXPoint point) {
return
Expand All @@ -185,7 +185,7 @@ NXRect& NXRect::offsetBy(const NXPoint& offset) {
return *this;
}

NXRect& NXRect::offsetBy(const float& offsetX, const float& offsetY) {
NXRect& NXRect::offsetBy(const NXFloat& offsetX, const NXFloat& offsetY) {
origin.x += offsetX;
origin.y += offsetY;
return *this;
Expand Down Expand Up @@ -215,7 +215,7 @@ NXRect NXRect::operator-(const NXRect& rhs) const {
);
}

NXRect NXRect::operator*(const float& rhs) const {
NXRect NXRect::operator*(const NXFloat& rhs) const {
return NXRect(
this->origin.x * rhs,
this->origin.y * rhs,
Expand Down
2 changes: 1 addition & 1 deletion Submodules/UIKit/lib/UIApplicationMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ bool applicationRunLoop() {
auto scale = SkiaCtx::_main->getScaleFactor();
canvas->scale(scale, scale);

keyWindow->layer()->setBounds({ NXPoint::zero, SkiaCtx::_main->getSize() } );
keyWindow->setFrame({ NXPoint::zero, SkiaCtx::_main->getSize() } );
keyWindow->layer()->presentationOrSelf()->skiaRender(canvas);
canvas->restore();

Expand Down
5 changes: 4 additions & 1 deletion Submodules/UIKit/lib/UIView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void UIView::drawAndLayoutTreeIfNeeded() {

// updateSafeAreaInsetsIfNeeded();
// updateLayoutMarginIfNeeded();
// layoutIfNeeded();
layoutIfNeeded();

for (auto& subview: _subviews) {
subview->drawAndLayoutTreeIfNeeded();
Expand Down Expand Up @@ -289,6 +289,9 @@ void UIView::setNeedsLayout() {
void UIView::layoutIfNeeded() {
if (_needsLayout) {
_needsLayout = false;
for (const auto &view : subviews()) {
view->setNeedsLayout();
}
layoutSubviews();
}
}
Expand Down
2 changes: 2 additions & 0 deletions Submodules/cmake/toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ elseif (PLATFORM_IOS)
message("Building for iOS")
add_definitions( -DPLATFORM_IOS )

set(DEPLOYMENT_TARGET "15.0")

set(USE_GLES ON)

set(BUILD_SHARED_LIBS OFF)
Expand Down
12 changes: 12 additions & 0 deletions app/Screens/TestViewController/TestViewController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,22 @@ void TestViewController::loadView() {
rootView->addSubview(blur);
animateBlur(blur);

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

setView(rootView);
}

void TestViewController::viewDidLoad() {
UIViewController::viewDidLoad();
animateLabel(label);
}

void TestViewController::viewDidLayoutSubviews() {
UIViewController::viewDidLayoutSubviews();

auto frame = view()->frame();
NXFloat bottomBarHeight = 48 + 35; //83;
bottomBar->setFrame({ 0, frame.size.height - bottomBarHeight, frame.size.width, bottomBarHeight });
}
3 changes: 3 additions & 0 deletions app/Screens/TestViewController/TestViewController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class TestViewController: public NXKit::UIViewController {
TestViewController();
void loadView() override;
void viewDidLoad() override;

void viewDidLayoutSubviews() override;
private:
std::shared_ptr<NXKit::UILabel> label;
std::shared_ptr<NXKit::UIView> bottomBar;
};

0 comments on commit fdb57c9

Please sign in to comment.