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

@ -1,3 +1,6 @@
// This won't be documented further as it is intended to be removed, or merged with the `time_format` crate.
#![allow(missing_docs)]
use chrono::{DateTime, Local, NaiveDateTime};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]

View file

@ -0,0 +1,83 @@
use gpui::{
div, AnyElement, Bounds, Div, DivFrameState, Element, ElementId, GlobalElementId, Hitbox,
IntoElement, LayoutId, ParentElement, Pixels, StyleRefinement, Styled, WindowContext,
};
/// An element that sets a particular rem size for its children.
pub struct WithRemSize {
div: Div,
rem_size: Pixels,
}
impl WithRemSize {
/// Create a new [WithRemSize] element, which sets a
/// particular rem size for its children.
pub fn new(rem_size: impl Into<Pixels>) -> Self {
Self {
div: div(),
rem_size: rem_size.into(),
}
}
}
impl Styled for WithRemSize {
fn style(&mut self) -> &mut StyleRefinement {
self.div.style()
}
}
impl ParentElement for WithRemSize {
fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) {
self.div.extend(elements)
}
}
impl Element for WithRemSize {
type RequestLayoutState = DivFrameState;
type PrepaintState = Option<Hitbox>;
fn id(&self) -> Option<ElementId> {
self.div.id()
}
fn request_layout(
&mut self,
id: Option<&GlobalElementId>,
cx: &mut WindowContext,
) -> (LayoutId, Self::RequestLayoutState) {
cx.with_rem_size(Some(self.rem_size), |cx| self.div.request_layout(id, cx))
}
fn prepaint(
&mut self,
id: Option<&GlobalElementId>,
bounds: Bounds<Pixels>,
request_layout: &mut Self::RequestLayoutState,
cx: &mut WindowContext,
) -> Self::PrepaintState {
cx.with_rem_size(Some(self.rem_size), |cx| {
self.div.prepaint(id, bounds, request_layout, cx)
})
}
fn paint(
&mut self,
id: Option<&GlobalElementId>,
bounds: Bounds<Pixels>,
request_layout: &mut Self::RequestLayoutState,
prepaint: &mut Self::PrepaintState,
cx: &mut WindowContext,
) {
cx.with_rem_size(Some(self.rem_size), |cx| {
self.div.paint(id, bounds, request_layout, prepaint, cx)
})
}
}
impl IntoElement for WithRemSize {
type Element = Self;
fn into_element(self) -> Self::Element {
self
}
}