From 07e3f998b1ceb4b8d2a7992782e60f5e776aa114 Mon Sep 17 00:00:00 2001 From: cynecx Date: Sun, 10 Oct 2021 19:08:08 +0200 Subject: [PATCH] rustdoc: merge source sidebar into main sidebar --- src/librustdoc/html/static/css/rustdoc.css | 63 +++++++++---------- .../html/static/css/themes/dark.css | 2 +- .../html/static/js/source-script.js | 14 +++-- src/librustdoc/html/templates/page.html | 13 +--- 4 files changed, 41 insertions(+), 51 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 9cd05a7d6f1c5..a99507a215dd3 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -311,7 +311,6 @@ li { } .source .content { - margin-top: 50px; max-width: none; overflow: visible; margin-left: 0px; @@ -335,7 +334,15 @@ nav.sub { } .source .sidebar { - display: none; + width: unset; + min-width: 0px; + max-width: 300px; + flex-grow: 0; + flex-shrink: 0; + flex-basis: auto; + border-right: 1px solid; + transition: width .5s; + overflow-x: hidden; } /* Improve the scrollbar display on firefox */ @@ -367,18 +374,6 @@ nav.sub { display: none !important; } -.logo-source { - display: none; -} - -.source .logo-source { - display: block; - position: absolute; - top: 0; - left: 0; - width: 200px; -} - .logo-container { height: 100px; width: 100px; @@ -742,7 +737,7 @@ nav:not(.sidebar) { margin-bottom: 25px; } .source nav:not(.sidebar).sub { - margin-left: 230px; + margin-left: 32px; } nav.main { padding: 20px 0; @@ -1367,15 +1362,9 @@ pre.rust { border-left: 0; } #source-sidebar { - position: fixed; - top: 0; - bottom: 0; - left: 0; width: 300px; z-index: 1; overflow: auto; - transition: left .5s; - border-right: 1px solid; } #source-sidebar > .title { font-size: 1.5em; @@ -1696,7 +1685,7 @@ details.rustdoc-toggle[open] > summary.hideme::after { flex-direction: column; } - .rustdoc > .sidebar { + .rustdoc:not(.source) > .sidebar { width: 100%; height: 45px; min-height: 40px; @@ -1707,6 +1696,14 @@ details.rustdoc-toggle[open] > summary.hideme::after { z-index: 11; } + .rustdoc.source > .sidebar { + position: fixed; + top: 0; + left: 0; + margin: 0; + z-index: 11; + } + .sidebar > .location { float: right; margin: 0px; @@ -1722,13 +1719,19 @@ details.rustdoc-toggle[open] > summary.hideme::after { padding: 0; } - .sidebar .logo-container { + .rustdoc.source .sidebar .logo-container { + width: 100%; + height: 45px; + margin: 0 auto; + } + + .rustdoc:not(.source) .sidebar .logo-container { width: 35px; - height: 35px; - margin-top: 5px; - margin-bottom: 5px; - float: left; - margin-left: 50px; + height: 35px; + margin-top: 5px; + margin-bottom: 5px; + float: left; + margin-left: 50px; } .sidebar .logo-container > img { @@ -1944,10 +1947,6 @@ details.rustdoc-toggle[open] > summary.hideme::after { .search-results div.desc, .search-results .result-description, .item-right { padding-left: 2em; } - - .source .logo-source { - display: none; - } } @media print { diff --git a/src/librustdoc/html/static/css/themes/dark.css b/src/librustdoc/html/static/css/themes/dark.css index 8caf8a05d507f..3e5ec748397c2 100644 --- a/src/librustdoc/html/static/css/themes/dark.css +++ b/src/librustdoc/html/static/css/themes/dark.css @@ -66,7 +66,7 @@ pre, .rustdoc.source .example-wrap { } .source .sidebar { - background-color: #353535; + background-color: #565656; } .sidebar .location { diff --git a/src/librustdoc/html/static/js/source-script.js b/src/librustdoc/html/static/js/source-script.js index 4d9a59f836b9e..ca0a1f2105122 100644 --- a/src/librustdoc/html/static/js/source-script.js +++ b/src/librustdoc/html/static/js/source-script.js @@ -77,15 +77,15 @@ function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) { } function toggleSidebar() { - var sidebar = document.getElementById("source-sidebar"); + var sidebar = document.querySelector("nav.sidebar"); var child = this.children[0].children[0]; if (child.innerText === ">") { - sidebar.style.left = ""; + sidebar.style.width = "300px"; this.style.left = ""; child.innerText = "<"; updateLocalStorage("rustdoc-source-sidebar-show", "true"); } else { - sidebar.style.left = "-300px"; + sidebar.style.width = "0"; this.style.left = "0"; child.innerText = ">"; updateLocalStorage("rustdoc-source-sidebar-show", "false"); @@ -120,7 +120,7 @@ function createSourceSidebar() { if (!window.rootPath.endsWith("/")) { window.rootPath += "/"; } - var main = document.getElementById("main"); + var main = document.querySelector("nav.sidebar"); var sidebarToggle = createSidebarToggle(); main.insertBefore(sidebarToggle, main.firstChild); @@ -128,7 +128,9 @@ function createSourceSidebar() { var sidebar = document.createElement("div"); sidebar.id = "source-sidebar"; if (getCurrentValue("rustdoc-source-sidebar-show") !== "true") { - sidebar.style.left = "-300px"; + main.style.width = "0px"; + } else { + main.style.width = "300px"; } var currentFile = getCurrentFilePath(); @@ -144,7 +146,7 @@ function createSourceSidebar() { currentFile, hasFoundFile); }); - main.insertBefore(sidebar, main.firstChild); + main.insertBefore(sidebar, document.querySelector(".sidebar-logo").nextSibling); // Focus on the current file in the source files sidebar. var selected_elem = sidebar.getElementsByClassName("selected")[0]; if (typeof selected_elem !== "undefined") { diff --git a/src/librustdoc/html/templates/page.html b/src/librustdoc/html/templates/page.html index 815dd03d34667..14bf35b6a2e4a 100644 --- a/src/librustdoc/html/templates/page.html +++ b/src/librustdoc/html/templates/page.html @@ -68,7 +68,7 @@ {{- layout.external_html.before_content | safe -}}