diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2017-11-15 20:04:02 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2017-11-17 22:50:15 +0100 |
| commit | aca1bd7d7ed90febe83508d2e0b93b6d99da26fb (patch) | |
| tree | ec96e835a1508d1506e4124c9728f21e39692b8c | |
| parent | be68d34a7eac8d653f453d7174f30e8ac1f73e62 (diff) | |
| download | rust-aca1bd7d7ed90febe83508d2e0b93b6d99da26fb.tar.gz rust-aca1bd7d7ed90febe83508d2e0b93b6d99da26fb.zip | |
First step for important traits UI
| -rw-r--r-- | src/librustdoc/html/render.rs | 27 | ||||
| -rw-r--r-- | src/librustdoc/html/static/main.js | 17 | ||||
| -rw-r--r-- | src/librustdoc/html/static/rustdoc.css | 31 |
3 files changed, 61 insertions, 14 deletions
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index d43a73c9864..eed0db032fe 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1816,8 +1816,7 @@ fn plain_summary_line(s: Option<&str>) -> String { fn document(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Result { document_stability(w, cx, item)?; - let mut prefix = render_assoc_const_value(item); - prefix.push_str(&render_spotlight_traits(item)?); + let prefix = render_assoc_const_value(item); document_full(w, item, cx, &prefix)?; Ok(()) } @@ -2267,10 +2266,15 @@ fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, AbiSpace(f.abi), it.name.as_ref().unwrap(), f.generics).len(); + let mut extra = render_spotlight_traits(it)?; + if !extra.is_empty() { + extra.insert_str(0, "<div class=\"important-traits\">ⓘ<div class=\"content hidden\">"); + extra.push_str("</div></div>"); + }; write!(w, "<pre class='rust fn'>")?; render_attributes(w, it)?; write!(w, "{vis}{constness}{unsafety}{abi}fn \ - {name}{generics}{decl}{where_clause}</pre>", + {name}{generics}{decl}{where_clause}</pre>{extra}", vis = VisSpace(&it.visibility), constness = ConstnessSpace(f.constness), unsafety = UnsafetySpace(f.unsafety), @@ -2282,7 +2286,8 @@ fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, decl: &f.decl, name_len, indent: 0, - })?; + }, + extra = extra)?; document(w, cx, it) } @@ -3266,7 +3271,7 @@ fn spotlight_decl(decl: &clean::FnDecl) -> Result<String, fmt::Error> { if out.is_empty() { out.push_str("<span class=\"docblock autohide\">"); out.push_str(&format!("<h3>Important traits for {}</h3>", impl_.for_)); - out.push_str("<code class=\"spotlight\">"); + out.push_str("<code class=\"content\">"); } //use the "where" class here to make it small @@ -3287,7 +3292,8 @@ fn spotlight_decl(decl: &clean::FnDecl) -> Result<String, fmt::Error> { } if !out.is_empty() { - out.push_str("</code></span>"); + out.insert_str(0, "<div class=\"important-traits\">ⓘ<div class=\"content hidden\">"); + out.push_str("</code></span></div></div>"); } Ok(out) @@ -3327,7 +3333,6 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi trait_: Option<&clean::Trait>, show_def_docs: bool) -> fmt::Result { let item_type = item.type_(); let name = item.name.as_ref().unwrap(); - let mut method_prefix: Option<String> = None; let render_method_item: bool = match render_mode { RenderMode::Normal => true, @@ -3342,6 +3347,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi let id = derive_id(format!("{}.{}", item_type, name)); let ns_id = derive_id(format!("{}.{}", name, item_type.name_space())); write!(w, "<h4 id='{}' class=\"{}\">", id, item_type)?; + write!(w, "{}", spotlight_decl(decl)?)?; write!(w, "<span id='{}' class='invisible'>", ns_id)?; write!(w, "<code>")?; render_assoc_item(w, item, link.anchor(&id), ItemType::Impl)?; @@ -3356,7 +3362,6 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi render_stability_since_raw(w, item.stable_since(), outer_version)?; } write!(w, "</span></h4>\n")?; - method_prefix = Some(spotlight_decl(decl)?); } } clean::TypedefItem(ref tydef, _) => { @@ -3388,11 +3393,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi } if render_method_item || render_mode == RenderMode::Normal { - let mut prefix = render_assoc_const_value(item); - - if let Some(method_prefix) = method_prefix { - prefix.push_str(&method_prefix); - } + let prefix = render_assoc_const_value(item); if !is_default_item { if let Some(t) = trait_ { diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 49dfa891c0a..72512bda41e 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1624,7 +1624,9 @@ } onEach(document.getElementById('main').getElementsByClassName('docblock'), function(e) { - e.parentNode.insertBefore(createToggle(), e); + if (e.parentNode.id === "main") { + e.parentNode.insertBefore(createToggle(), e); + } }); onEach(document.getElementsByClassName('docblock'), function(e) { @@ -1711,6 +1713,19 @@ } }); + function showModal(content) { + var modal = document.createElement('div'); + addClass(modal, 'modal'); + modal.innerHTML = '<div class="modal-content">' + content + "</div>"; + document.getElementsByTagName('body')[0].appendChild(modal); + } + + onEach(document.getElementsByClassName('important-traits'), function(e) { + e.onclick = function() { + showModal(e.firstElementChild.innerHTML); + }; + }); + var search_input = document.getElementsByClassName("search-input")[0]; if (search_input) { diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 29bec231b84..63792714d47 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -954,3 +954,34 @@ pre.rust { color: #888; font-size: 16px; } + +h4 > .important-traits { + position: absolute; + left: -44px; + top: 2px; + cursor: pointer; +} + +.modal { + position: fixed; + width: 100vw; + height: 100vh; + background-color: rgba(0,0,0,0.3); + z-index: 10000; + top: 0; + left: 0; +} + +.modal-content { + display: block; + max-width: 60%; + min-width: 200px; + background-color: white; + padding: 5px; + top: 10%; + position: absolute; + left: 50%; + transform: translate(-50%, -50%); + border: 1px solid #999; + border-radius: 4px; +} \ No newline at end of file |
