-
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
16 changed files
with
291 additions
and
45 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
Empty file.
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 |
---|---|---|
@@ -1,11 +1,25 @@ | ||
#pragma once | ||
|
||
#include <CGImage.h> | ||
#include <NXData.h> | ||
#include <SkiaCtx.h> | ||
|
||
namespace NXKit { | ||
|
||
class UIImage { | ||
public: | ||
UIImage(); | ||
UIImage(std::shared_ptr<CGImage> cgImage, NXFloat scale); | ||
|
||
static std::shared_ptr<UIImage> fromPath(std::string path); | ||
static std::shared_ptr<UIImage> fromData(std::shared_ptr<NXData> data, NXFloat scale = SkiaCtx::main()->getScaleFactor()); | ||
|
||
std::shared_ptr<CGImage> cgImage() { return _cgImage; } | ||
NXSize size() const { return _size; } | ||
NXFloat scale() const { return _scale; } | ||
|
||
private: | ||
std::shared_ptr<CGImage> _cgImage; | ||
NXSize _size; | ||
NXFloat _scale; | ||
}; | ||
|
||
} | ||
} |
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,27 @@ | ||
#pragma once | ||
|
||
#include <UIView.h> | ||
#include <UIImage.h> | ||
|
||
namespace NXKit { | ||
|
||
class UIImageView: public UIView { | ||
public: | ||
static std::shared_ptr<UIImageView> init(); | ||
|
||
UIImageView(std::shared_ptr<UIImage> image = nullptr); | ||
UIImageView(NXRect frame); | ||
|
||
void setImage(std::shared_ptr<UIImage> image); | ||
std::shared_ptr<UIImage> image() { return _image; } | ||
|
||
// void sizeToFit() override; | ||
// Size sizeThatFits(Size size) override; | ||
// bool applyXMLAttribute(std::string name, std::string value) override; | ||
|
||
private: | ||
std::shared_ptr<UIImage> _image; | ||
void updateTextureFromImage(); | ||
}; | ||
|
||
} |
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,15 @@ | ||
#pragma once | ||
|
||
#include <UIView.h> | ||
|
||
namespace NXKit { | ||
|
||
class UILabel: public UIView { | ||
public: | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#pragma once | ||
|
||
namespace NXKit { | ||
|
||
enum class UIViewContentMode { | ||
scaleToFill = 0, | ||
|
||
scaleAspectFit = 1, // contents scaled to fit with fixed aspect. remainder is transparent | ||
|
||
scaleAspectFill = 2, // contents scaled to fill with fixed aspect. some portion of content may be clipped. | ||
|
||
redraw = 3, // redraw on bounds change (calls -setNeedsDisplay) | ||
|
||
center = 4, // contents remain same size. positioned adjusted. | ||
|
||
top = 5, | ||
|
||
bottom = 6, | ||
|
||
left = 7, | ||
|
||
right = 8, | ||
|
||
topLeft = 9, | ||
|
||
topRight = 10, | ||
|
||
bottomLeft = 11, | ||
|
||
bottomRight = 12, | ||
}; | ||
|
||
} |
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 |
---|---|---|
@@ -1,7 +1,19 @@ | ||
#include "UIImage.h" | ||
#include <tools/SharedBase.hpp> | ||
|
||
using namespace NXKit; | ||
|
||
UIImage::UIImage() { | ||
|
||
UIImage::UIImage(std::shared_ptr<CGImage> cgImage, NXFloat scale): | ||
_cgImage(cgImage), _scale(scale), _size(cgImage->size()) | ||
{ } | ||
|
||
std::shared_ptr<UIImage> UIImage::fromPath(std::string path) { | ||
auto imageData = NXData::fromPath(path); | ||
if (!imageData) { return nullptr; } | ||
return fromData(imageData); | ||
} | ||
|
||
std::shared_ptr<UIImage> UIImage::fromData(std::shared_ptr<NXData> data, NXFloat scale) { | ||
auto image = new_shared<CGImage>(data); | ||
return new_shared<UIImage>(image, scale); | ||
} |
Oops, something went wrong.