修复鼠标旋转模型

增加侧边栏图标和布局
This commit is contained in:
JackLee 2026-03-18 17:26:34 +08:00
parent 1fe0238d87
commit a99ebe39da
15 changed files with 131 additions and 76 deletions

View File

@ -216,6 +216,7 @@ void NativeManager::OnMouseEvent(OH_NativeXComponent *component, void *window) {
if(event.button==OH_NATIVEXCOMPONENT_LEFT_BUTTON&&event.action==OH_NATIVEXCOMPONENT_MOUSE_PRESS){
if(NativeManager::isMouseMiddleBtnPressed){
NativeManager::isMouseMiddleBtnPressed=false;
return;
}
//记录按下时候的X.Y坐标
NativeManager::lastMouseX_=event.x;
@ -226,13 +227,13 @@ void NativeManager::OnMouseEvent(OH_NativeXComponent *component, void *window) {
HILOG_WARN(NATIVE_TAG, "AtButton:%{public}d",event.button);
HILOG_WARN(NATIVE_TAG, "AtButtonAction:%{public}d",event.action);
HILOG_WARN(NATIVE_TAG, "AtisMouseMiddleBtnPressed:%{public}d",NativeManager::isMouseMiddleBtnPressed);
}else if(NativeManager::isMouseMiddleBtnPressed&&event.action==OH_NATIVEXCOMPONENT_MOUSE_MOVE){
}else if(event.action==OH_NATIVEXCOMPONENT_MOUSE_MOVE&&NativeManager::isMouseMiddleBtnPressed){
// 计算鼠标移动距离
float deltaX = curtX - NativeManager::lastMouseX_;
float deltaY = curtY - NativeManager::lastMouseY_;
// 将像素移动量映射到旋转角度
// 这里的系数可以根据需要调整灵敏度
float rotationSpeed = 0.005f;
float rotationSpeed = 0.003f;
float angleX = deltaX * rotationSpeed;
float angleY = deltaY * rotationSpeed;
// 通知渲染线程执行旋转

View File

@ -24,4 +24,23 @@ export struct Expandable {
.alignSelf(ItemAlign.Center)
}.width('100%')
}
}
@ComponentV2
export struct LeftSideTabExpan {
// 控制内容区域显示与隐藏的状态
@Consumer('isSubExpanded') isSubExpanded: boolean=true;
build(){
// 标题行
Row({ space: 0 }) {
// 切换按钮,显示向上或向下箭头
Button(this.isSubExpanded ? '◀' : '▶')
.type(ButtonType.Normal)
.fontSize(12)
.onClick(() => {
// 点击按钮时,切换 isSubExpanded 状态
this.isSubExpanded = !this.isSubExpanded;
})
}
}
}

View File

@ -1,9 +1,9 @@
import { hilog } from '@kit.PerformanceAnalysisKit';
import { edgeColors,display } from '@kit.ArkUI';
import {TitleTab} from './TitleTabLayout/TitleTab'
import {LeftSideTab} from './leftSideTab'
import {TitleTab} from './TitleLayout/TitleTab'
import {LeftSideTab} from './LeftSideTab'
import {ModelViewTab} from './modelViewTab'
import {TitleColumnSub} from './TitleTabLayout/TitleColumnSub'
import {TitleColumnSub} from './TitleLayout/TitleColumnSub'
const DOMAIN = 0x0000;
@Entry
@ -12,29 +12,35 @@ struct Index {
build() {
//OpenCAX主界面整体布局,采用多行布局
Column({space:1}) {
Column({space:0}) {
//头部导航功能区
TitleTab().height('auto').borderWidth('1vp')
TitleTab()
.height('auto')
.borderWidth(2)
.borderRadius(5)
//工具栏
Row() {
TitleColumnSub();
}.height('4%')
.width('100%')
.borderWidth('1vp')
.borderWidth(2)
.borderRadius(5)
.align(Alignment.Start)
.margin({ top: -2,left:0,bottom:0,right:0})
Row() {
//左侧边导航区
LeftSideTab().borderWidth('1vp').width('20%');
LeftSideTab().width("15%");
//中间操作区域
Row() {
ModelViewTab()
}.width('80%')
}.width('90%')
.height('100%')
.borderWidth('1vp')
.borderWidth(1)
.align(Alignment.Center)
}.height('80%')
.padding(1)
.padding(1)
.borderWidth(2)
.borderRadius(5)
.margin({ top: -2,left:0,bottom:0,right:0})
Column(){
Text('状态栏').height('100%').width('100%')
}.height('5%').borderWidth(1)

View File

@ -0,0 +1,8 @@
import { TitleButton } from "../Interface/ButtonInterface";
import { ModelType } from "./ModelType";
export let LeftSideBars:Array<TitleButton>=[
{eModel:[ModelType.BASE],eName:"装配导航器",eNamed:"",ePage:'',eIcon:"left_side_assembly",eTips:"正三轴测图",eEvent:""},
{eModel:[ModelType.BASE],eName:"约束导航器",eNamed:"",ePage:'',eIcon:"left_side_mate_components",eTips:"前视图",eEvent:""},
{eModel:[ModelType.BASE],eName:"部件导航器",eNamed:"",ePage:'',eIcon:"base_model_cad",eTips:"前视图",eEvent:""},
]

View File

@ -0,0 +1,81 @@
import { TitleButton } from './LayoutInterface/Interface/ButtonInterface';
import {LeftSideBars} from './LayoutInterface/Layout/LeftSideBar'
@ComponentV2
export struct LeftSideTab {
private leftSideBarTabs: TabsController = new TabsController();
@Local leftSideBarFocusIndex: number = 0;
@Local isExpanded:boolean=true;
@Local leftWidth:number=0;
build() {
Row() {
Column({space:1}){
Button()
.borderWidth(1)
.borderColor(Color.Grey)
.borderRadius(5)
.backgroundImagePosition({ x: '5%', y: '5%' })
.backgroundColor(Color.Transparent)
.backgroundImageSize({
width: '90%', // 图片宽度占满按钮
height: '90%' // 图片高度占满按钮
})
.backgroundImage(this.isExpanded ? $r('app.media.base_expand_on'):$r('app.media.base_expand_off'))
.type(ButtonType.Normal)
.width(50)
.height(50)
.onClick(()=>{
this.isExpanded = !this.isExpanded;
}).margin({ top: 2,left:1,bottom:0,right:2})
Scroll() {
Flex({ direction: FlexDirection.Column}) {
ForEach(LeftSideBars, (item: TitleButton, index: number) => {
Column({ space: 0 }) {
Button()
.borderWidth(1)
.borderColor(Color.Grey)
.borderRadius(5)
.backgroundImagePosition({ x: '5%', y: '5%' })
.backgroundColor(Color.Transparent)
.backgroundImageSize({
width: '90%', // 图片宽度占满按钮
height: '90%' // 图片高度占满按钮
})
.backgroundImage($r('app.media.'+item.eIcon))
.fontWeight(index === this.leftSideBarFocusIndex ? FontWeight.Bold : FontWeight.Normal)
.height(50)
.width(50)
.type(ButtonType.Normal)
.onClick(() => {
this.leftSideBarTabs.changeIndex(index);
this.leftSideBarFocusIndex = index;
})
}.margin({ top: 2,left:0,bottom:0,right:0})
})
Blank().height('95%')
}
}
.align(Alignment.Start)
.scrollable(ScrollDirection.Vertical)
.scrollBar(BarState.Off)
.width(50)
.height('100%')
}
Column({space:1}){
if (this.isExpanded) {
Column() {
Tabs({ barPosition: BarPosition.Start, controller: this.leftSideBarTabs }) {
ForEach(LeftSideBars, (item: TitleButton, index: number) => {
TabContent() {
Text(item.eName)
.fontSize(30)
}
})
}.barHeight(0)
}
}
}
}.width('auto')
}
}

View File

@ -77,7 +77,6 @@ export struct TitleTab {
TabContent() {
TitleTabContent({curtLayout:item})
}.align(Alignment.Start)
.padding(1)
.margin({ top: 0,left:0,bottom:0,right:0})
})
}.scrollable(false)

View File

@ -15,7 +15,7 @@ export struct TitleTabContent {
//迭代生成行容器
ForEach(this.curtLayout?.cmEvents, (row_items: Array<TitleButton|Array<TitleGroup>|Array<TitleButton>>, mIndex: number) => {
//行的按钮组容器
Row(){
Row({ space: 1 }){
ForEach(row_items, (row_item: TitleButton|Array<TitleGroup>|Array<TitleButton>, index: number) => {
if(!Array.isArray(row_item)){//TitleButton
//单按钮
@ -44,6 +44,7 @@ export struct TitleTabContent {
//功能组名
GroupTextEventMenu({grpEvent:group_item})
}.borderWidth(1)
.borderRadius(5)
.borderColor(Color.Grey)
})
}else{
@ -63,6 +64,6 @@ export struct TitleTabContent {
.borderColor(Color.Gray)
})
}.margin({ top: 1,left:1,bottom:1,right:1})
.borderWidth(1)
//.borderWidth(1)
}
}

View File

@ -1,60 +0,0 @@
import { hilog } from '@kit.PerformanceAnalysisKit';
interface LeftSideTabName {
//标签名
str: string;
//图标名
ico: string;
//页面名
page:string;
}
@Component
export struct LeftSideTab {
@State leftSideBarTabsName:Array<LeftSideTabName>=[
{str:'建模树',ico:'',page:''},
{str:'组装树',ico:'',page:''},
]
private leftSideBarTabs: TabsController = new TabsController();
@State leftSideBarFocusIndex: number = 0;
build() {
Row() {
Scroll() {
Flex({ direction: FlexDirection.Column }) {
ForEach(this.leftSideBarTabsName, (item: LeftSideTabName, index: number) => {
Column({ space: 5 }) {
Button(item.str)
.fontWeight(index === this.leftSideBarFocusIndex ? FontWeight.Bold : FontWeight.Normal)
.height(50)
.width(50)
.padding(5)
.type(ButtonType.Normal)
}
.padding({ left: 5, right: 5 })
.margin({ top: 2,left:2,bottom:2,right:2})
.onClick(() => {
this.leftSideBarTabs.changeIndex(index);
this.leftSideBarFocusIndex = index;
})
})
Blank().height('80%')
}
}
.align(Alignment.Start)
.scrollable(ScrollDirection.Vertical)
.scrollBar(BarState.Off)
.width('30%')
Tabs({ barPosition: BarPosition.Start, controller: this.leftSideBarTabs }) {
ForEach(this.leftSideBarTabsName, (item: LeftSideTabName, index: number) => {
TabContent() {
Text(item.str)
.fontSize(30)
}
})
}.barHeight(0)
.width('70%')
}.borderWidth('1')
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB