-
Notifications
You must be signed in to change notification settings - Fork 50
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
how to set guidePos offset #59
Comments
<template>
<div id="designer-ruler-horizontal"></div>
<div id="designer-ruler-vertical"></div>
<n-icon
size="18"
:depth="2"
style="padding: 3px;cursor: pointer"
@click="show">
<eye v-if="showLines"/>
<eye-off v-else/>
</n-icon>
</template>
<script setup lang="ts">
import Guides from "@scena/guides";
import { useEditorStore } from "@/store/editorStore";
import { Eye, EyeOff } from "@vicons/ionicons5";
let hGuides;
let vGuides;
const editorStore = useEditorStore();
const showLines = ref(true);
const lintOffset = computed(() => {
return Math.round(20 / editorStore.boardConfig.scale);
});
watch(() => editorStore.boardConfig.scale, calcZoom);
onMounted(() => {
hGuides = new Guides(document.getElementById("designer-ruler-horizontal"), {
type: "horizontal",
longLineSize: 7,
shortLineSize: 4,
textOffset: [0, 8],
displayDragPos: true,
displayGuidePos: true,
rulerStyle: { left: "40px", width: "calc(100% - 40px)", height: "100%" },
dragPosFormat: (value) => {
return value - lintOffset.value;
},
guidePosFormat: (value) => {
return value - lintOffset.value;
},
guidePosStyle: {
height: "15px",
backgroundColor: "#18a058",
color: "white",
fontWeight: "500",
padding: "0px 3px",
left: 0,
top: "1px",
transform: "translate(0)",
lineHeight: "15px",
},
});
vGuides = new Guides(document.getElementById("designer-ruler-vertical"), {
type: "vertical",
longLineSize: 7,
shortLineSize: 4,
textOffset: [8, 0],
displayDragPos: true,
displayGuidePos: true,
rulerStyle: { top: "40px", height: "calc(100% - 40px)", width: "100%" },
dragPosFormat: (value) => {
return value - lintOffset.value;
},
guidePosFormat: (value) => {
return value - lintOffset.value;
},
guidePosStyle: {
left: "1px",
top: "30px",
height: "15px",
backgroundColor: "#18a058",
color: "white",
fontWeight: "500",
padding: "0px 3px",
lineHeight: "15px"
},
});
calcZoom(editorStore.boardConfig.scale);
});
function calcZoom(scale) {
let unit;
if (scale > 0.7) {
unit = 50;
} else if (scale > 0.5) {
unit = 100;
} else if (scale > 0.3) {
unit = 200;
} else if (scale > 0.1) {
unit = 400;
} else {
unit = 1000;
}
hGuides.setState({
zoom: scale,
unit,
});
vGuides.setState({
zoom: scale,
unit,
});
}
function resize() {
hGuides?.resize();
vGuides?.resize();
}
function show() {
showLines.value = !showLines.value;
hGuides.setState({ showGuides: showLines.value });
vGuides.setState({ showGuides: showLines.value });
}
defineExpose({ resize });
</script>
<style lang="scss">
#designer-ruler-horizontal {
height: 20px;
width: 100%;
position: absolute;
background-color: #333;
}
#designer-ruler-vertical {
height: 100%;
width: 20px;
position: absolute;
background-color: #333;
}
</style> Its all code,I use guidePosFormat: (value) => {
return value - Math.round(20 / editorStore.boardConfig.scale);
}, its work ,but I think its too complex, Is there a simple way? |
I will add that feature in the next release. |
guides' new version is released. guidesOffset prop is added. Thank you :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Environments
Description
when I set zoom the guild pos not correct,how I set the pos offset?
The text was updated successfully, but these errors were encountered: