调整一些组件间隔,尺寸

This commit is contained in:
JackLee 2026-03-18 12:38:28 +08:00
parent 68e72767dd
commit 1fe0238d87
9 changed files with 32 additions and 260 deletions

View File

@ -1,31 +0,0 @@
/*
* Copyright (c) 2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// [Start Common_ContextUtils]
export class ContextUtils {
public static context: Context | undefined;
static setContext(context: Context): void {
ContextUtils.context = context;
}
static getContext(uiContext?: UIContext): Context | undefined {
if (uiContext) {
return uiContext.getHostContext();
}
return ContextUtils.context;
}
}
// [End Common_ContextUtils]

View File

@ -1,57 +0,0 @@
/*
* Copyright (c) 2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// [Start Common_PixelUtils]
import { hilog } from '@kit.PerformanceAnalysisKit';
import { display } from '@kit.ArkUI';
const DOMAIN = 0x0000;
export class PixelUtils {
public static uiContext: UIContext | undefined;
static setUIContext(uiContext: UIContext): void {
PixelUtils.uiContext = uiContext;
}
static vp2px(vpValue: number, uiContext?: UIContext): number | undefined {
let _uiContext = uiContext ?? PixelUtils.uiContext;
if (!_uiContext || !_uiContext.isAvailable()) {
let displayClass = display.getDefaultDisplaySync();
let density = displayClass.densityPixels;
return vpValue * density;
}
return _uiContext.vp2px(vpValue)
}
static fp2px(fpValue: number, uiContext?: UIContext): number | undefined {
let _uiContext = uiContext ?? PixelUtils.uiContext;
if (!_uiContext || !_uiContext.isAvailable()) {
hilog.error(DOMAIN, 'testTag', `Can't get UIContext`);
return undefined;
}
return _uiContext.fp2px(fpValue)
}
lpx2px(lpxValue: number, uiContext?: UIContext): number | undefined {
let _uiContext = uiContext ?? PixelUtils.uiContext;
if (!_uiContext || !_uiContext.isAvailable()) {
hilog.error(DOMAIN, 'testTag', `Can't get UIContext`);
return undefined;
}
return _uiContext.lpx2px(lpxValue)
}
}
// [End Common_PixelUtils]

View File

@ -1,60 +0,0 @@
/*
* Copyright (c) 2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// [Start Common_Utils]
// common/Utils.ets
import { hilog } from '@kit.PerformanceAnalysisKit';
const DOMAIN = 0x0000;
export class PixelUtil {
static uiContext: UIContext | undefined;
static setUIContext(uiContext: UIContext): void {
PixelUtil.uiContext = uiContext;
}
static removeUIContext(): void {
PixelUtil.uiContext = undefined;
}
static vp2px(vpValue: number, uiContext?: UIContext): number | undefined {
let _uiContext = uiContext ?? PixelUtil.uiContext;
if (!_uiContext || !_uiContext.isAvailable()) {
hilog.error(DOMAIN, 'testTag', `Can't get UIContext`);
return undefined;
}
return _uiContext.vp2px(vpValue)
}
static fp2px(fpValue: number, uiContext?: UIContext): number | undefined {
let _uiContext = uiContext ?? PixelUtil.uiContext;
if (!_uiContext || !_uiContext.isAvailable()) {
hilog.error(DOMAIN, 'testTag', `Can't get UIContext`);
return undefined;
}
return _uiContext.fp2px(fpValue)
}
lpx2px(lpxValue: number, uiContext?: UIContext): number | undefined {
let _uiContext = uiContext ?? PixelUtil.uiContext;
if (!_uiContext || !_uiContext.isAvailable()) {
hilog.error(DOMAIN, 'testTag', `Can't get UIContext`);
return undefined;
}
return _uiContext.lpx2px(lpxValue)
}
}
// [End Common_Utils]

View File

@ -1,62 +0,0 @@
/*
* Copyright (c) 2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// [Start Common_WindowUtils]
// common/WindowUtils.ets
import { display, window } from '@kit.ArkUI';
import { hilog } from '@kit.PerformanceAnalysisKit';
const DOMAIN = 0x0000;
export class WindowUIContextUtils {
public static activeUIContext: UIContext | undefined;
static registerWindowCallback(windowClass: window.Window): void {
try {
windowClass.on('windowEvent', (event: window.WindowEventType) => {
if (event === window.WindowEventType.WINDOW_ACTIVE) {
try {
let uiContext = windowClass.getUIContext();
WindowUIContextUtils.activeUIContext = uiContext;
} catch (exception) {
hilog.error(DOMAIN, 'testTag', `Can't get UIContext, ${exception}`);
}
}
});
} catch (exception) {
console.error(`Failed to unregister callback. Cause: ${exception}`);
}
}
static unregisterWindowCallback(windowClass: window.Window): void {
windowClass.off('windowEvent');
}
static setActiveUIContext(uiContext: UIContext): void {
WindowUIContextUtils.activeUIContext = uiContext;
}
static vp2px(vpValue: number, uiContext?: UIContext): number {
let _uiContext = uiContext ?? WindowUIContextUtils.activeUIContext;
if (!_uiContext || !_uiContext.isAvailable()) {
let displayClass = display.getDefaultDisplaySync();
let density = displayClass.densityPixels;
return vpValue * density;
}
return _uiContext.vp2px(vpValue);
}
}
// [End Common_WindowUtils]

View File

@ -1,8 +1,6 @@
import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { window,display,AppStorageV2} from '@kit.ArkUI';
import { WindowUIContextUtils } from '../common/WindowUtils';
import { PixelUtils } from '../common/UIContext';
const DOMAIN = 0x0000;
@ -24,8 +22,6 @@ export default class EntryAbility extends UIAbility {
// Main window is created, set main page for this ability
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
let window = windowStage.getMainWindowSync();
// 注册主窗的回调。
WindowUIContextUtils.registerWindowCallback(window);
windowStage.loadContent('pages/Index', (err) => {
if (err.code) {
hilog.error(DOMAIN, 'Tag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err));
@ -33,13 +29,7 @@ export default class EntryAbility extends UIAbility {
}
AppStorage.setOrCreate('windowStage', windowStage);
let uiContext = window.getUIContext();
PixelUtils.setUIContext(uiContext);
// 主窗获焦可能早于loadContent完成需要在成功后设置保证有效。
WindowUIContextUtils.setActiveUIContext(uiContext)
if (!uiContext) {
hilog.error(DOMAIN, 'testTag', `Can't get UIContext`);
return;
}
let screenWidth:number=display.getDefaultDisplaySync().width;
let screenHeight:number=display.getDefaultDisplaySync().height;
//定义新的宽度和高度(单位:虚拟像素)

View File

@ -11,36 +11,36 @@ import { TitleData } from '../LayoutInterface/Layout/TabContent';
export struct EventBtn {
@Param eventBtn: TitleButton | undefined = undefined;
build() {
Column({ space: 2 }) {
Column({ space: 0 }) {
if (this.eventBtn != undefined) {
Button()
.width('35vp')
.height('35vp')
.width(35)
.height(35)
.backgroundImage($r('app.media.' + this.eventBtn.eIcon))
.backgroundImagePosition({ x: '10%', y: '10%' })
.backgroundImagePosition({ x: '5%', y: '5%' })
.backgroundColor(Color.Transparent)
.backgroundImageSize({
width: '80%', // 图片宽度占满按钮
height: '80%' // 图片高度占满按钮
width: '90%', // 图片宽度占满按钮
height: '90%' // 图片高度占满按钮
})
.onClick(()=>{
ExecuteCommand(this.eventBtn as TitleButton);
})
Text()
.width('50vp')
.height('7vp')
.width(50)
.height(7)
.backgroundColor(Color.Transparent)
Text(this.eventBtn.eName)
.fontSize('8fp')
.width('50vp')
.height('10vp')
.fontSize(10)
.width(50)
.height(10)
.textAlign(TextAlign.Center)
.backgroundColor(Color.Transparent)
}
}
.height('50vp')
.width('50vp')
.padding('1vp')
.height(50)
.width(50)
.padding(1)
}
}

View File

@ -79,37 +79,37 @@ export struct MenuBtn {
}
build() {
Column({ space: 2 }) {
Column({ space: 0 }) {
if (this.menuBtn != undefined) {
Button()
.bindMenu(this.EventMenu)
.width('35vp')
.height('35vp')
.width(35)
.height(35)
.backgroundImage($r('app.media.' + this.menuBtn[this.curtIndex].eIcon))
.backgroundImagePosition({ x: '10%', y: '10%' })
.backgroundImagePosition({ x: '5%', y: '5%' })
.backgroundColor(Color.Transparent)
.backgroundImageSize({
width: '80%', // 图片宽度占满按钮
height: '80%' // 图片高度占满按钮
width: '90%', // 图片宽度占满按钮
height: '90%' // 图片高度占满按钮
})
Button()
.bindMenu(this.EventMenu)
.width('50vp')
.height('7vp')
.width(50)
.height(7)
.backgroundImage($r('app.media.base_chevron_down'))
.backgroundImagePosition({ x: '35%', y: '-50%' })
.backgroundColor(Color.Transparent)
Text(this.menuBtn[this.curtIndex].eName)
.fontSize('8fp')
.width('50vp')
.height('10vp')
.fontSize(10)
.width(50)
.height(10)
.textAlign(TextAlign.Center)
}
}
.height('50vp')
.width('50vp')
.padding('1vp')
.height(50)
.width(50)
.padding(1)
}
}

View File

@ -6,12 +6,6 @@ import {ModelViewTab} from './modelViewTab'
import {TitleColumnSub} from './TitleTabLayout/TitleColumnSub'
const DOMAIN = 0x0000;
let displayClass: display.Display | null = null;
try {
displayClass = display.getDefaultDisplaySync();
} catch (exception) {
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
}
@Entry
@Component
struct Index {
@ -43,7 +37,7 @@ struct Index {
.padding(1)
Column(){
Text('状态栏').height('100%').width('100%')
}.height('5%').borderWidth('1vp')
}.height('5%').borderWidth(1)
}.width('100%')
.height('100%')
}

View File

@ -48,8 +48,7 @@ export struct TitleTab {
Row({space:0}) {
Button(TitleData.mFileModel.cmName)
.height(25)
.width(60)
.padding(5)
.width(100)
.bindMenu(this.FileMenu(TitleData.mFileModel.cmEvents as Array<TitleButton>))
.type(ButtonType.Normal)
.backgroundColor(Color.Brown)
@ -57,8 +56,7 @@ export struct TitleTab {
Button(item.cmName)
.fontWeight(index === this.titleBarFocusIndex ? FontWeight.Bold : FontWeight.Normal)
.height(25)
.width(60)
.padding(5)
.width(100)
.type(ButtonType.Normal)
.backgroundColor(index === this.titleBarFocusIndex ? Color.Blue : Color.Brown)
.onClick(() => {