[bugfix] Main Page: Message Log Input Box Ratio: Fix init apply ratio. imperfectly, tho.
This commit is contained in:
@@ -7,12 +7,15 @@ import { MessageLogSettingsContainer } from "./message_log_settings_container/Me
|
|||||||
import { MessageInputBox } from "./message_input_box/MessageInputBox";
|
import { MessageInputBox } from "./message_input_box/MessageInputBox";
|
||||||
import { useMessageInputBoxRatio } from "@logics_main";
|
import { useMessageInputBoxRatio } from "@logics_main";
|
||||||
import { useUiScaling } from "@logics_configs";
|
import { useUiScaling } from "@logics_configs";
|
||||||
|
import { useStore_IsAppliedInitMessageBoxHeight } from "@store";
|
||||||
|
|
||||||
export const MessageContainer = () => {
|
export const MessageContainer = () => {
|
||||||
const { currentMessageInputBoxRatio, asyncSetMessageInputBoxRatio } = useMessageInputBoxRatio();
|
const { currentMessageInputBoxRatio, asyncSetMessageInputBoxRatio } = useMessageInputBoxRatio();
|
||||||
const { currentUiScaling } = useUiScaling();
|
const { currentUiScaling } = useUiScaling();
|
||||||
const [is_hovered, setIsHovered] = useState(false);
|
const [is_hovered, setIsHovered] = useState(false);
|
||||||
const [message_box_height_in_rem, setMessageBoxHeightInRem] = useState(10);
|
const [message_box_height_in_rem, setMessageBoxHeightInRem] = useState(10);
|
||||||
const FONT_SIZE_STANDARD = 10 * currentUiScaling.data / 100; // 10px = 1rem
|
const FONT_SIZE_STANDARD = 10 * currentUiScaling.data / 100; // 10px = 1rem
|
||||||
|
const { currentIsAppliedInitMessageBoxHeight, updateIsAppliedInitMessageBoxHeight } = useStore_IsAppliedInitMessageBoxHeight();
|
||||||
|
|
||||||
const container_ref = useRef(null);
|
const container_ref = useRef(null);
|
||||||
const log_box_ref = useRef(null);
|
const log_box_ref = useRef(null);
|
||||||
@@ -23,8 +26,13 @@ export const MessageContainer = () => {
|
|||||||
if (minimized === true) return; // don't save while the window is minimized.
|
if (minimized === true) return; // don't save while the window is minimized.
|
||||||
setMessageBoxHeightInRem(data);
|
setMessageBoxHeightInRem(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
const calculateMessageBoxRatioAndHeight = () => {
|
const calculateMessageBoxRatioAndHeight = () => {
|
||||||
|
if (!currentIsAppliedInitMessageBoxHeight.data) {
|
||||||
|
asyncSetMessageInputBoxRatio(currentMessageInputBoxRatio.data);
|
||||||
|
asyncSetMessageBoxHeightInRem(convertRatioToRem(currentMessageInputBoxRatio.data));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (log_box_ref.current && message_box_wrapper_ref.current) {
|
if (log_box_ref.current && message_box_wrapper_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);
|
||||||
@@ -34,9 +42,7 @@ export const MessageContainer = () => {
|
|||||||
const message_box_ratio = (message_box_height / total_height) * 100;
|
const message_box_ratio = (message_box_height / total_height) * 100;
|
||||||
|
|
||||||
asyncSetMessageInputBoxRatio(message_box_ratio);
|
asyncSetMessageInputBoxRatio(message_box_ratio);
|
||||||
|
asyncSetMessageBoxHeightInRem(convertRatioToRem(message_box_ratio));
|
||||||
const height_in_rem = convertRatioToRem(message_box_ratio);
|
|
||||||
asyncSetMessageBoxHeightInRem(height_in_rem);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -65,23 +71,24 @@ export const MessageContainer = () => {
|
|||||||
return ((ratio / 100) * total_height / FONT_SIZE_STANDARD);
|
return ((ratio / 100) * total_height / FONT_SIZE_STANDARD);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let resizeTimeout;
|
||||||
|
|
||||||
// Tauriのwindow resizeイベントをリッスン
|
const unlisten = appWindow.onResized(() => {
|
||||||
useEffect(() => {
|
clearTimeout(resizeTimeout);
|
||||||
let resizeTimeout;
|
resizeTimeout = setTimeout(() => {
|
||||||
|
calculateMessageBoxRatioAndHeight();
|
||||||
|
}, 200);
|
||||||
|
});
|
||||||
|
|
||||||
// イベントのリスナーを設定
|
return () => {
|
||||||
const unlisten = appWindow.onResized(() => {
|
unlisten.then((dispose) => dispose());
|
||||||
clearTimeout(resizeTimeout);
|
};
|
||||||
resizeTimeout = setTimeout(() => {
|
}, []);
|
||||||
calculateMessageBoxRatioAndHeight(); // リサイズが終了した後に実行
|
|
||||||
}, 200); // ドラッグが終了したと見なすまでの遅延(200ms程度)
|
|
||||||
});
|
|
||||||
|
|
||||||
return () => {
|
useEffect(() => {
|
||||||
unlisten.then((dispose) => dispose()); // イベントリスナーを解除
|
updateIsAppliedInitMessageBoxHeight(true);
|
||||||
};
|
}, []);
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.container} ref={container_ref}>
|
<div className={styles.container} ref={container_ref}>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export const store = {
|
|||||||
backend_subprocess: null,
|
backend_subprocess: null,
|
||||||
config_page: null,
|
config_page: null,
|
||||||
log_box_ref: null,
|
log_box_ref: null,
|
||||||
|
is_applied_init_message_box_height: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
const generatePropertyNames = (base_name) => ({
|
const generatePropertyNames = (base_name) => ({
|
||||||
@@ -122,6 +123,7 @@ export const { atomInstance: Atom_ForegroundStatus, useHook: useStore_Foreground
|
|||||||
export const { atomInstance: Atom_MessageLogs, useHook: useStore_MessageLogs } = createAtomWithHook(generateTestData(20), "MessageLogs");
|
export const { atomInstance: Atom_MessageLogs, useHook: useStore_MessageLogs } = createAtomWithHook(generateTestData(20), "MessageLogs");
|
||||||
export const { atomInstance: Atom_MessageInputValue, useHook: useStore_MessageInputValue } = createAtomWithHook("", "MessageInputValue");
|
export const { atomInstance: Atom_MessageInputValue, useHook: useStore_MessageInputValue } = createAtomWithHook("", "MessageInputValue");
|
||||||
export const { atomInstance: Atom_IsVisibleResendButton, useHook: useStore_IsVisibleResendButton } = createAtomWithHook(false, "IsVisibleResendButton");
|
export const { atomInstance: Atom_IsVisibleResendButton, useHook: useStore_IsVisibleResendButton } = createAtomWithHook(false, "IsVisibleResendButton");
|
||||||
|
export const { atomInstance: Atom_IsAppliedInitMessageBoxHeight, useHook: useStore_IsAppliedInitMessageBoxHeight } = createAtomWithHook(false, "IsAppliedInitMessageBoxHeight");
|
||||||
|
|
||||||
export const { atomInstance: Atom_SelectableLanguageList, useHook: useStore_SelectableLanguageList } = createAtomWithHook([], "SelectableLanguageList");
|
export const { atomInstance: Atom_SelectableLanguageList, useHook: useStore_SelectableLanguageList } = createAtomWithHook([], "SelectableLanguageList");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user