feat(ui): add ScrollView content alignment options#141
Open
orchid-world wants to merge 1 commit into
Open
Conversation
Add horizontal and vertical content alignment options for ScrollView when content is smaller than the view. The default remains left/top to preserve existing behavior. Also add editor tooltip localization for the new alignment properties.
Code Size Check Report
Interface Check Report! WARNING this pull request has changed these public interfaces:
@@ -57294,8 +57294,10 @@
* 滚动视图组件。
*/
export class ScrollView extends ViewGroup {
static EventType: typeof __private._cocos_ui_scroll_view__ScrollViewEventType;
+ static HorizontalContentAlign: typeof __private._cocos_ui_scroll_view__ScrollViewHorizontalContentAlign;
+ static VerticalContentAlign: typeof __private._cocos_ui_scroll_view__ScrollViewVerticalContentAlign;
/**
* @en
* The elapse time of bouncing back. A value of 0 will bounce back immediately.
*
@@ -57346,8 +57348,17 @@
*/
horizontal: boolean;
/**
* @en
+ * Horizontal alignment used when the content is not wider than the view.
+ *
+ * @zh
+ * 当内容宽度不大于视图时使用的水平对齐方式。
+ */
+ get horizontalContentAlign(): __private._cocos_ui_scroll_view__ScrollViewHorizontalContentAlign;
+ set horizontalContentAlign(value: __private._cocos_ui_scroll_view__ScrollViewHorizontalContentAlign);
+ /**
+ * @en
* The horizontal scrollbar reference.
* @zh
* 水平滚动的 ScrollBar。
*/
@@ -57362,8 +57373,17 @@
*/
vertical: boolean;
/**
* @en
+ * Vertical alignment used when the content is not taller than the view.
+ *
+ * @zh
+ * 当内容高度不大于视图时使用的垂直对齐方式。
+ */
+ get verticalContentAlign(): __private._cocos_ui_scroll_view__ScrollViewVerticalContentAlign;
+ set verticalContentAlign(value: __private._cocos_ui_scroll_view__ScrollViewVerticalContentAlign);
+ /**
+ * @en
* The vertical scrollbar reference.
*
* @zh
* 垂直滚动的 ScrollBar。
@@ -57397,8 +57417,10 @@
protected _scrolling: boolean;
protected _content: Node | null;
protected _horizontalScrollBar: ScrollBar | null;
protected _verticalScrollBar: ScrollBar | null;
+ protected _horizontalContentAlign: __private._cocos_ui_scroll_view__ScrollViewHorizontalContentAlign;
+ protected _verticalContentAlign: __private._cocos_ui_scroll_view__ScrollViewVerticalContentAlign;
protected _topBoundary: number;
protected _bottomBoundary: number;
protected _leftBoundary: number;
protected _rightBoundary: number;
@@ -57767,9 +57789,23 @@
protected _isNecessaryAutoScrollBrake(): boolean;
protected _processAutoScrolling(dt: any): void;
protected _checkMouseWheel(dt: number): void;
protected _calculateMovePercentDelta(options: any): math.Vec3;
- protected _moveContentToTopLeft(scrollViewSize: math.Size): void;
+ /**
+ * @en Aligns the content when its size does not fill the view on one or both axes.
+ * @zh 当内容在某个轴向没有填满视图时,按照配置对齐内容。
+ */
+ protected _alignContentIfNeeded(scrollViewSize: math.Size): void;
+ /**
+ * @en Gets the horizontal movement needed to align the content in the view.
+ * @zh 获取将内容按水平配置对齐到视图中所需的位移。
+ */
+ protected _getHorizontalContentAlignDelta(): number;
+ /**
+ * @en Gets the vertical movement needed to align the content in the view.
+ * @zh 获取将内容按垂直配置对齐到视图中所需的位移。
+ */
+ protected _getVerticalContentAlignDelta(): number;
protected _scaleChanged(value: TransformBit): void;
protected _xrHoverEnter(event: XrUIPressEvent): void;
protected _xrHoverExit(event: XrUIPressEvent): void;
protected _xrThumbStickMove(event: math.Vec2): void;
@@ -74230,8 +74266,56 @@
* 当用户松手的时候会发出一个事件。
*/
TOUCH_UP = "touch-up"
}
+ /**
+ * @en
+ * Enum for the horizontal alignment of the content when it is not wider than the ScrollView.
+ *
+ * @zh
+ * 当内容宽度不大于 ScrollView 时,内容的水平对齐方式。
+ */
+ export enum _cocos_ui_scroll_view__ScrollViewHorizontalContentAlign {
+ /**
+ * @en Align the content to the left side of the view.
+ * @zh 将内容对齐到视图左侧。
+ */
+ LEFT = 0,
+ /**
+ * @en Align the content to the horizontal center of the view.
+ * @zh 将内容对齐到视图水平中心。
+ */
+ CENTER = 1,
+ /**
+ * @en Align the content to the right side of the view.
+ * @zh 将内容对齐到视图右侧。
+ */
+ RIGHT = 2
+ }
+ /**
+ * @en
+ * Enum for the vertical alignment of the content when it is not taller than the ScrollView.
+ *
+ * @zh
+ * 当内容高度不大于 ScrollView 时,内容的垂直对齐方式。
+ */
+ export enum _cocos_ui_scroll_view__ScrollViewVerticalContentAlign {
+ /**
+ * @en Align the content to the top side of the view.
+ * @zh 将内容对齐到视图顶部。
+ */
+ TOP = 0,
+ /**
+ * @en Align the content to the vertical center of the view.
+ * @zh 将内容对齐到视图垂直中心。
+ */
+ CENTER = 1,
+ /**
+ * @en Align the content to the bottom side of the view.
+ * @zh 将内容对齐到视图底部。
+ */
+ BOTTOM = 2
+ }
export enum _cocos_ui_scroll_view__XrhoverType {
NONE = 0,
LEFT = 1,
RIGHT = 2
|
Contributor
|
@cocos-robot run test cases |
|
@orchid-world, Please check the result of
Task Details
|
|
@orchid-world, Please check the result of
Task Details
|
Contributor
|
Package size increased a bit. Maybe we can find a way to reduce code size. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add horizontal and vertical content alignment options for ScrollView when content is smaller than the view. The default remains left/top to preserve existing behavior.
Also add editor tooltip localization for the new alignment properties.
Re: #
Changelog
Continuous Integration
This pull request:
Compatibility Check
This pull request: