Improved animation quality for users and settings sidebars.

This commit is contained in:
flash 2024-01-22 22:35:10 +00:00
parent f539c46954
commit a72e605097
3 changed files with 76 additions and 41 deletions

View file

@ -3,10 +3,6 @@ select {
accent-color: currentcolor; accent-color: currentcolor;
} }
.setting__category {
transition: max-height .2s;
}
.setting__category-title { .setting__category-title {
font-size: 2em; font-size: 2em;
line-height: 1.1em; line-height: 1.1em;

View file

@ -1,3 +1,4 @@
#include animate.js
#include common.js #include common.js
#include emotes.js #include emotes.js
#include utility.js #include utility.js
@ -462,31 +463,55 @@ Umi.UI.Settings = (function() {
const createCategory = function(category) { const createCategory = function(category) {
const catHeader = <div class={['setting__category-title', `setting__category-title--${category.name}`]} style={{ cursor: 'pointer' }}>{category.title}</div>; const catHeader = <div class={['setting__category-title', `setting__category-title--${category.name}`]} style={{ cursor: 'pointer' }}>{category.title}</div>;
const catBody = <div class={['setting__category', `setting__category--${category.name}`]} style={{ overflow: 'hidden' }}/>; const catBody = <div class={['setting__category', `setting__category--${category.name}`]} style={{ overflow: 'hidden' }}/>;
const catContainer = <div>{catHeader}{catBody}</div>;
catHeader.onclick = () => { catHeader.onclick = () => {
if(catBody.dataset.mamiClosed) { if(catContainer.dataset.mamiAnimRun === 'yes')
delete catBody.dataset.mamiClosed; return;
catBody.style.maxHeight = null; catContainer.dataset.mamiAnimRun = 'yes';
const meow = catBody.clientHeight;
catBody.style.maxHeight = '0';
setTimeout(function() {
catBody.style.maxHeight = meow.toString() + 'px';
}, 50);
} else {
catBody.dataset.mamiClosed = 1;
if(!catBody.style.maxHeight) {
catBody.style.maxHeight = catBody.clientHeight.toString() + 'px';
setTimeout(function() {
catBody.style.maxHeight = '0';
}, 50);
} else catBody.style.maxHeight = '0';
}
};
if(category.collapse) { let start, update, end, height;
catBody.dataset.mamiClosed = 1;
catBody.style.maxHeight = '0'; if(catContainer.dataset.mamiIsClosed === 'yes') {
} catContainer.dataset.mamiIsClosed = 'no';
start = () => {
const curHeight = catBody.style.height;
catBody.style.height = null;
height = catBody.clientHeight;
catBody.style.height = curHeight;
};
update = t => {
catBody.style.height = `${height * t}px`;
};
end = () => {
catBody.style.height = null;
catContainer.dataset.mamiAnimRun = 'no';
};
} else {
catContainer.dataset.mamiIsClosed = 'yes';
start = () => {
height = catBody.clientHeight;
};
update = t => {
catBody.style.height = `${height - (height * t)}px`;
};
end = () => {
catBody.style.height = '0';
catContainer.dataset.mamiAnimRun = 'no';
};
}
// todo: actually make cancellable
MamiAnimate({
duration: 500,
easing: 'easeOutExpo',
start: start,
update: update,
end: end,
});
};
if(category.warning) if(category.warning)
catBody.appendChild(<div style={{ fontSize: '.9em', lineHeight: '1.4em', margin: '5px', padding: '5px', backgroundColor: 'darkred', border: '2px solid red', borderRadius: '5px' }}>{category.warning}</div>); catBody.appendChild(<div style={{ fontSize: '.9em', lineHeight: '1.4em', margin: '5px', padding: '5px', backgroundColor: 'darkred', border: '2px solid red', borderRadius: '5px' }}>{category.warning}</div>);
@ -495,10 +520,7 @@ Umi.UI.Settings = (function() {
for(const item of category.items) for(const item of category.items)
catBody.appendChild(createSetting(item)); catBody.appendChild(createSetting(item));
return <div> return catContainer;
{catHeader}
{catBody}
</div>;
}; };
return { return {
@ -506,8 +528,15 @@ Umi.UI.Settings = (function() {
const html = Umi.UI.Menus.Get('settings'); const html = Umi.UI.Menus.Get('settings');
$rc(html); $rc(html);
for(const category of items) for(const category of items) {
html.appendChild(createCategory(category)); const elem = createCategory(category);
html.appendChild(elem);
// only a little bit of hacking, stan
if(category.collapse)
elem.firstChild.click();
}
html.appendChild(createCopyright()); html.appendChild(createCopyright());
}, },

View file

@ -13,9 +13,7 @@ Umi.UI.Users = (function() {
userOptions = $i(prefix + '-options-wrapper'), userOptions = $i(prefix + '-options-wrapper'),
closedClass = 'sidebar__user-options--hidden', closedClass = 'sidebar__user-options--hidden',
isClosed = userOptions.classList.contains(closedClass); isClosed = userOptions.classList.contains(closedClass);
let update = null, let start, update, end, height;
start = null,
end = null;
if(prefix in toggleTimeouts) { if(prefix in toggleTimeouts) {
clearTimeout(toggleTimeouts[prefix]); clearTimeout(toggleTimeouts[prefix]);
@ -29,21 +27,33 @@ Umi.UI.Users = (function() {
toggleUser(id); toggleUser(id);
}, 300000); }, 300000);
start = function() { start = () => {
userOptions.classList.remove(closedClass); userOptions.classList.remove(closedClass);
const curHeight = userOptions.style.height;
userOptions.style.height = null;
height = userOptions.clientHeight;
userOptions.style.height = curHeight;
}; };
update = function(t) { update = function(t) {
userOptions.style.maxHeight = (230 * t).toString() + 'px'; userOptions.style.height = `${height * t}px`;
};
end = () => {
userOptions.style.height = null;
}; };
} else { } else {
end = function() { start = () => {
userOptions.classList.add(closedClass); height = userOptions.clientHeight;
}; };
update = function(t) { update = t => {
userOptions.style.maxHeight = (230 - (230 * t)).toString() + 'px'; userOptions.style.height = `${height - (height * t)}px`;
};
end = () => {
userOptions.style.height = '0';
userOptions.classList.add(closedClass);
}; };
} }
// todo: actually make cancellable
MamiAnimate({ MamiAnimate({
duration: 500, duration: 500,
easing: 'easeOutExpo', easing: 'easeOutExpo',