Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjust font size for menus #36

Merged
merged 2 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/livecodes/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2593,6 +2593,8 @@ const handleAppMenuProject = () => {
if (!menuProjectContainer || !menuProjectButton) return;
menuProjectContainer.innerHTML = menuProjectHTML; // settingsMenuHTML;
translateElement(menuProjectContainer);
adjustFontSize(menuProjectContainer);

// This fixes the behaviour where :
// clicking outside the settings menu but inside settings menu container,
// hides the settings menu but not the container
Expand All @@ -2615,6 +2617,8 @@ const handleAppMenuSettings = () => {
menuSettingsContainer.innerHTML = menuSettingsHTML; // settingsMenuHTML;

translateElement(menuSettingsContainer);
adjustFontSize(menuSettingsContainer);

// This fixes the behaviour where :
// clicking outside the settings menu but inside settings menu container,
// hides the settings menu but not the container
Expand All @@ -2636,6 +2640,8 @@ const handleAppMenuHelp = () => {
if (!menuHelpContainer || !menuHelpButton) return;
menuHelpContainer.innerHTML = menuHelpHTML;
translateElement(menuHelpContainer);
adjustFontSize(menuHelpContainer);

// This fixes the behaviour where :
// clicking outside the settings menu but inside settings menu container,
// hides the settings menu but not the container
Expand All @@ -2651,6 +2657,36 @@ const handleAppMenuHelp = () => {
});
};

/**
* decrease font size in menus when text is too wide (for different languages)
*/
const adjustFontSize = (container: HTMLElement) => {
const adjustFont = (el: HTMLElement) =>
new Promise<void>((resolve) => {
const fontSize = Number(getComputedStyle(el).getPropertyValue('font-size').replace('px', ''));
const maxWidth =
Number(getComputedStyle(el).getPropertyValue('--label-max-width').replace('px', '')) || 188;
if (el.clientWidth <= maxWidth || fontSize <= 0) return resolve();
el.style.fontSize = fontSize - 1 + 'px';
requestAnimationFrame(async () => {
await adjustFont(el);
resolve();
});
});

setTimeout(async () => {
container.style.display = 'block';
container.style.visibility = 'hidden';
(container.children[0] as HTMLElement).style.display = 'block';
for (const el of container.querySelectorAll<HTMLElement>('span')) {
await adjustFont(el);
}
container.style.display = '';
container.style.visibility = '';
(container.children[0] as HTMLElement).style.display = '';
}, 1000);
};

const handleSettings = () => {
const toggles = UI.getSettingToggles();
toggles.forEach((toggle) => {
Expand Down
4 changes: 4 additions & 0 deletions src/livecodes/i18n/locales/en/translation.lokalise.json
Original file line number Diff line number Diff line change
Expand Up @@ -1736,6 +1736,10 @@
"notes": "",
"translation": "Add stylesheet/script URLs. Each URL should be in a separate line."
},
"resultMode.linkText": {
"notes": "",
"translation": "Edit on LiveCodes"
},
"savePrompt.heading": {
"notes": "",
"translation": "Unsaved changes"
Expand Down
3 changes: 3 additions & 0 deletions src/livecodes/i18n/locales/en/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,9 @@ const translation = {
stylesheets: 'External Stylesheets',
urlDesc: 'Add stylesheet/script URLs. Each URL should be in a separate line.',
},
resultMode: {
linkText: 'Edit on LiveCodes',
},
savePrompt: {
heading: 'Unsaved changes',
prompt: {
Expand Down
17 changes: 6 additions & 11 deletions src/livecodes/styles/inc-menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,17 @@
margin-top: 0;
top: 0;
width: 255px; // for font-size 14px
--label-max-width: 188px; // used in js to reduce label font size

&:hover {
animation: fadeIn 0.4s forwards;
display: block !important;
}

span {
display: inline-block;
text-wrap: nowrap;
}
}

#app-menu-i18n {
Expand Down Expand Up @@ -376,17 +382,6 @@ i.arrow {
}
}

label:has(span[data-i18n='menu.formatOnsave'], span[data-i18n='menu.recoverUnsaved']) {
container: i18nlabel / inline-size; // Parent to set font-size based on size of container
white-space: nowrap;
}

@container i18nlabel (width < 236px) {
span {
font-size: 5.25cqi; // font-size based on size of container
}
}

.switch {
cursor: pointer;
display: inherit;
Expand Down
Loading