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

ENH: CharacterButtonのメニューが常に下方向に展開されるようにする #1291

Merged
merged 4 commits into from
Apr 27, 2023
Merged
Changes from 3 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
22 changes: 20 additions & 2 deletions src/components/CharacterButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<q-btn
flat
class="q-pa-none character-button"
ref="buttonRef"
:disable="uiLocked"
:class="{ opaque: loading }"
>
Expand All @@ -23,6 +24,8 @@
class="character-menu"
transition-show="none"
transition-hide="none"
:max-height="maxMenuHeight"
@before-show="updateMenuHeight"
>
<q-list style="min-width: max-content" class="character-item-container">
<q-item
Expand Down Expand Up @@ -179,8 +182,8 @@
</template>

<script setup lang="ts">
import { debounce } from "quasar";
import { computed, ref } from "vue";
import { debounce, QBtn } from "quasar";
import { computed, Ref, ref } from "vue";
import { base64ImageToUri } from "@/helpers/imageHelper";
import { useStore } from "@/store";
import { CharacterInfo, SpeakerId, Voice } from "@/type/preload";
Expand Down Expand Up @@ -291,6 +294,21 @@ const reassignSubMenuOpen = debounce((idx: number) => {
arr[idx] = true;
subMenuOpenFlags.value = arr;
}, 100);

// 高さを制限してメニューが下方向に展開されるようにする
const buttonRef: Ref<InstanceType<typeof QBtn> | undefined> = ref();
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
const heightLimit = "65vh"; // QMenuのデフォルト値
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

とりあえず元々の動作は変えないようにしました。
参照する方法がなさそうなのでハードコートしました。

const maxMenuHeight = ref(heightLimit);
const updateMenuHeight = () => {
if (buttonRef.value == undefined)
throw new Error("buttonRef.value == undefined");
const el = buttonRef.value.$el;
if (!(el instanceof Element)) throw new Error("!(el instanceof Element)");
const buttonRect = el.getBoundingClientRect();
// QMenuは展開する方向のスペースが不足している場合、自動的に展開方向を変更してしまうためmax-heightで制限する。
// AudioDetailよりボタンが下に来ることはないのでその最低高185pxに余裕を持たせた170pxを最小の高さにする。
maxMenuHeight.value = `max(170px, min(${heightLimit}, calc(96vh - ${buttonRect.bottom}px)))`;
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
};
</script>

<style scoped lang="scss">
Expand Down