mirror of
https://github.com/XITRIX/NXKit.git
synced 2026-05-30 11:46:52 +00:00
UISelectorViewController improvements
This commit is contained in:
@@ -89,7 +89,7 @@ YGSize UILabel::labelMeasureFunc(YGNodeRef node, float width, YGMeasureMode widt
|
||||
}
|
||||
else
|
||||
{
|
||||
// fatal("Unsupported Label width measure mode: " + std::to_string(widthMode));
|
||||
printf("Unsupported Label width measure mode: %s\n", std::to_string(widthMode).c_str());
|
||||
}
|
||||
|
||||
// Height
|
||||
@@ -138,7 +138,7 @@ YGSize UILabel::labelMeasureFunc(YGNodeRef node, float width, YGMeasureMode widt
|
||||
}
|
||||
else
|
||||
{
|
||||
// fatal("Unsupported Label height measure mode: " + std::to_string(heightMode));
|
||||
printf("Unsupported Label height measure mode: %s\n", std::to_string(heightMode).c_str());
|
||||
}
|
||||
}
|
||||
// No wrapping necessary or allowed, return the normal height
|
||||
|
||||
@@ -183,7 +183,8 @@ void UIScrollView::layoutSubviews() {
|
||||
|
||||
if (contentView) {
|
||||
Size frameSize = getBounds().size;
|
||||
Size size = Size(fixWidth ? frameSize.width : UIView::AUTO, fixHeight ? frameSize.height : UIView::AUTO);
|
||||
Size size = Size(fixWidth ? frameSize.width : UIView::AUTO,
|
||||
fixHeight ? frameSize.height : UIView::AUTO);
|
||||
contentView->setSize(size);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,13 +32,6 @@ void UISelectorViewController::loadView() {
|
||||
view->addSubview(makeFooter());
|
||||
}
|
||||
|
||||
void UISelectorViewController::viewWillAppear(bool animated) {
|
||||
if (selectedView) {
|
||||
getView()->layoutIfNeeded();
|
||||
Application::shared()->setFocus(selectedView);
|
||||
}
|
||||
}
|
||||
|
||||
UIView* UISelectorViewController::makeContentView() {
|
||||
UINavigationBar* navigationBar = new UINavigationBar();
|
||||
navigationBar->setSize(Size(UIView::AUTO, headerHeight));
|
||||
@@ -125,8 +118,19 @@ void UISelectorViewController::viewDidLayoutSubviews() {
|
||||
float contHeight = contentView->getBounds().size.height;
|
||||
|
||||
float height = std::min(heightLimit, contHeight);
|
||||
if (!floatSame(scrollView->getBounds().size.height, height))
|
||||
if (!floatSame(scrollView->getBounds().size.height, height)) {
|
||||
scrollView->setHeight(height);
|
||||
|
||||
if (selectedView) {
|
||||
Application::shared()->setFocus(selectedView);
|
||||
|
||||
Rect focusedViewFrame = selectedView->getFrame();
|
||||
Point origin = selectedView->getSuperview()->convert(focusedViewFrame.origin, scrollView);
|
||||
origin.y -= height / 2 - focusedViewFrame.height() / 2;
|
||||
|
||||
scrollView->setContentOffset(origin, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UISelectorViewController::makeViewAppear(bool animated, UIViewController* presentingViewController, std::function<void()> completion) {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <Core/UIViewController/UIViewController.hpp>
|
||||
#include <Core/UIScrollView/UIScrollView.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
@@ -19,7 +20,6 @@ public:
|
||||
UISelectorViewController(std::string title, std::vector<std::string> data, std::function<void(int)> onComplete, int selectedIndex = -1);
|
||||
|
||||
void loadView() override;
|
||||
void viewWillAppear(bool animated) override;
|
||||
void viewDidLayoutSubviews() override;
|
||||
|
||||
protected:
|
||||
@@ -30,7 +30,7 @@ private:
|
||||
float headerHeight = 70;
|
||||
float footerHeight = 73;
|
||||
|
||||
UIView* scrollView = nullptr;
|
||||
UIScrollView* scrollView = nullptr;
|
||||
UIView* contentView = nullptr;
|
||||
UIView* containerView = nullptr;
|
||||
|
||||
|
||||
@@ -517,7 +517,7 @@ void UIView::applyAnimationContext(std::deque<float>* context) {
|
||||
}
|
||||
|
||||
void UIView::animate(float duration, std::function<void()> animations, EasingFunction easing, std::function<void(bool)> completion) {
|
||||
if (duration <= 0) {
|
||||
if (duration <= 0 || noAnimations) {
|
||||
animations();
|
||||
animationContext.reset(createAnimationContext());
|
||||
completion(true);
|
||||
@@ -879,6 +879,13 @@ float UIView::getBorderBottom() {
|
||||
}
|
||||
|
||||
void UIView::animate(std::initializer_list<UIView*> views, float duration, std::function<void()> animations, EasingFunction easing, std::function<void(bool)> completion) {
|
||||
// Maybe needs improvements
|
||||
if (noAnimations) {
|
||||
animations();
|
||||
completion(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (duration <= 0) {
|
||||
animations();
|
||||
for (UIView* view: views) {
|
||||
@@ -925,6 +932,15 @@ void UIView::animate(std::initializer_list<UIView*> views, float duration, std::
|
||||
}
|
||||
}
|
||||
|
||||
bool UIView::noAnimations = false;
|
||||
|
||||
void UIView::performWithoutAnimation(std::function<void()> function) {
|
||||
bool old = noAnimations;
|
||||
noAnimations = true;
|
||||
function();
|
||||
noAnimations = old;
|
||||
}
|
||||
|
||||
// Trait collection
|
||||
UITraitCollection UIView::getTraitCollection() {
|
||||
if (controller)
|
||||
|
||||
@@ -96,6 +96,8 @@ public:
|
||||
virtual void applyAnimationContext(std::deque<float>* context);
|
||||
void animate(float duration, std::function<void()> animations, EasingFunction easing = EasingFunction::linear, std::function<void(bool)> completion = [](bool res){});
|
||||
|
||||
static void performWithoutAnimation(std::function<void()> function);
|
||||
|
||||
void addGestureRecognizer(UIGestureRecognizer* gestureRecognizer);
|
||||
std::vector<UIGestureRecognizer*> getGestureRecognizers();
|
||||
|
||||
@@ -174,6 +176,7 @@ private:
|
||||
friend class UIViewController;
|
||||
friend class UITableView;
|
||||
|
||||
static bool noAnimations;
|
||||
std::optional<UIColor> tintColor;
|
||||
|
||||
AnimationContext animationContext;
|
||||
|
||||
Reference in New Issue
Block a user