Skip to content

Commit 74ce3ff

Browse files
authored
Have blocking messages and dialogs vertically centered.
2 parents 22c63e6 + b36f11e commit 74ce3ff

4 files changed

Lines changed: 80 additions & 4 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"url": "git+https://github.com/opencor/webapp.git"
2424
},
2525
"type": "module",
26-
"version": "0.20260220.1",
26+
"version": "0.20260223.0",
2727
"scripts": {
2828
"archive:web": "bun src/renderer/scripts/archive.web.js",
2929
"build": "electron-vite build",

src/renderer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
},
4040
"./style.css": "./dist/opencor.css"
4141
},
42-
"version": "0.20260220.1",
42+
"version": "0.20260223.0",
4343
"scripts": {
4444
"build": "vite build && bun scripts/generate.version.js",
4545
"build:lib": "vite build --config vite.lib.config.ts && cp index.d.ts dist/index.d.ts",

src/renderer/src/common/vueCommon.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,35 @@ export const useTheme = vueusecore.createGlobalState(() => {
6767
useDarkMode
6868
};
6969
});
70+
71+
// A composable to track the height of an element as a CSS variable.
72+
73+
export const trackElementHeight = (
74+
sourceElement: HTMLElement,
75+
targetElement: HTMLElement,
76+
cssVariableName: string
77+
): (() => void) => {
78+
const updateHeight = () => {
79+
const height = sourceElement.offsetHeight;
80+
81+
targetElement.style.setProperty(cssVariableName, `${height}px`);
82+
};
83+
84+
// Set the initial height.
85+
86+
updateHeight();
87+
88+
// Watch for height changes, including border and padding changes.
89+
90+
const { stop: stopTrackingElementHeight } = vueusecore.useResizeObserver(
91+
sourceElement,
92+
() => {
93+
updateHeight();
94+
},
95+
{ box: 'border-box' }
96+
);
97+
98+
// Return the function to stop tracking the element's height.
99+
100+
return stopTrackingElementHeight;
101+
};

src/renderer/src/components/OpenCOR.vue

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<BlockUI ref="blockUi" class="opencor overflow-hidden h-full"
2+
<BlockUI ref="blockUi" class="opencor overflow-hidden h-full" :class="showMainMenu ? 'with-main-menu' : ''"
33
:blocked="compBlockUiEnabled"
44
@click="activateInstance"
55
@focus="activateInstance"
@@ -21,7 +21,7 @@
2121
>
2222
<input ref="files" type="file" multiple style="display: none;" @change="onChange" />
2323
<DragNDropComponent v-show="dragAndDropCounter" />
24-
<MainMenu :id="mainMenuId" v-if="!electronApi && !omex"
24+
<MainMenu ref="mainMenu" :id="mainMenuId" v-if="showMainMenu"
2525
:isActive="compIsActive"
2626
:uiEnabled="compUiEnabled"
2727
:hasFiles="hasFiles"
@@ -139,6 +139,7 @@ const { isDialogActive } = provideDialogState();
139139
140140
const blockUi = vue.ref<vue.ComponentPublicInstance | null>(null);
141141
const toastId = vue.ref('opencorToast');
142+
const mainMenu = vue.ref<vue.ComponentPublicInstance | null>(null);
142143
const mainMenuId = vue.ref('opencorMainMenu');
143144
const files = vue.ref<HTMLElement | null>(null);
144145
const contents = vue.ref<InstanceType<typeof IContentsComponent> | null>(null);
@@ -181,6 +182,12 @@ const compUiEnabled = vue.computed(() => {
181182
return !compBlockUiEnabled.value && !isDialogActive.value;
182183
});
183184
185+
// Determine whether to show the main menu or not.
186+
187+
const showMainMenu = vue.computed(() => {
188+
return !electronApi && !props.omex;
189+
});
190+
184191
// Provide access to our progress message features.
185192
186193
export interface IProgressMessage {
@@ -933,6 +940,33 @@ vue.onMounted(() => {
933940
}, SHORT_DELAY);
934941
});
935942
943+
// Track the height of our main menu.
944+
945+
let stopTrackingMainMenuHeight: (() => void) | null = null;
946+
947+
vue.onMounted(() => {
948+
if (!showMainMenu.value) {
949+
return;
950+
}
951+
952+
void vue.nextTick(() => {
953+
const mainMenuElement = mainMenu.value?.$el as HTMLElement | undefined;
954+
const blockUiElement = blockUi.value?.$el as HTMLElement | undefined;
955+
956+
if (mainMenuElement && blockUiElement) {
957+
stopTrackingMainMenuHeight = vueCommon.trackElementHeight(mainMenuElement, blockUiElement, '--main-menu-height');
958+
}
959+
});
960+
});
961+
962+
vue.onBeforeUnmount(() => {
963+
if (stopTrackingMainMenuHeight) {
964+
stopTrackingMainMenuHeight();
965+
966+
stopTrackingMainMenuHeight = null;
967+
}
968+
});
969+
936970
// If a COMBINE archive is provided then open it (and then the Simulation Experiment view will be shown in isolation) or
937971
// carry on as normal (i.e. the whole OpenCOR UI will be shown).
938972
@@ -1258,4 +1292,14 @@ const onGitHubButtonClick = async (): Promise<void> => {
12581292
color: var(--p-red-200);
12591293
}
12601294
}
1295+
1296+
.with-main-menu {
1297+
:deep(.p-dialog-mask) {
1298+
padding-top: var(--main-menu-height) !important;
1299+
}
1300+
1301+
:deep(.p-message) {
1302+
margin-top: calc(0.5 * var(--main-menu-height)) !important;
1303+
}
1304+
}
12611305
</style>

0 commit comments

Comments
 (0)