diff --git a/publish/changeLog.md b/publish/changeLog.md index 1af08ab1..db0fe97e 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -2,6 +2,10 @@ - 新增 是否将歌词显示在状态栏 设置,默认关闭,该功能只在 MacOS 下可用(#1940) +### 优化 + +- 优化侧栏图标显示,修复图标可能被裁切的问题(#1960) + ### 修复 - 修复 MacOS 下点击 dock 右键菜单的退出按钮时,程序没有退出的问题(#1923) diff --git a/src/renderer/components/layout/Aside/NavBar.vue b/src/renderer/components/layout/Aside/NavBar.vue index 5dfe9165..734ecedc 100644 --- a/src/renderer/components/layout/Aside/NavBar.vue +++ b/src/renderer/components/layout/Aside/NavBar.vue @@ -1,82 +1,94 @@ - @@ -141,7 +153,7 @@ export default { transition-property: background-color, opacity; color: var(--color-nav-font); cursor: pointer; - font-size: 11.5px; + // font-size: 11.5px; text-align: center; outline: none; display: flex; @@ -190,11 +202,11 @@ export default { } } -.icon { - // margin-bottom: 5px; - &> svg { - width: 32%; - } -} +// .icon { +// // margin-bottom: 5px; +// &> svg { +// width: 32%; +// } +// } diff --git a/src/renderer/utils/compositions/useIconSize.ts b/src/renderer/utils/compositions/useIconSize.ts new file mode 100644 index 00000000..be086602 --- /dev/null +++ b/src/renderer/utils/compositions/useIconSize.ts @@ -0,0 +1,37 @@ +import { type Ref, onBeforeUnmount, onMounted, ref } from '@common/utils/vueTools' + +const onDomSizeChanged = (dom: HTMLElement, onChanged: (width: number, height: number) => void) => { + // 使用 ResizeObserver 监听大小变化 + const resizeObserver = new ResizeObserver(entries => { + for (let entry of entries) { + const { width, height } = entry.contentRect + // console.log(dom.offsetLeft, dom.offsetTop, left, top, width, height) + onChanged(Math.trunc(width), Math.trunc(height)) + } + }) + + resizeObserver.observe(dom) + + onChanged(dom.clientWidth, dom.clientHeight) + + return () => { + resizeObserver.disconnect() + } +} + +export const useIconSize = (parentDom: Ref, size: number) => { + const iconSize = ref('32px') + let unsub: (() => void) | null = null + + onMounted(() => { + if (!parentDom.value) return + unsub = onDomSizeChanged(parentDom.value, (width, height) => { + iconSize.value = Math.trunc(width * size) + 'px' + }) + }) + onBeforeUnmount(() => { + unsub?.() + }) + + return iconSize +}