去掉多余的嵌套
This commit is contained in:
parent
ec474c43d9
commit
c49f7d821f
@ -43,81 +43,79 @@ export struct TitleBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Row() {
|
RelativeContainer() {
|
||||||
RelativeContainer() {
|
if (this.leftMenuType != TitleBarMenuType.None) {
|
||||||
if (this.leftMenuType != TitleBarMenuType.None) {
|
Button() {
|
||||||
Button() {
|
if (this.leftMenuType == TitleBarMenuType.Icon) {
|
||||||
if (this.leftMenuType == TitleBarMenuType.Icon) {
|
Image(this.leftIcon)
|
||||||
Image(this.leftIcon)
|
.setWidthAndHeight()
|
||||||
.setWidthAndHeight()
|
.padding(this.menuPadding)
|
||||||
.padding(this.menuPadding)
|
} else {
|
||||||
} else {
|
Text(this.leftText)
|
||||||
Text(this.leftText)
|
.textAlign(TextAlign.Center)
|
||||||
.textAlign(TextAlign.Center)
|
.setWidthAndHeight()
|
||||||
.setWidthAndHeight()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.setWidthAndHeight()
|
|
||||||
.backgroundColor(0xFFFFFF)
|
|
||||||
.type(ButtonType.Normal)
|
|
||||||
.stateEffect(true)
|
|
||||||
.onClick((event) => {
|
|
||||||
this.onLeftClicked?.(event);
|
|
||||||
})
|
|
||||||
.alignRules({
|
|
||||||
top: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Top },
|
|
||||||
left: { anchor: ComponentConst.ContainerId, align: HorizontalAlign.Start },
|
|
||||||
}).id("left_menu")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.titleVisible == Visibility.Visible) {
|
|
||||||
Text(this.title)
|
|
||||||
.textAlign(this.titleTextAlign)
|
|
||||||
.backgroundColor(0xFFFFFF)
|
|
||||||
.padding({
|
|
||||||
left: this.leftMenuType != TitleBarMenuType.None ? 0 : this.menuPadding,
|
|
||||||
right: this.rightMenuType != TitleBarMenuType.None ? 0 : this.menuPadding
|
|
||||||
})
|
|
||||||
.alignRules({
|
|
||||||
top: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Top },
|
|
||||||
left: {
|
|
||||||
anchor: this.leftMenuType != TitleBarMenuType.None ? "left_menu" : ComponentConst.ContainerId,
|
|
||||||
align: this.leftMenuType != TitleBarMenuType.None ? HorizontalAlign.End : HorizontalAlign.Start
|
|
||||||
},
|
|
||||||
right: {
|
|
||||||
anchor: this.rightMenuType != TitleBarMenuType.None ? "right_menu" : ComponentConst.ContainerId,
|
|
||||||
align: this.rightMenuType != TitleBarMenuType.None ? HorizontalAlign.Start : HorizontalAlign.End
|
|
||||||
},
|
|
||||||
bottom: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Bottom }
|
|
||||||
})
|
|
||||||
.id("title")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.rightMenuType != TitleBarMenuType.None) {
|
|
||||||
Button() {
|
|
||||||
if (this.rightMenuType == TitleBarMenuType.Icon) {
|
|
||||||
Image(this.rightIcon)
|
|
||||||
.setWidthAndHeight().padding(this.menuPadding)
|
|
||||||
} else {
|
|
||||||
Text(this.rightText)
|
|
||||||
.textAlign(TextAlign.Center)
|
|
||||||
.setWidthAndHeight()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.setWidthAndHeight()
|
|
||||||
.backgroundColor(0xFFFFFF)
|
|
||||||
.type(ButtonType.Normal)
|
|
||||||
.stateEffect(true)
|
|
||||||
.onClick((event) => {
|
|
||||||
this.onRightClicked?.(event);
|
|
||||||
})
|
|
||||||
.alignRules({
|
|
||||||
top: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Top },
|
|
||||||
right: { anchor: ComponentConst.ContainerId, align: HorizontalAlign.End },
|
|
||||||
}).id("right_menu")
|
|
||||||
}
|
}
|
||||||
|
.setWidthAndHeight()
|
||||||
|
.backgroundColor(0xFFFFFF)
|
||||||
|
.type(ButtonType.Normal)
|
||||||
|
.stateEffect(true)
|
||||||
|
.onClick((event) => {
|
||||||
|
this.onLeftClicked?.(event);
|
||||||
|
})
|
||||||
|
.alignRules({
|
||||||
|
top: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Top },
|
||||||
|
left: { anchor: ComponentConst.ContainerId, align: HorizontalAlign.Start },
|
||||||
|
}).id("left_menu")
|
||||||
}
|
}
|
||||||
.width('100%').height('100%')
|
|
||||||
}.height(this.barHeight)
|
if (this.titleVisible == Visibility.Visible) {
|
||||||
|
Text(this.title)
|
||||||
|
.textAlign(this.titleTextAlign)
|
||||||
|
.backgroundColor(0xFFFFFF)
|
||||||
|
.padding({
|
||||||
|
left: this.leftMenuType != TitleBarMenuType.None ? 0 : this.menuPadding,
|
||||||
|
right: this.rightMenuType != TitleBarMenuType.None ? 0 : this.menuPadding
|
||||||
|
})
|
||||||
|
.alignRules({
|
||||||
|
top: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Top },
|
||||||
|
left: {
|
||||||
|
anchor: this.leftMenuType != TitleBarMenuType.None ? "left_menu" : ComponentConst.ContainerId,
|
||||||
|
align: this.leftMenuType != TitleBarMenuType.None ? HorizontalAlign.End : HorizontalAlign.Start
|
||||||
|
},
|
||||||
|
right: {
|
||||||
|
anchor: this.rightMenuType != TitleBarMenuType.None ? "right_menu" : ComponentConst.ContainerId,
|
||||||
|
align: this.rightMenuType != TitleBarMenuType.None ? HorizontalAlign.Start : HorizontalAlign.End
|
||||||
|
},
|
||||||
|
bottom: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Bottom }
|
||||||
|
})
|
||||||
|
.id("title")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.rightMenuType != TitleBarMenuType.None) {
|
||||||
|
Button() {
|
||||||
|
if (this.rightMenuType == TitleBarMenuType.Icon) {
|
||||||
|
Image(this.rightIcon)
|
||||||
|
.setWidthAndHeight().padding(this.menuPadding)
|
||||||
|
} else {
|
||||||
|
Text(this.rightText)
|
||||||
|
.textAlign(TextAlign.Center)
|
||||||
|
.setWidthAndHeight()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.setWidthAndHeight()
|
||||||
|
.backgroundColor(0xFFFFFF)
|
||||||
|
.type(ButtonType.Normal)
|
||||||
|
.stateEffect(true)
|
||||||
|
.onClick((event) => {
|
||||||
|
this.onRightClicked?.(event);
|
||||||
|
})
|
||||||
|
.alignRules({
|
||||||
|
top: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Top },
|
||||||
|
right: { anchor: ComponentConst.ContainerId, align: HorizontalAlign.End },
|
||||||
|
}).id("right_menu")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.width('100%').height('100%').height(this.barHeight)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user