Skip to content

Fix item info pos and height #99779

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

Merged
merged 2 commits into from
Aug 2, 2022
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
10 changes: 9 additions & 1 deletion src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,14 @@ table,
}

.item-info .stab {
display: inline-block;
width: fit-content;
/* This min-height is needed to unify the height of the stab elements because some of them
have emojis.
*/
Copy link
Contributor

@camsteffen camsteffen Jul 26, 2022

Choose a reason for hiding this comment

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

Idea to avoid min-height:

.stab::before {
  content: '\200b'; /* zero-width space */
  font-size: 1.25rem; /* emoji font size */
}

Maybe the content could be the actual emoji when applicable, determined by a CSS class?

Copy link
Member Author

Choose a reason for hiding this comment

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

The min-height is mostly for items which don't have an emoji actually. Unless I misunderstood what you meant?

Copy link
Contributor

Choose a reason for hiding this comment

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

Right. The zero-with space makes the element taller as if there were an emoji.

Copy link
Member Author

Choose a reason for hiding this comment

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

Exactly.

Copy link
Contributor

Choose a reason for hiding this comment

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

So you wouldn't need an arbitrary min-height.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I still don't get your point.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I guess this is all moot. I thought that the actual height of the emoji is not a predictable px value. I've had experiences with some fonts not having a predictable height.

min-height: 36px;
display: flex;
align-items: center;
white-space: pre-wrap;
}
.stab {
padding: 3px;
Expand All @@ -1121,6 +1128,7 @@ table,
}
.stab p {
display: inline;
margin: 0;
}

.stab .emoji {
Expand Down
8 changes: 0 additions & 8 deletions src/test/rustdoc-gui/item-info-width.goml

This file was deleted.

32 changes: 32 additions & 0 deletions src/test/rustdoc-gui/item-info.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// This test ensures a few things for item info elements.
goto: file://|DOC_PATH|/lib2/struct.Foo.html
// Ensuring that the item information don't take 100% of the width if unnecessary.
// We set a fixed size so there is no chance of "random" resize.
size: (1100, 800)
// We check that ".item-info" is bigger than its content.
assert-css: (".item-info", {"width": "790px"})
assert-css: (".item-info .stab", {"width": "289px"})
assert-position: (".item-info .stab", {"x": 295})

// Now we ensure that they're not rendered on the same line.
goto: 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)
// They should not have the same `y` position!
compare-elements-position-false: (
"#main-content > .item-info .stab:nth-of-type(1)",
"#main-content > .item-info .stab:nth-of-type(2)",
("y"),
)
// But they should have the same `x` position.
compare-elements-position: (
"#main-content > .item-info .stab:nth-of-type(1)",
"#main-content > .item-info .stab:nth-of-type(2)",
("x"),
)
// They are supposed to have the same height too.
compare-elements-css: (
"#main-content > .item-info .stab:nth-of-type(1)",
"#main-content > .item-info .stab:nth-of-type(2)",
["height"],
)
3 changes: 3 additions & 0 deletions src/test/rustdoc-gui/src/lib2/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ impl Foo {
pub fn a_method(&self) {}
}

#[doc(cfg(feature = "foo-method"))]
#[deprecated = "Whatever [`Foo::a_method`](#method.a_method)"]
pub trait Trait {
type X;
const Y: u32;

#[deprecated = "Whatever [`Foo`](#tadam)"]
fn foo() {}
}

Expand Down