[bugfix_2] Main Page: Message Log Input Box Ratio: Fix init apply ratio. (when I did it at the first time, 5ddc77a9cc, it looks not fixed yet.)

This commit is contained in:
Sakamoto Shiina
2024-12-09 09:25:05 +09:00
parent a2bcbed780
commit b4eacc7175

View File

@@ -23,9 +23,10 @@ export const MessageContainer = () => {
const asyncSetMessageBoxHeightInRem = async (data) => { const asyncSetMessageBoxHeightInRem = async (data) => {
const minimized = await appWindow.isMinimized(); const minimized = await appWindow.isMinimized();
if (minimized === true) return; // don't save while the window is minimized. if (minimized) return; // don't save while the window is minimized.
setMessageBoxHeightInRem(data); setMessageBoxHeightInRem(data);
}; };
const calculateMessageBoxRatioAndHeight = () => { const calculateMessageBoxRatioAndHeight = () => {
if (!currentIsAppliedInitMessageBoxHeight.data) { if (!currentIsAppliedInitMessageBoxHeight.data) {
asyncSetMessageInputBoxRatio(currentMessageInputBoxRatio.data); asyncSetMessageInputBoxRatio(currentMessageInputBoxRatio.data);
@@ -33,7 +34,7 @@ export const MessageContainer = () => {
return; return;
} }
if (log_box_ref.current && message_box_wrapper_ref.current) { if (log_box_ref.current && message_box_wrapper_ref.current && container_ref.current) {
const container_height = container_ref.current.offsetHeight; const container_height = container_ref.current.offsetHeight;
const container_padding_bottom = parseFloat(window.getComputedStyle(container_ref.current).paddingBottom); const container_padding_bottom = parseFloat(window.getComputedStyle(container_ref.current).paddingBottom);
const total_height = container_height - container_padding_bottom; const total_height = container_height - container_padding_bottom;
@@ -43,6 +44,8 @@ export const MessageContainer = () => {
asyncSetMessageInputBoxRatio(message_box_ratio); asyncSetMessageInputBoxRatio(message_box_ratio);
asyncSetMessageBoxHeightInRem(convertRatioToRem(message_box_ratio)); asyncSetMessageBoxHeightInRem(convertRatioToRem(message_box_ratio));
} else {
console.warn("References not ready for calculation");
} }
}; };
@@ -53,24 +56,26 @@ export const MessageContainer = () => {
}); });
useEffect(() => { useEffect(() => {
// Note: I thought the part "1.4" is message box bottom padding + (message box separator height/2)
// but it should be fixed at 1.4. Idk why, tho.
asyncSetMessageBoxHeightInRem((position / FONT_SIZE_STANDARD) - 1.4); asyncSetMessageBoxHeightInRem((position / FONT_SIZE_STANDARD) - 1.4);
}, [position]); }, [position]);
useEffect(() => { useEffect(() => {
asyncSetMessageBoxHeightInRem(convertRatioToRem(currentMessageInputBoxRatio.data)); asyncSetMessageBoxHeightInRem(convertRatioToRem(currentMessageInputBoxRatio.data));
}, [currentMessageInputBoxRatio.data]); }, [currentMessageInputBoxRatio.data]);
const convertRatioToRem = (ratio) => { const convertRatioToRem = (ratio) => {
if (!container_ref.current) return 0;
const container_height = container_ref.current.offsetHeight; const container_height = container_ref.current.offsetHeight;
const container_padding_bottom = parseFloat(window.getComputedStyle(container_ref.current).paddingBottom); const container_padding_bottom = parseFloat(window.getComputedStyle(container_ref.current).paddingBottom);
const total_height = container_height - container_padding_bottom; const total_height = container_height - container_padding_bottom;
if (total_height === 0) return 0; return total_height === 0 ? 0 : ((ratio / 100) * total_height / FONT_SIZE_STANDARD);
return ((ratio / 100) * total_height / FONT_SIZE_STANDARD);
}; };
useEffect(() => {
calculateMessageBoxRatioAndHeight();
updateIsAppliedInitMessageBoxHeight(true); // Ensure this happens after initial calculation
}, []);
useEffect(() => { useEffect(() => {
let resizeTimeout; let resizeTimeout;
@@ -86,10 +91,6 @@ export const MessageContainer = () => {
}; };
}, []); }, []);
useEffect(() => {
updateIsAppliedInitMessageBoxHeight(true);
}, []);
return ( return (
<div className={styles.container} ref={container_ref}> <div className={styles.container} ref={container_ref}>
<div className={styles.log_box_resize_wrapper} <div className={styles.log_box_resize_wrapper}
@@ -98,7 +99,7 @@ export const MessageContainer = () => {
onMouseLeave={() => setIsHovered(false)} onMouseLeave={() => setIsHovered(false)}
> >
<LogBox /> <LogBox />
<MessageLogSettingsContainer to_visible_toggle_bar={is_hovered}/> <MessageLogSettingsContainer to_visible_toggle_bar={is_hovered} />
</div> </div>
<Separator {...separatorProps} onDragStart={calculateMessageBoxRatioAndHeight} /> <Separator {...separatorProps} onDragStart={calculateMessageBoxRatioAndHeight} />
<div <div
@@ -112,10 +113,8 @@ export const MessageContainer = () => {
); );
}; };
const Separator = ({ onDragStart, ...props }) => { const Separator = ({ onDragStart, ...props }) => (
return (
<div tabIndex={0} className={styles.separator} {...props} onDragStart={onDragStart}> <div tabIndex={0} className={styles.separator} {...props} onDragStart={onDragStart}>
<span className={styles.separator_line}></span> <span className={styles.separator_line}></span>
</div> </div>
); );
};