/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
//#define ENABLED_SCROLL_STATE_LOGGING
#ifdef ENABLED_SCROLL_STATE_LOGGING
-#define DALI_LOG_SCROLL_STATE(format, ...) Dali::Integration::Log::LogMessageWithFunctionLine(Dali::Integration::Log::DebugInfo, "%s:%d " format "\n", __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
+#define DALI_LOG_SCROLL_STATE(format, ...) Dali::Integration::Log::LogMessageWithFunctionLine(Dali::Integration::Log::INFO, "%s:%d " format "\n", __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#define DALI_LOG_SCROLL_STATE(format, ...)
#endif
}
}
+Dali::Vector2 GetPosition(Dali::Actor actor)
+{
+ Vector2 screenPosition = actor.GetProperty<Vector2>(Actor::Property::SCREEN_POSITION);
+ Vector3 size = actor.GetCurrentProperty<Vector3>(Actor::Property::SIZE) * actor.GetCurrentProperty<Vector3>(Actor::Property::WORLD_SCALE);
+ bool positionUsesAnchorPoint = actor.GetProperty<bool>(Actor::Property::POSITION_USES_ANCHOR_POINT);
+ Vector3 anchorPointOffSet = size * (positionUsesAnchorPoint ? actor.GetCurrentProperty<Vector3>(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT);
+ Vector2 position = Vector2(screenPosition.x - anchorPointOffSet.x, screenPosition.y - anchorPointOffSet.y);
+
+ return position;
+}
+
} // unnamed namespace
namespace Dali
return false;
}
- // child can be one of descendants
- // find direct child of ScrollView to avoid the ASSERT in ScrollTo
- auto parent = child.GetParent();
- while (parent && parent != Self())
- {
- child = parent;
- parent = child.GetParent();
- }
- if (!parent)
- {
- return false;
- }
+ auto childPosition = GetPosition(child);
+ auto selfPosition = GetPosition(Self());
+
+ scrollView.ScrollTo(childPosition - selfPosition, scrollView.GetScrollFlickDuration());
- // FIXME: ScrollTo does not work (snaps back to original position)
- scrollView.ScrollTo(child, scrollView.GetScrollFlickDuration());
return true;
}