Add cursor tooltip API

This commit is contained in:
JannisX11 2023-11-05 14:22:59 +01:00
parent a5753c2c39
commit 1f0ed593e3
4 changed files with 41 additions and 3 deletions

View File

@ -216,7 +216,6 @@
cursor: default; cursor: default;
pointer-events: none; pointer-events: none;
} }
@media (max-device-width: 640px) { @media (max-device-width: 640px) {
#quick_message_box { #quick_message_box {
bottom: 26px; bottom: 26px;
@ -224,6 +223,24 @@
padding: 6px; padding: 6px;
} }
} }
#cursor_tooltip {
position: absolute;
z-index: 101;
max-width: 250px;
width: fit-content;
line-height: 18px;
padding: 2px 8px;
margin-top: 10px;
margin-left: 9px;
background-color: var(--color-bright_ui);
color: var(--color-bright_ui_text);
box-shadow: 0 0 2px rgba(0, 0, 0, 0.5);;
overflow-wrap: break-word;
white-space: pre-line;
cursor: default;
pointer-events: none;
border-radius: 6px;
}
.uv_message_box { .uv_message_box {
position: absolute; position: absolute;
margin-left: auto; margin-left: auto;

View File

@ -167,6 +167,22 @@ const Blockbench = {
} }
return new deletableToast(notification); return new deletableToast(notification);
}, },
setCursorTooltip(text) {
if (!Interface.cursor_tooltip) {
Interface.cursor_tooltip = Interface.createElement('div', {id: 'cursor_tooltip'});
}
if (text) {
Interface.cursor_tooltip.textContent = text;
if (!Interface.cursor_tooltip.parentNode) {
document.body.append(Interface.cursor_tooltip);
Interface.cursor_tooltip.style.left = mouse_pos.x + 'px';
Interface.cursor_tooltip.style.top = mouse_pos.y + 'px';
}
} else {
Interface.cursor_tooltip.textContent = '';
Interface.cursor_tooltip.remove();
}
},
showStatusMessage(message, time) { showStatusMessage(message, time) {
Blockbench.setStatusBarText(tl(message)) Blockbench.setStatusBarText(tl(message))
setTimeout(function() { setTimeout(function() {

View File

@ -547,6 +547,11 @@ function setupInterface() {
document.addEventListener('mousemove', event => { document.addEventListener('mousemove', event => {
mouse_pos.x = event.clientX; mouse_pos.x = event.clientX;
mouse_pos.y = event.clientY; mouse_pos.y = event.clientY;
if (Interface.cursor_tooltip?.textContent) {
Interface.cursor_tooltip.style.left = mouse_pos.x + 'px';
Interface.cursor_tooltip.style.top = mouse_pos.y + 'px';
}
}) })
updateInterface() updateInterface()
} }

View File

@ -1002,7 +1002,7 @@
Undo.cancelEdit(); Undo.cancelEdit();
} }
function displayDistance(number) { function displayDistance(number) {
Blockbench.setStatusBarText(trimFloatNumber(number)); Blockbench.setCursorTooltip(trimFloatNumber(number));
} }
function extendTransformLineOnAxis(long, axis) { function extendTransformLineOnAxis(long, axis) {
let axisNumber = getAxisNumber(axis); let axisNumber = getAxisNumber(axis);
@ -1593,7 +1593,7 @@
extendTransformLine(false); extendTransformLine(false);
Blockbench.setStatusBarText(); Blockbench.setCursorTooltip();
if (Modes.id === 'edit' || Modes.id === 'pose' || Toolbox.selected.id == 'pivot_tool') { if (Modes.id === 'edit' || Modes.id === 'pose' || Toolbox.selected.id == 'pivot_tool') {
if (Toolbox.selected.id === 'resize_tool') { if (Toolbox.selected.id === 'resize_tool') {