Skip to content

Commit

Permalink
More RowView changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vorlias committed Aug 10, 2023
1 parent 64a891b commit cced9cf
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rbxts/zenui-core",
"version": "0.8.0",
"version": "0.8.1",
"description": "",
"main": "out/init.lua",
"scripts": {
Expand Down
71 changes: 45 additions & 26 deletions src/Layouts/RowView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export interface RowProps {
*/
readonly MaxHeight?: number;

// /**
// * Automatic Height
// */
// readonly AutomaticHeight?: boolean;
/**
* Automatic Height
*/
readonly AutomaticHeight?: boolean;

/**
* The minimum height of this row
Expand Down Expand Up @@ -68,6 +68,11 @@ interface RowViewDefaultProps {
*/
readonly RowWidth: UDim;

/**
* Automatic sizing rules
*/
readonly AutomaticSize?: Enum.AutomaticSize | InferEnumNames<Enum.AutomaticSize>;

/**
* Whether or not this `RowView` scrols
*/
Expand Down Expand Up @@ -174,27 +179,38 @@ export class RowView extends Roact.Component<RowViewProps> {
if (child.component === Row) {
const props = child.props as RowProps;

let height: UDim2;
let automaticSize: Enum.AutomaticSize = Enum.AutomaticSize.None;
const shouldAutoX = this.props.RowWidth === new UDim();
const shouldAutoY = props.AutomaticHeight === true;

if (props.Height) {
height = new UDim2(
this.props.RowWidth.Scale,
this.props.RowWidth.Offset,
props.Height.Scale,
props.Height.Offset,
);
} else {
height = new UDim2(
this.props.RowWidth.Scale,
this.props.RowWidth.Offset,
props.AutomaticHeight ? 0 : (1 + scaleOffset) * (1 / autoSizeCount),
widthOffset / autoSizeCount,
);
}

if (shouldAutoX && shouldAutoY) {
automaticSize = Enum.AutomaticSize.XY;
} else if (shouldAutoY) {
automaticSize = Enum.AutomaticSize.Y;
} else if (shouldAutoX) {
automaticSize = Enum.AutomaticSize.X;
}

containerMap.set(
key,
<View
LayoutOrder={idx}
Size={
props.Height
? new UDim2(
this.props.RowWidth.Scale,
this.props.RowWidth.Offset,
props.Height.Scale,
props.Height.Offset,
)
: new UDim2(
this.props.RowWidth.Scale,
this.props.RowWidth.Offset,
(1 + scaleOffset) * (1 / autoSizeCount),
widthOffset / autoSizeCount,
)
}
AutomaticSize={this.props.RowWidth === new UDim() ? "X" : "None"}
>
<View LayoutOrder={idx} Size={height} AutomaticSize={automaticSize}>
{(props.MaxHeight !== undefined || props.MinHeight !== undefined) && (
<uisizeconstraint
Key="ColumnItemSizeConstraint"
Expand Down Expand Up @@ -241,7 +257,7 @@ export class RowView extends Roact.Component<RowViewProps> {
BackgroundTransparency={1}
Size={this.props.Size}
{...properties}
AutomaticSize={this.props.RowWidth !== new UDim() ? "None" : "X"}
AutomaticSize={this.props.AutomaticSize ?? (this.props.RowWidth !== new UDim() ? "None" : "X")}
CanvasSize={this.contentsSize.map((size) => new UDim2(0, size.X, 0, size.Y))}
>
<uilistlayout
Expand All @@ -250,7 +266,7 @@ export class RowView extends Roact.Component<RowViewProps> {
SortOrder="LayoutOrder"
FillDirection="Vertical"
Padding={colPadding}
VerticalAlignment={this.props.VerticalAlignment ?? "Center"}
VerticalAlignment={this.props.VerticalAlignment ?? "Top"}
/>
{(this.props.MinSize !== undefined || this.props.MaxSize !== undefined) && (
<uisizeconstraint
Expand All @@ -265,7 +281,10 @@ export class RowView extends Roact.Component<RowViewProps> {
);
} else {
return (
<View Size={this.props.Size} AutomaticSize={this.props.RowWidth !== new UDim() ? "None" : "X"}>
<View
Size={this.props.Size}
AutomaticSize={this.props.AutomaticSize ?? (this.props.RowWidth !== new UDim() ? "None" : "X")}
>
<uilistlayout
Ref={this.layoutRef}
Key="RowLayout"
Expand Down

0 comments on commit cced9cf

Please sign in to comment.