From 3ed3511af8ac3d5d31bf49d616d091c934073703 Mon Sep 17 00:00:00 2001 From: JannisX11 Date: Sat, 8 May 2021 16:52:49 +0200 Subject: [PATCH] Tab bar: add tab sorting --- css/window.css | 21 +++++++++- index.html | 17 +++++++- js/interface/interface.js | 8 +--- js/io/project.js | 83 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 119 insertions(+), 10 deletions(-) diff --git a/css/window.css b/css/window.css index 2ec4db80..a6fd8d53 100644 --- a/css/window.css +++ b/css/window.css @@ -274,7 +274,6 @@ display: grid; grid-template-rows: auto minmax(200px, 5000px) 26px 36px; grid-template-areas: - "tab_bar" "toolbar" "center" "status_bar" @@ -414,6 +413,11 @@ display: inline-flex; margin-left: 2px; border-top: 2px solid transparent; + left: 0; + --tabwidth: 202px; + } + #tab_bar.drag_mode .project_tab { + transition: left 100ms ease; } #tab_bar .project_tab.selected { background-color: var(--color-ui); @@ -424,11 +428,26 @@ background-color: var(--color-button); color: var(--color-light); } + #tab_bar .project_tab.dragging { + background-color: var(--color-button); + color: var(--color-light); + position: relative; + z-index: 5; + box-shadow: 0 0 10px #00000080; + transition: none; + } + #tab_bar .project_tab.move_back { + left: calc(var(--tabwidth) * -1); + } + #tab_bar .project_tab.move_forth { + left: var(--tabwidth); + } #tab_bar .project_tab > label { overflow: hidden; width: calc(100% - 20px); flex: 1 1 auto; padding: 0 4px; + pointer-events: none; } #tab_bar .project_tab > * { cursor: inherit diff --git a/index.html b/index.html index ace05cd8..7a6fb6cf 100644 --- a/index.html +++ b/index.html @@ -584,8 +584,21 @@ -
-
+
+
{{ project.saved ? 'clear' : 'fiber_manual_record' }} diff --git a/js/interface/interface.js b/js/interface/interface.js index acfdb6b3..86418633 100644 --- a/js/interface/interface.js +++ b/js/interface/interface.js @@ -100,7 +100,7 @@ const Interface = { }, position: function(line) { line.setPosition({ - top: 26, + top: document.getElementById('page_wrapper').offsetTop, bottom: 0, left: Interface.data.left_bar_width+2 }) @@ -123,7 +123,7 @@ const Interface = { }, position: function(line) { line.setPosition({ - top: 56, + top: document.getElementById('page_wrapper').offsetTop+30, bottom: 0, right: Interface.data.right_bar_width-2 }) @@ -747,10 +747,6 @@ onVueSetup(function() { > live_tv
-
- check - close -
diff --git a/js/io/project.js b/js/io/project.js index bde12e42..898a7ebd 100644 --- a/js/io/project.js +++ b/js/io/project.js @@ -277,6 +277,8 @@ onVueSetup(() => { el: '#tab_bar', data: { projects: ModelProject.all, + drag_target_index: null, + drag_position_index: null, new_tab: { name: 'New Tab', saved: true, @@ -302,7 +304,6 @@ onVueSetup(() => { if (this.new_tab.visible) { tabs.push(this.new_tab); } - console.log(tabs) return tabs; } }, @@ -310,6 +311,86 @@ onVueSetup(() => { openNewTab() { this.new_tab.visible = true; this.new_tab.select(); + }, + dragTab(tab, e1) { + convertTouchEvent(e1); + + let scope = this; + let active = false; + let timeout; + let last_event = e1; + + let tab_node = e1.target; + if (!tab_node.classList.contains('project_tab') || ModelProject.all.indexOf(tab) < 0) return; + + let activate = () => { + this.drag_target_index = ModelProject.all.indexOf(tab); + this.drag_position_index = 0; + if (open_menu) open_menu.hide(); + active = true; + } + + function move(e2) { + convertTouchEvent(e2); + let offset = e2.clientX - e1.clientX; + if (!active) { + let distance = Math.abs(offset); + if (Blockbench.isTouch) { + if (distance > 14 && timeout) { + clearTimeout(timeout); + timeout = null; + } else { + document.getElementById('tab_bar').scrollLeft += last_event.clientX - e2.clientX; + } + } else if (distance > 5) { + activate(); + } + } else { + if (e2) e2.preventDefault(); + + tab_node.style.left = `${offset}px`; + + let index_offset = Math.trunc((e2.clientX - e1.clientX) / tab_node.clientWidth); + scope.drag_position_index = scope.drag_target_index + index_offset; + console.log('drag_target_index', scope.drag_target_index, 'drag_position_index', scope.drag_position_index) + } + last_event = e2; + } + function off(e2) { + let {drag_target_index} = scope; + + removeEventListeners(document, 'mousemove touchmove', move); + removeEventListeners(document, 'mouseup touchend', off); + tab_node.style.left = null; + scope.drag_target_index = null; + scope.drag_position_index = null; + + if (Blockbench.isTouch) clearTimeout(timeout); + + if (active && !open_menu) { + convertTouchEvent(e2); + let index_offset = Math.trunc((e2.clientX - e1.clientX) / tab_node.clientWidth); + if (index_offset) { + ModelProject.all.splice(drag_target_index, 1); + ModelProject.all.splice(drag_target_index + index_offset, 0, tab); + } + } + } + + if (Blockbench.isTouch) { + timeout = setTimeout(() => { + active = true; + move(e1); + }, 320) + } + + addEventListeners(document, 'mousemove touchmove', move, {passive: false}); + addEventListeners(document, 'mouseup touchend', off, {passive: false}); + }, + mouseUp(tab, e1) { + if (e1.button === 1) { + tab.close() + } } } })