-
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
15 changed files
with
840 additions
and
194 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
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,85 @@ | ||
#pragma once | ||
|
||
namespace NXKit { | ||
|
||
typedef double NXFloat; | ||
|
||
struct NXPoint { | ||
NXFloat x, y; | ||
|
||
NXPoint(); | ||
NXPoint(NXFloat x, NXFloat y); | ||
|
||
bool operator==(const NXPoint& rhs) const; | ||
NXPoint operator+(const NXPoint& first) const; | ||
NXPoint operator-(const NXPoint& first) const; | ||
NXPoint& operator+=(const NXPoint& rhs); | ||
NXPoint& operator-=(const NXPoint& rhs); | ||
NXPoint operator/(const NXFloat& rhs); | ||
NXPoint operator*(const NXFloat& rhs); | ||
|
||
// Point applying(const NXAffineTransform& t) const; | ||
|
||
bool valid(); | ||
NXFloat magnitude(); | ||
}; | ||
|
||
struct NXSize { | ||
NXFloat width, height; | ||
|
||
NXSize(); | ||
NXSize(NXFloat width, NXFloat height); | ||
|
||
bool operator==(const NXSize &rhs) const; | ||
|
||
NXSize operator+(const NXSize &first) const; | ||
NXSize operator-(const NXSize &first) const; | ||
NXSize &operator+=(const NXSize &rhs); | ||
NXSize &operator-=(const NXSize &rhs); | ||
|
||
NXSize operator*(const NXFloat &first) const; | ||
NXSize operator/(const NXFloat &first) const; | ||
NXSize &operator*=(const NXFloat &rhs); | ||
NXSize &operator/=(const NXFloat &rhs); | ||
|
||
bool valid(); | ||
// NXSize inset(UIEdgeInsets inset) const; | ||
}; | ||
|
||
struct NXRect { | ||
NXPoint origin; | ||
NXSize size; | ||
|
||
NXRect(); | ||
NXRect(NXPoint origin, NXSize size); | ||
NXRect(NXFloat x, NXFloat y, NXFloat width, NXFloat height); | ||
|
||
NXFloat width() const; | ||
NXFloat height() const; | ||
|
||
NXFloat minX() const; | ||
NXFloat midX() const; | ||
NXFloat maxX() const; | ||
|
||
NXFloat minY() const; | ||
NXFloat midY() const; | ||
NXFloat maxY() const; | ||
|
||
bool contains(NXPoint point); | ||
bool intersects(const NXRect& other) const; | ||
NXRect intersection(const NXRect& other) const; | ||
NXRect& offsetBy(const NXPoint& offset); | ||
NXRect& offsetBy(const NXFloat& offsetX, const NXFloat& offsetY); | ||
// NXRect& insetBy(const UIEdgeInsets& insets); | ||
// NXRect applying(const NXAffineTransform& t) const; | ||
// NXRect applying(const NXTransform3D& t) const; | ||
|
||
bool operator==(const NXRect& rhs); | ||
|
||
bool valid(); | ||
|
||
static NXRect zero; | ||
static NXRect null; | ||
}; | ||
|
||
} |
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,21 @@ | ||
#pragma once | ||
|
||
namespace NXKit { | ||
|
||
class NXColor { | ||
public: | ||
NXColor(); | ||
NXColor(unsigned char red, unsigned char green, unsigned char blue); | ||
NXColor(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha); | ||
|
||
unsigned char r(); | ||
unsigned char g(); | ||
unsigned char b(); | ||
unsigned char a(); | ||
|
||
private: | ||
friend class NXLayer; | ||
int color; | ||
}; | ||
|
||
} |
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,70 @@ | ||
#pragma once | ||
|
||
#include "include/core/SkCanvas.h" | ||
|
||
#include <Geometry.h> | ||
#include <NXColor.h> | ||
|
||
#include <tools/SharedBase.hpp> | ||
#include <optional> | ||
#include <vector> | ||
|
||
namespace NXKit { | ||
|
||
class NXLayer: public enable_shared_from_this<NXLayer> { | ||
public: | ||
NXLayer(); | ||
~NXLayer() {} | ||
|
||
// Getter Setters | ||
void setAnchorPoint(NXPoint anchorPoint); | ||
[[nodiscard]] NXPoint anchorPoint() const { return _anchorPoint; } | ||
|
||
void setBounds(NXRect bounds); | ||
[[nodiscard]] NXRect bounds() const { return _bounds; } | ||
|
||
void setPosition(NXPoint position); | ||
[[nodiscard]] NXPoint position() const { return _position; } | ||
|
||
void setBackgroundColor(std::optional<NXColor> backgroundColor); | ||
[[nodiscard]] std::optional<NXColor> backgroundColor() const { return _backgroundColor; } | ||
|
||
void setCornerRadius(NXFloat cornerRadius); | ||
[[nodiscard]] NXFloat cornerRadius() const { return _cornerRadius; } | ||
|
||
|
||
// Layers | ||
[[nodiscard]] std::vector<std::shared_ptr<NXLayer>> sublayers() { return _sublayers; } | ||
|
||
void addSublayer(const std::shared_ptr<NXLayer>& layer); | ||
void insertSublayerAt(const std::shared_ptr<NXLayer>& layer, int index); | ||
void insertSublayerAbove(const std::shared_ptr<NXLayer>& layer, const std::shared_ptr<NXLayer>& sibling); | ||
void insertSublayerBelow(const std::shared_ptr<NXLayer>& layer, const std::shared_ptr<NXLayer>& sibling); | ||
|
||
void removeFromSuperlayer(); | ||
|
||
void skiaRender(SkCanvas* canvas); | ||
private: | ||
|
||
std::weak_ptr<NXLayer> superlayer; | ||
std::vector<std::shared_ptr<NXLayer>> _sublayers; | ||
|
||
// Animatable | ||
NXPoint _anchorPoint = NXPoint(0.5f, 0.5f); | ||
NXPoint _position; | ||
NXRect _bounds; | ||
NXFloat _cornerRadius = 0; | ||
std::optional<NXColor> _backgroundColor; | ||
|
||
/** | ||
Indicates whether a layer somewhere has changed since the last render pass. | ||
The current implementation of this is quite simple and doesn't check whether the layer is actually in | ||
the layer hierarchy or not. In theory this means that we're wasting render passes if users frequently | ||
update layers that aren't in the tree. In practice it's not expected that UIKit users would do that | ||
often enough for us to care about it. | ||
**/ | ||
static bool layerTreeIsDirty; | ||
}; | ||
|
||
} |
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,34 +0,0 @@ | ||
#pragma once | ||
|
||
namespace NXKit { | ||
|
||
typedef double NXFloat; | ||
|
||
struct NXSize { | ||
NXFloat width; | ||
NXFloat height; | ||
|
||
NXSize(); | ||
|
||
NXSize(NXFloat width, NXFloat height); | ||
|
||
bool operator==(const NXSize &rhs) const; | ||
|
||
NXSize operator+(const NXSize &first) const; | ||
|
||
NXSize operator-(const NXSize &first) const; | ||
|
||
NXSize &operator+=(const NXSize &rhs); | ||
|
||
NXSize &operator-=(const NXSize &rhs); | ||
|
||
NXSize operator*(const NXFloat &first) const; | ||
|
||
NXSize operator/(const NXFloat &first) const; | ||
|
||
NXSize &operator*=(const NXFloat &rhs); | ||
|
||
NXSize &operator/=(const NXFloat &rhs); | ||
}; | ||
|
||
} | ||
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,30 @@ | ||
#pragma once | ||
|
||
#include "NXLayer.h" | ||
|
||
namespace NXKit { | ||
|
||
class UIView: public enable_shared_from_this<UIView> { | ||
public: | ||
UIView(); | ||
|
||
virtual void addSubview(std::shared_ptr<UIView> view); | ||
void insertSubviewAt(std::shared_ptr<UIView> view, int index); | ||
void insertSubviewBelow(std::shared_ptr<UIView> view, std::shared_ptr<UIView> belowSubview); | ||
void removeFromSuperview(); | ||
|
||
// virtual std::shared_ptr<UIWindow> window(); | ||
|
||
const std::vector<std::shared_ptr<UIView>>& subviews() const { return _subviews; } | ||
std::weak_ptr<UIView> superview() const { return _superview; } | ||
|
||
std::shared_ptr<NXLayer> layer() const { return _layer; }; | ||
private: | ||
std::vector<std::shared_ptr<UIView>> _subviews; | ||
std::weak_ptr<UIView> _superview; | ||
std::shared_ptr<NXLayer> _layer; | ||
|
||
void setSuperview(std::shared_ptr<UIView> superview); | ||
}; | ||
|
||
} |
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,72 @@ | ||
// | ||
// SharedBase.hpp | ||
// NXKit | ||
// | ||
// Created by Даниил Виноградов on 08.10.2022. | ||
// | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
|
||
namespace NXKit { | ||
|
||
class enable_shared_from_this_pointer_holder { | ||
public: | ||
mutable std::shared_ptr<void> __strong_this_ctor_; | ||
}; | ||
|
||
template <class Base> | ||
class enable_shared_from_this: public enable_shared_from_this_pointer_holder { | ||
public: | ||
// mutable std::shared_ptr<Base> __strong_this_ctor_; | ||
mutable std::weak_ptr<Base> __weak_this_; | ||
|
||
enable_shared_from_this() { | ||
__strong_this_ctor_ = std::shared_ptr<Base>(static_cast<Base*>(this)); | ||
__weak_this_ = std::static_pointer_cast<Base>(__strong_this_ctor_); | ||
} | ||
|
||
|
||
protected: | ||
std::shared_ptr<Base> shared_from_this() { | ||
return std::shared_ptr<Base>(__weak_this_); | ||
} | ||
|
||
std::weak_ptr<Base> weak_from_this() { | ||
return __weak_this_; | ||
} | ||
|
||
template <class Derived> | ||
std::shared_ptr<Derived> shared_from_base() { | ||
return std::dynamic_pointer_cast<Derived>(this->shared_from_this()); | ||
} | ||
|
||
template <class Derived> | ||
std::weak_ptr<Derived> weak_from_base() { | ||
if (!this->weak_from_this().expired()) { | ||
return std::dynamic_pointer_cast<Derived>(this->weak_from_this().lock()); | ||
} | ||
return std::weak_ptr<Derived>(); | ||
} | ||
}; | ||
|
||
template<class _Tp, class ..._Args> | ||
typename std::enable_if<std::is_base_of<enable_shared_from_this_pointer_holder, _Tp>::value, std::shared_ptr<_Tp>>::type new_shared(_Args&& ...__args) { | ||
std::allocator<_Tp> alloc; | ||
using traits_t = std::allocator_traits<decltype(alloc)>; | ||
auto obj = alloc.allocate(1); | ||
traits_t::construct(alloc, obj, std::forward<_Args>(__args)...); | ||
|
||
auto ptr = std::static_pointer_cast<_Tp>(obj->__strong_this_ctor_); | ||
obj->__strong_this_ctor_ = nullptr; | ||
return ptr; | ||
} | ||
|
||
template<class _Tp, class ..._Args> | ||
typename std::enable_if<!std::is_base_of<enable_shared_from_this_pointer_holder, _Tp>::value, std::shared_ptr<_Tp>>::type new_shared(_Args&& ...__args) { | ||
auto res = std::make_shared<_Tp>(std::forward<_Args>(__args)...); | ||
return res; | ||
} | ||
|
||
} |
Oops, something went wrong.