Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rustdoc] Fix display of features #118677

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1081,15 +1081,9 @@ so that we can apply CSS-filters to change the arrow color in themes */
}

.item-info .stab {
/* This min-height is needed to unify the height of the stab elements because some of them
have emojis.
*/
min-height: 36px;
display: flex;
display: block;
padding: 3px;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see why it looks different. Try this.

Suggested change
padding: 3px;
padding: 0 3px;
line-height: 36px;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still looks bad when there is more than one line:

image

Copy link
Contributor

@notriddle notriddle Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that is more line spacing than I'd like. Here's one more attempt to get a decent rendering (where ones with both emoji and non-emoji have the same height, but there's not excessive line spacing).

.item-info .stab {
  display:block;
  padding:3px;
  margin-bottom:5px;
}
.item-name .stab {
  margin-left:0.3125em;
}
.stab {
  padding:0 2px;
  font-size:0.875rem;
  font-weight:normal;
  color:var(--main-color);
  background-color:var(--stab-background-color);
  width:fit-content;
  white-space:pre-wrap;
  border-radius:3px;
  display:inline;
  vertical-align:baseline;
}
.stab.portability>code {
  background:none;
  color:var(--stab-code-color);
}
.stab .emoji, .item-info .stab::before {
  font-size:1.25rem;
}
.stab .emoji {
  margin-right:0.3rem;
}
.item-info .stab::before {
  /* ensure badges with emoji and without it have same height */
  content: "\0";
  width: 0;
  display: inline-block;
  color: transparent;
}
.emoji {
  text-shadow:1px 0 0 black,-1px 0 0 black,0 1px 0 black,0 -1px 0 black;
}

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow. That's quite impressive, congrats! I updated as suggested. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the big screenshot at the top, too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

margin-bottom: 5px;
align-items: center;
vertical-align: text-bottom;
}
.item-name .stab {
margin-left: 0.3125em;
Expand All @@ -1112,17 +1106,26 @@ so that we can apply CSS-filters to change the arrow color in themes */
color: var(--stab-code-color);
}

.stab .emoji {
.stab .emoji, .item-info .stab::before {
font-size: 1.25rem;
}
.stab .emoji {
margin-right: 0.3rem;
}
.item-info .stab::before {
/* ensure badges with emoji and without it have same height */
content: "\0";
width: 0;
display: inline-block;
color: transparent;
}

/* Black one-pixel outline around emoji shapes */
.emoji {
text-shadow:
1px 0 0 black,
-1px 0 0 black,
0 1px 0 black,
0 1px 0 black,
0 -1px 0 black;
}

Expand Down
15 changes: 15 additions & 0 deletions tests/rustdoc-gui/item-info.goml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,22 @@ assert-size: (".item-info", {"width": 840})
assert-size: (".item-info .stab", {"width": 289})
assert-position: (".item-info .stab", {"x": 245})

// We check that the display of the feature elements is not broken. It serves as regression
// test for <https://github.com/rust-lang/rust/issues/118615>.
set-window-size: (850, 800)
store-position: (
"//*[@class='stab portability']//code[text()='Win32_System']",
{"x": first_line_x, "y": first_line_y},
)
store-position: (
"//*[@class='stab portability']//code[text()='Win32_System_Diagnostics']",
{"x": second_line_x, "y": second_line_y},
)
assert: |first_line_x| != |second_line_x| && |first_line_x| == 516 && |second_line_x| == 272
assert: |first_line_y| != |second_line_y| && |first_line_y| == 688 && |second_line_y| == 711

// Now we ensure that they're not rendered on the same line.
set-window-size: (1100, 800)
go-to: "file://" + |DOC_PATH| + "/lib2/trait.Trait.html"
// We first ensure that there are two item info on the trait.
assert-count: ("#main-content > .item-info .stab", 2)
Expand Down
7 changes: 7 additions & 0 deletions tests/rustdoc-gui/src/lib2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ edition = "2018"
[lib]
path = "lib.rs"

[features]
Win32 = ["Win32_System"]
Win32_System = ["Win32_System_Diagnostics"]
Win32_System_Diagnostics = ["Win32_System_Diagnostics_Debug"]
Win32_System_Diagnostics_Debug = []
default = ["Win32"]

[dependencies]
implementors = { path = "./implementors" }
http = { path = "./http" }
9 changes: 9 additions & 0 deletions tests/rustdoc-gui/src/lib2/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// ignore-tidy-linelength

#![feature(doc_cfg)]
#![feature(doc_auto_cfg)]

pub mod another_folder;
pub mod another_mod;
Expand Down Expand Up @@ -28,6 +29,14 @@ impl Foo {
/// Some documentation
/// # A Heading
pub fn a_method(&self) {}

#[cfg(all(
feature = "Win32",
feature = "Win32_System",
feature = "Win32_System_Diagnostics",
feature = "Win32_System_Diagnostics_Debug"
))]
pub fn lot_of_features() {}
}

#[doc(cfg(feature = "foo-method"))]
Expand Down
Loading