mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-22 14:01:42 +03:00
fix(Aspect Ratio Calculator): better UI and ratio preset handling
Fix #51
This commit is contained in:
1 parent
9cea7922da
commit
512bf387cd
1 file changed
+21
-3
@@ -17,9 +17,19 @@ const result = ref<string | null>(null);
|
|||||||
function calculateResult() {
|
function calculateResult() {
|
||||||
if (mode.value === 'ratio' && width.value && height.value) {
|
if (mode.value === 'ratio' && width.value && height.value) {
|
||||||
const ratio = calculateAspectRatio(width.value, height.value);
|
const ratio = calculateAspectRatio(width.value, height.value);
|
||||||
r1.value = ratio.r1;
|
if (r2.value) {
|
||||||
r2.value = ratio.r2;
|
r1.value = ratio.r1 / ratio.r2;
|
||||||
result.value = `Aspect Ratio: ${ratio.r1}:${ratio.r2}`;
|
} else if (r1.value) {
|
||||||
|
r2.value = ratio.r2 / ratio.r1;
|
||||||
|
} else {
|
||||||
|
r1.value = ratio.r1;
|
||||||
|
r2.value = ratio.r2;
|
||||||
|
}
|
||||||
|
if (ratio.r1 !== r1.value) {
|
||||||
|
result.value = `Aspect Ratio: ${r1.value}:${r2.value} or ${ratio.r1}:${ratio.r2}`;
|
||||||
|
} else {
|
||||||
|
result.value = `Aspect Ratio: ${ratio.r1}:${ratio.r2}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (mode.value === 'dimensions' && r1.value && r2.value) {
|
else if (mode.value === 'dimensions' && r1.value && r2.value) {
|
||||||
if (width.value) {
|
if (width.value) {
|
||||||
@@ -48,6 +58,11 @@ function clearAll() {
|
|||||||
r2.value = null;
|
r2.value = null;
|
||||||
result.value = null;
|
result.value = null;
|
||||||
}
|
}
|
||||||
|
function clearRatio() {
|
||||||
|
r1.value = null;
|
||||||
|
r2.value = null;
|
||||||
|
result.value = null;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -90,6 +105,9 @@ function clearAll() {
|
|||||||
<NButton type="primary" @click="calculateResult">
|
<NButton type="primary" @click="calculateResult">
|
||||||
Calculate
|
Calculate
|
||||||
</NButton>
|
</NButton>
|
||||||
|
<NButton @click="clearRatio" v-if="mode === 'ratio'">
|
||||||
|
Clear Ratio
|
||||||
|
</NButton>
|
||||||
<NButton @click="clearAll">
|
<NButton @click="clearAll">
|
||||||
Clear All
|
Clear All
|
||||||
</NButton>
|
</NButton>
|
||||||
|
|||||||
Reference in new issue
Block a user