From f35fdae0384adee12703c540afe181182ea2fdc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BF=9E=E6=BC=AA?= Date: Thu, 27 Feb 2025 09:51:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9pc=20menubar=E9=A1=B6?= =?UTF-8?q?=E8=BE=B9=E8=B7=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 连漪 --- .../interfaces/custom_app_bar_forpc.js | 37 ++++++------------- customappbar/source/custom_app_bar_forpc.ets | 24 ++++++------ 2 files changed, 23 insertions(+), 38 deletions(-) diff --git a/customappbar/interfaces/custom_app_bar_forpc.js b/customappbar/interfaces/custom_app_bar_forpc.js index 2d726b3..c5610c7 100644 --- a/customappbar/interfaces/custom_app_bar_forpc.js +++ b/customappbar/interfaces/custom_app_bar_forpc.js @@ -28,16 +28,14 @@ const MENU_RADIUS = 15.5; const DIVIDER_HEIGHT = 16.5; const DIVIDER_WIDTH = 0.5; const MENU_BUTTON_MARGIN = 2; -const VIEW_MARGIN_TOP = 18; +const VIEW_MARGIN_TOP = 14; const VIEW_MARGIN_RIGHT = 24; -const MENU_MARGIN_TOP = 10; const MENU_BACK_BLUR = 5; const MENU_BORDER_WIDTH = '0.5px'; const ICON_FILL_COLOR_DEFAULT = '#182431'; const BORDER_COLOR_DEFAULT = '#33000000'; const MENU_BACK_COLOR = '#99FFFFFF'; const ARKUI_APP_BAR_COLOR_CONFIGURATION = 'arkui_app_bar_color_configuration'; -const ARKUI_APP_BAR_MENU_SAFE_AREA = 'arkui_app_bar_menu_safe_area'; const ARKUI_APP_BAR_CONTENT_SAFE_AREA = 'arkui_app_bar_content_safe_area'; const ARKUI_APP_BG_COLOR = 'arkui_app_bg_color'; const maximizeButtonResourceId = 125829923; @@ -90,7 +88,6 @@ export class CustomAppBarForPC extends ViewPU { this.__contentMarginLeft = new ObservedPropertySimplePU('0vp', this, 'contentMarginLeft'); this.__contentMarginRight = new ObservedPropertySimplePU('0vp', this, 'contentMarginRight'); this.__contentMarginBottom = new ObservedPropertySimplePU('0vp', this, 'contentMarginBottom'); - this.__menuMarginTop = new ObservedPropertySimplePU('10vp', this, 'menuMarginTop'); this.__isAdaptPC = new ObservedPropertySimplePU(false, this, 'isAdaptPC'); this.__maximizeResource = new ObservedPropertyObjectPU(this.getIconResource(maximizeButtonResourceId), this, 'maximizeResource'); this.isDark = true; @@ -132,9 +129,6 @@ export class CustomAppBarForPC extends ViewPU { if (params.contentMarginBottom !== undefined) { this.contentMarginBottom = params.contentMarginBottom; } - if (params.menuMarginTop !== undefined) { - this.menuMarginTop = params.menuMarginTop; - } if (params.isAdaptPC !== undefined) { this.isAdaptPC = params.isAdaptPC; } @@ -162,7 +156,6 @@ export class CustomAppBarForPC extends ViewPU { this.__contentMarginLeft.purgeDependencyOnElmtId(rmElmtId); this.__contentMarginRight.purgeDependencyOnElmtId(rmElmtId); this.__contentMarginBottom.purgeDependencyOnElmtId(rmElmtId); - this.__menuMarginTop.purgeDependencyOnElmtId(rmElmtId); this.__isAdaptPC.purgeDependencyOnElmtId(rmElmtId); this.__maximizeResource.purgeDependencyOnElmtId(rmElmtId); } @@ -178,7 +171,6 @@ export class CustomAppBarForPC extends ViewPU { this.__contentMarginLeft.aboutToBeDeleted(); this.__contentMarginRight.aboutToBeDeleted(); this.__contentMarginBottom.aboutToBeDeleted(); - this.__menuMarginTop.aboutToBeDeleted(); this.__isAdaptPC.aboutToBeDeleted(); this.__maximizeResource.aboutToBeDeleted(); SubscriberManager.Get().delete(this.id__()); @@ -250,12 +242,6 @@ export class CustomAppBarForPC extends ViewPU { set contentMarginBottom(newValue) { this.__contentMarginBottom.set(newValue); } - get menuMarginTop() { - return this.__menuMarginTop.get(); - } - set menuMarginTop(newValue) { - this.__menuMarginTop.set(newValue); - } get isAdaptPC() { return this.__isAdaptPC.get(); } @@ -293,22 +279,25 @@ export class CustomAppBarForPC extends ViewPU { this.windowClass = data; this.windowClass?.setWindowDecorVisible(false); this.windowClass?.setWindowTitleButtonVisible(false, false, false); + this.updateMaximizeResource(this.windowClass?.getWindowStatus()); this.windowClass?.on('windowStatusChange', (windowStatusType) => { console.info('windowStatusChange windowStatusType: ' + JSON.stringify(windowStatusType)); - if (windowStatusType === window.WindowStatusType.FULL_SCREEN) { - this.maximizeResource = this.getIconResource(recoverButtonResourceId); - } - else { - this.maximizeResource = this.getIconResource(maximizeButtonResourceId); - } + this.updateMaximizeResource(windowStatusType); }); - }).catch((err) => { if (err.code) { console.error(`Failed to obtain the main window. Cause code: ${err.code}, message: ${err.message}`); } }); } + updateMaximizeResource(windowStatusType) { + if (windowStatusType === window.WindowStatusType.FULL_SCREEN || + windowStatusType === window.WindowStatusType.SPLIT_SCREEN) { + this.maximizeResource = this.getIconResource(recoverButtonResourceId); + } else { + this.maximizeResource = this.getIconResource(maximizeButtonResourceId); + } + } aboutToDisappear() { this.windowClass?.off('windowStatusChange'); } @@ -336,10 +325,6 @@ export class CustomAppBarForPC extends ViewPU { if (eventName === ARKUI_APP_BAR_COLOR_CONFIGURATION) { this.onColorConfigurationUpdate(this.parseBoolean(param)); } - else if (eventName === ARKUI_APP_BAR_MENU_SAFE_AREA) { - let value = Number(param) + MENU_MARGIN_TOP; - this.menuMarginTop = value.toString(); - } else if (eventName === ARKUI_APP_BAR_CONTENT_SAFE_AREA) { //top left right bottom let splitArray = param.split('|'); diff --git a/customappbar/source/custom_app_bar_forpc.ets b/customappbar/source/custom_app_bar_forpc.ets index e6b60e8..ee914ab 100644 --- a/customappbar/source/custom_app_bar_forpc.ets +++ b/customappbar/source/custom_app_bar_forpc.ets @@ -25,9 +25,8 @@ const MENU_RADIUS: number = 15.5; const DIVIDER_HEIGHT: number = 16.5; const DIVIDER_WIDTH: number = 0.5; const MENU_BUTTON_MARGIN: number = 2; -const VIEW_MARGIN_TOP: number = 18; +const VIEW_MARGIN_TOP: number = 14; const VIEW_MARGIN_RIGHT: number = 24; -const MENU_MARGIN_TOP: number = 10; const MENU_BACK_BLUR: number = 5; const MENU_BORDER_WIDTH: string = '0.5px'; @@ -36,7 +35,6 @@ const BORDER_COLOR_DEFAULT: string = '#33000000'; const MENU_BACK_COLOR: string = '#99FFFFFF'; const ARKUI_APP_BAR_COLOR_CONFIGURATION: string = 'arkui_app_bar_color_configuration'; -const ARKUI_APP_BAR_MENU_SAFE_AREA: string = 'arkui_app_bar_menu_safe_area'; const ARKUI_APP_BAR_CONTENT_SAFE_AREA: string = 'arkui_app_bar_content_safe_area'; const ARKUI_APP_BG_COLOR: string = 'arkui_app_bg_color'; const maximizeButtonResourceId: number = 125829923; @@ -88,7 +86,6 @@ export struct CustomAppBarForPC { @State contentMarginLeft: string = '0vp'; @State contentMarginRight: string = '0vp'; @State contentMarginBottom: string = '0vp'; - @State menuMarginTop: string = '10vp'; @State isAdaptPC: boolean = false; @State maximizeResource: Resource = this.getIconResource(maximizeButtonResourceId); private isDark: boolean = true; @@ -121,13 +118,10 @@ export struct CustomAppBarForPC { this.windowClass = data; this.windowClass?.setWindowDecorVisible(false); this.windowClass?.setWindowTitleButtonVisible(false, false, false); + this.updateMaximizeResource(this.windowClass?.getWindowStatus()); this.windowClass?.on('windowStatusChange', (windowStatusType) => { console.info('windowStatusChange windowStatusType: ' + JSON.stringify(windowStatusType)); - if (windowStatusType === window.WindowStatusType.FULL_SCREEN) { - this.maximizeResource = this.getIconResource(recoverButtonResourceId); - } else { - this.maximizeResource = this.getIconResource(maximizeButtonResourceId); - } + this.updateMaximizeResource(windowStatusType); }); } ).catch((err: BusinessError) => { @@ -137,6 +131,15 @@ export struct CustomAppBarForPC { }); } + updateMaximizeResource(windowStatusType: window.WindowStatusType): void { + if (windowStatusType === window.WindowStatusType.FULL_SCREEN || + windowStatusType === window.WindowStatusType.SPLIT_SCREEN) { + this.maximizeResource = this.getIconResource(recoverButtonResourceId); + } else { + this.maximizeResource = this.getIconResource(maximizeButtonResourceId); + } + } + aboutToDisappear(): void { this.windowClass?.off('windowStatusChange'); } @@ -166,9 +169,6 @@ export struct CustomAppBarForPC { setCustomCallback(eventName: string, param: string) { if (eventName === ARKUI_APP_BAR_COLOR_CONFIGURATION) { this.onColorConfigurationUpdate(this.parseBoolean(param)); - } else if (eventName === ARKUI_APP_BAR_MENU_SAFE_AREA) { - let value = Number(param) + MENU_MARGIN_TOP; - this.menuMarginTop = value.toString(); } else if (eventName === ARKUI_APP_BAR_CONTENT_SAFE_AREA) { //top left right bottom let splitArray: string[] = param.split('|'); -- Gitee