Skip to content

Commit 135281e

Browse files
cynecxGuillaumeGomez
authored andcommitted
rustdoc: use flexbox to layout sidebar and main content
1 parent 9981e56 commit 135281e

File tree

3 files changed

+80
-81
lines changed

3 files changed

+80
-81
lines changed

Diff for: src/librustdoc/html/static/css/rustdoc.css

+43-48
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ body {
111111
font: 16px/1.4 "Source Serif 4", NanumBarunGothic, serif;
112112
margin: 0;
113113
position: relative;
114-
padding: 10px 15px 20px 15px;
115114

116115
-webkit-font-feature-settings: "kern", "liga";
117116
-moz-font-feature-settings: "kern", "liga";
@@ -248,6 +247,25 @@ textarea {
248247

249248
/* end tweaks for normalize.css 8 */
250249

250+
.rustdoc {
251+
display: flex;
252+
flex-direction: row;
253+
flex-wrap: nowrap;
254+
}
255+
256+
main {
257+
position: relative;
258+
flex-grow: 1;
259+
padding: 10px 15px 40px 45px;
260+
height: 100vh;
261+
overflow-y: auto;
262+
}
263+
264+
.main-inner {
265+
max-width: 960px;
266+
margin-right: auto;
267+
}
268+
251269
details:not(.rustdoc-toggle) summary {
252270
margin-bottom: .6em;
253271
}
@@ -298,15 +316,13 @@ nav.sub {
298316

299317
.sidebar {
300318
width: 200px;
301-
position: fixed;
302-
left: 0;
303-
top: 0;
304-
bottom: 0;
305319
overflow-y: scroll;
306320
}
307321

308322
.rustdoc.source .sidebar {
309323
overflow-y: auto;
324+
min-width: 200px;
325+
height: 100vh;
310326
}
311327

312328
/* Improve the scrollbar display on firefox */
@@ -332,10 +348,6 @@ nav.sub {
332348
margin-right: -10px;
333349
}
334350

335-
.content, nav {
336-
max-width: 960px;
337-
}
338-
339351
/* Everything else */
340352

341353
.hidden {
@@ -439,10 +451,6 @@ nav.sub {
439451
display: none;
440452
}
441453

442-
.content {
443-
padding: 15px 0;
444-
}
445-
446454
.source .content pre.rust {
447455
white-space: pre;
448456
overflow: auto;
@@ -487,7 +495,6 @@ nav.sub {
487495
}
488496

489497
#search {
490-
margin-left: 230px;
491498
position: relative;
492499
}
493500

@@ -707,7 +714,7 @@ nav.sub {
707714
nav:not(.sidebar) {
708715
border-bottom: 1px solid;
709716
padding-bottom: 10px;
710-
margin-bottom: 10px;
717+
margin-bottom: 25px;
711718
}
712719
nav.main {
713720
padding: 20px 0;
@@ -726,10 +733,6 @@ nav.main .separator {
726733
nav.sum { text-align: right; }
727734
nav.sub form { display: inline; }
728735

729-
nav.sub, .content {
730-
margin-left: 230px;
731-
}
732-
733736
a {
734737
text-decoration: none;
735738
background: transparent;
@@ -1354,7 +1357,7 @@ pre.rust {
13541357

13551358
.theme-picker {
13561359
position: absolute;
1357-
left: 211px;
1360+
left: 11px;
13581361
top: 19px;
13591362
}
13601363

@@ -1653,11 +1656,23 @@ details.rustdoc-toggle[open] > summary.hideme::after {
16531656
padding-top: 0px;
16541657
}
16551658

1659+
main {
1660+
height: auto;
1661+
padding-left: 15px;
1662+
padding-top: 0px;
1663+
overflow-y: visible;
1664+
}
1665+
1666+
.rustdoc {
1667+
flex-direction: column;
1668+
}
1669+
16561670
.rustdoc > .sidebar {
1671+
width: 100%;
16571672
height: 45px;
16581673
min-height: 40px;
1674+
max-height: 45px;
16591675
margin: 0;
1660-
margin-left: -15px;
16611676
padding: 0 15px;
16621677
position: static;
16631678
z-index: 11;
@@ -1748,20 +1763,17 @@ details.rustdoc-toggle[open] > summary.hideme::after {
17481763

17491764
nav.sub {
17501765
width: calc(100% - 32px);
1751-
float: right;
1766+
margin-left: 32px;
1767+
margin-bottom: 10px;
17521768
}
17531769

17541770
.content {
17551771
margin-left: 0px;
17561772
}
17571773

1758-
#main, #search {
1759-
margin-top: 45px;
1760-
padding: 0;
1761-
}
1762-
17631774
#search {
17641775
margin-left: 0;
1776+
padding: 0;
17651777
}
17661778

17671779
.anchor {
@@ -1770,7 +1782,7 @@ details.rustdoc-toggle[open] > summary.hideme::after {
17701782

17711783
.theme-picker {
17721784
left: 10px;
1773-
top: 54px;
1785+
top: 9px;
17741786
z-index: 1;
17751787
}
17761788

@@ -1790,22 +1802,12 @@ details.rustdoc-toggle[open] > summary.hideme::after {
17901802
}
17911803

17921804
.sidebar.mobile {
1793-
position: fixed;
1805+
position: sticky;
1806+
top: 0;
1807+
left: 0;
17941808
width: 100%;
17951809
margin-left: 0;
17961810
background-color: rgba(0,0,0,0);
1797-
height: 100%;
1798-
}
1799-
/*
1800-
This allows to prevent the version text to overflow the sidebar title on mobile mode when the
1801-
sidebar is displayed (after clicking on the "hamburger" button).
1802-
*/
1803-
.sidebar.mobile > div.version {
1804-
overflow: hidden;
1805-
max-height: 33px;
1806-
}
1807-
.sidebar {
1808-
width: calc(100% + 30px);
18091811
}
18101812

18111813
.show-it, .sidebar-elems:focus-within {
@@ -1920,13 +1922,6 @@ details.rustdoc-toggle[open] > summary.hideme::after {
19201922
height: 73px;
19211923
}
19221924

1923-
/* This is to prevent the search bar from being underneath the <section>
1924-
* element following it.
1925-
*/
1926-
#main, #search {
1927-
margin-top: 100px;
1928-
}
1929-
19301925
#main > table:not(.table-display) td {
19311926
word-break: break-word;
19321927
width: 50%;

Diff for: src/librustdoc/html/static/js/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ function hideThemeButtonState() {
10011001
container.appendChild(rustdoc_version);
10021002

10031003
popup.appendChild(container);
1004-
insertAfter(popup, searchState.outputElement());
1004+
insertAfter(popup, document.querySelector("main"));
10051005
// So that it's only built once and then it'll do nothing when called!
10061006
buildHelperPopup = function() {};
10071007
};

Diff for: src/librustdoc/html/templates/page.html

+36-32
Original file line numberDiff line numberDiff line change
@@ -81,39 +81,43 @@
8181
</a> {#- -#}
8282
{{- sidebar | safe -}}
8383
</nav> {#- -#}
84-
<div class="theme-picker"> {#- -#}
85-
<button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu" title="themes"> {#- -#}
86-
<img width="18" height="18" alt="Pick another theme!" {# -#}
87-
src="{{static_root_path | safe}}brush{{page.resource_suffix}}.svg"> {#- -#}
88-
</button> {#- -#}
89-
<div id="theme-choices" role="menu"></div> {#- -#}
90-
</div> {#- -#}
91-
<nav class="sub"> {#- -#}
92-
<form class="search-form"> {#- -#}
93-
<div class="search-container"> {#- -#}
94-
<div>{%- if layout.generate_search_filter -%}
95-
<select id="crate-search"> {#- -#}
96-
<option value="All crates">All crates</option> {#- -#}
97-
</select> {#- -#}
98-
{%- endif -%}
99-
<input {# -#}
100-
class="search-input" {# -#}
101-
name="search" {# -#}
102-
autocomplete="off" {# -#}
103-
spellcheck="false" {# -#}
104-
placeholder="Click or press ‘S’ to search, ‘?’ for more options…" {# -#}
105-
type="search"> {#- -#}
106-
</div> {#- -#}
107-
<button type="button" id="help-button" title="help">?</button> {#- -#}
108-
<a id="settings-menu" href="{{page.root_path | safe}}settings.html" title="settings"> {#- -#}
109-
<img width="18" height="18" alt="Change settings" {# -#}
110-
src="{{static_root_path | safe}}wheel{{page.resource_suffix}}.svg"> {#- -#}
111-
</a> {#- -#}
84+
<main> {#- -#}
85+
<div class="main-inner"> {#- -#}
86+
<div class="theme-picker"> {#- -#}
87+
<button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu" title="themes"> {#- -#}
88+
<img width="18" height="18" alt="Pick another theme!" {# -#}
89+
src="{{static_root_path | safe}}brush{{page.resource_suffix}}.svg"> {#- -#}
90+
</button> {#- -#}
91+
<div id="theme-choices" role="menu"></div> {#- -#}
11292
</div> {#- -#}
113-
</form> {#- -#}
114-
</nav> {#- -#}
115-
<section id="main" class="content">{{- content | safe -}}</section> {#- -#}
116-
<section id="search" class="content hidden"></section> {#- -#}
93+
<nav class="sub"> {#- -#}
94+
<form class="search-form"> {#- -#}
95+
<div class="search-container"> {#- -#}
96+
<div>{%- if layout.generate_search_filter -%}
97+
<select id="crate-search"> {#- -#}
98+
<option value="All crates">All crates</option> {#- -#}
99+
</select> {#- -#}
100+
{%- endif -%}
101+
<input {# -#}
102+
class="search-input" {# -#}
103+
name="search" {# -#}
104+
autocomplete="off" {# -#}
105+
spellcheck="false" {# -#}
106+
placeholder="Click or press ‘S’ to search, ‘?’ for more options…" {# -#}
107+
type="search"> {#- -#}
108+
</div> {#- -#}
109+
<button type="button" id="help-button" title="help">?</button> {#- -#}
110+
<a id="settings-menu" href="{{page.root_path | safe}}settings.html" title="settings"> {#- -#}
111+
<img width="18" height="18" alt="Change settings" {# -#}
112+
src="{{static_root_path | safe}}wheel{{page.resource_suffix}}.svg"> {#- -#}
113+
</a> {#- -#}
114+
</div> {#- -#}
115+
</form> {#- -#}
116+
</nav> {#- -#}
117+
<section id="main" class="content">{{- content | safe -}}</section> {#- -#}
118+
<section id="search" class="content hidden"></section> {#- -#}
119+
</div> {#- -#}
120+
</main> {#- -#}
117121
{{- layout.external_html.after_content | safe -}}
118122
<div id="rustdoc-vars" {# -#}
119123
data-root-path="{{page.root_path | safe}}" {# -#}

0 commit comments

Comments
 (0)