ui crate docs & spring cleaning (#18768)

Similar to https://github.com/zed-industries/zed/pull/18690 &
https://github.com/zed-industries/zed/pull/18695, this PR enables
required docs for `ui` and does some cleanup.

Changes:
- Enables the `deny(missing_docs)` crate-wide.
- Adds `allow(missing_docs)` on many modules until folks pick them up to
document them
- Documents some modules (all in `ui/src/styles`)
- Crate root-level organization: Traits move to `traits`, other misc
organization
- Cleaned out a bunch of unused code.

Note: I'd like to remove `utils/format_distance` but the assistant panel
uses it. To move it over to use the `time_format` crate we may need to
update it to use `time` instead of `chrono`. Needs more investigation.

Release Notes:

- N/A
This commit is contained in:
Nate Butler 2024-10-05 23:28:34 -04:00 committed by GitHub
parent c9bee9f81f
commit 8376dd2011
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
66 changed files with 405 additions and 364 deletions

View file

@ -87,6 +87,7 @@ pub trait StyledTypography: Styled + Sized {
impl<E: Styled> StyledTypography for E {}
/// A utility for getting the size of various semantic text sizes.
#[derive(Debug, Default, Clone)]
pub enum TextSize {
/// The default size for UI text.
@ -128,6 +129,7 @@ pub enum TextSize {
}
impl TextSize {
/// Returns the text size in rems.
pub fn rems(self, cx: &WindowContext) -> Rems {
let theme_settings = ThemeSettings::get_global(cx);
@ -143,20 +145,27 @@ impl TextSize {
}
/// The size of a [`Headline`] element
///
/// Defaults to a Major Second scale.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Default)]
pub enum HeadlineSize {
/// An extra small headline - `~14px` @16px/rem
XSmall,
/// A small headline - `16px` @16px/rem
Small,
#[default]
/// A medium headline - `~18px` @16px/rem
Medium,
/// A large headline - `~20px` @16px/rem
Large,
/// An extra large headline - `~22px` @16px/rem
XLarge,
}
impl HeadlineSize {
pub fn size(self) -> Rems {
/// Returns the headline size in rems.
pub fn rems(self) -> Rems {
match self {
// Based on the Major Second scale
Self::XSmall => rems(0.88),
Self::Small => rems(1.0),
Self::Medium => rems(1.125),
@ -165,6 +174,7 @@ impl HeadlineSize {
}
}
/// Returns the line height for the headline size.
pub fn line_height(self) -> Rems {
match self {
Self::XSmall => rems(1.6),
@ -176,6 +186,8 @@ impl HeadlineSize {
}
}
/// A headline element, used to emphasize some text and
/// create a visual hierarchy.
#[derive(IntoElement)]
pub struct Headline {
size: HeadlineSize,
@ -190,13 +202,14 @@ impl RenderOnce for Headline {
div()
.font(ui_font)
.line_height(self.size.line_height())
.text_size(self.size.size())
.text_size(self.size.rems())
.text_color(cx.theme().colors().text)
.child(self.text)
}
}
impl Headline {
/// Create a new headline element.
pub fn new(text: impl Into<SharedString>) -> Self {
Self {
size: HeadlineSize::default(),
@ -205,11 +218,13 @@ impl Headline {
}
}
/// Set the size of the headline.
pub fn size(mut self, size: HeadlineSize) -> Self {
self.size = size;
self
}
/// Set the color of the headline.
pub fn color(mut self, color: Color) -> Self {
self.color = color;
self