|
|
@@ -0,0 +1,77 @@
|
|
|
+import { hdsEffect } from "@kit.UIDesignKit"
|
|
|
+
|
|
|
+@Component
|
|
|
+export struct PointLightButton{
|
|
|
+ @BuilderParam builder:() => void
|
|
|
+ @Require isPx: boolean
|
|
|
+ @Require@Prop@Watch('setButtonSize') builderHeight: number
|
|
|
+ @Require@Prop@Watch('setButtonSize') builderWidth: number
|
|
|
+ // 可选
|
|
|
+ public buttonScale: number = 1.7
|
|
|
+ @State pointLightHeight: number = 100
|
|
|
+ public canShadow: boolean = true
|
|
|
+ public canPointLight: boolean = true
|
|
|
+
|
|
|
+
|
|
|
+ @StorageProp("EnablePointLight") enablePointLight: boolean = true
|
|
|
+ @StorageProp("EnableShadow") enableShadow: boolean = true
|
|
|
+
|
|
|
+ @StorageProp("SdkApiVersion") sdkApiVersion: number = 17
|
|
|
+ @State pointLightOptions: hdsEffect.PointLightOptions | undefined = undefined
|
|
|
+ @State buttonHeight: Length = 0
|
|
|
+ @State buttonWidth: Length = 0
|
|
|
+
|
|
|
+ aboutToAppear(): void {
|
|
|
+ this.setButtonSize()
|
|
|
+ }
|
|
|
+
|
|
|
+ setButtonSize(){
|
|
|
+ let buttonHeight = this.builderHeight * this.buttonScale
|
|
|
+ let buttonWidth = this.builderWidth * this.buttonScale
|
|
|
+ if(this.isPx){
|
|
|
+ this.buttonHeight = `${buttonHeight}px`
|
|
|
+ this.buttonWidth = `${buttonWidth}px`
|
|
|
+ }else{
|
|
|
+ this.buttonHeight = buttonHeight
|
|
|
+ this.buttonWidth = buttonWidth
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ build() {
|
|
|
+ if(this.enablePointLight){
|
|
|
+ Button(){
|
|
|
+ this.builder()
|
|
|
+ }
|
|
|
+ .hitTestBehavior(HitTestMode.Transparent)
|
|
|
+ .height(this.buttonHeight)
|
|
|
+ .width(this.buttonWidth)
|
|
|
+ .stateEffect(false)
|
|
|
+ .clickEffect({level:ClickEffectLevel.LIGHT,scale: 0.9})
|
|
|
+ .backgroundColor(Color.Transparent)
|
|
|
+ .type(ButtonType.Circle)
|
|
|
+ .onTouch((event: TouchEvent) => {
|
|
|
+ if (event.type === TouchType.Down) {
|
|
|
+ this.pointLightOptions = {
|
|
|
+ color: Color.White,
|
|
|
+ intensity: 1,
|
|
|
+ height: this.pointLightHeight
|
|
|
+ }
|
|
|
+ } else if (event.type === TouchType.Up || event.type === TouchType.Cancel) {
|
|
|
+ this.pointLightOptions = undefined
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .shadow(this.canShadow && this.enableShadow ? ShadowStyle.OUTER_DEFAULT_XS : undefined)
|
|
|
+ .visualEffect(this.canPointLight && this.sdkApiVersion >= 20 ?
|
|
|
+ new hdsEffect.HdsEffectBuilder()
|
|
|
+ .pointLight({
|
|
|
+ options: this.pointLightOptions,
|
|
|
+ illuminatedType: hdsEffect.PointLightIlluminatedType.BORDER_CONTENT
|
|
|
+ })
|
|
|
+ .buildEffect()
|
|
|
+ : undefined
|
|
|
+ )
|
|
|
+ }else{
|
|
|
+ this.builder()
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|