chore: audit components
This commit is contained in:
@@ -7,3 +7,4 @@ description = "Small helpers shared by the component crates: layout shorthands,
|
||||
[dependencies]
|
||||
gpui = { workspace = true }
|
||||
gpui-native-theme = { workspace = true }
|
||||
log = "0.4"
|
||||
|
||||
+25
-2
@@ -4,21 +4,42 @@ use gpui::{
|
||||
Refineable as _, StatefulInteractiveElement, StyleRefinement, Styled, Window, WindowId, div,
|
||||
px,
|
||||
};
|
||||
use gpui_native_theme::ActiveTheme as _;
|
||||
use gpui_native_theme::{ActiveTheme as _, FOCUS_RING_SPREAD};
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// A row whose children center on the cross axis.
|
||||
#[must_use]
|
||||
pub fn h_flex() -> Div {
|
||||
div().flex().flex_row().items_center()
|
||||
}
|
||||
|
||||
/// A column whose children stack on the main axis.
|
||||
#[must_use]
|
||||
pub fn v_flex() -> Div {
|
||||
div().flex().flex_col()
|
||||
}
|
||||
|
||||
/// Logs the error and yields the success value, if any.
|
||||
pub trait ResultLogErr<T> {
|
||||
/// Logs the error and yields the success value, if any.
|
||||
fn log_err(self) -> Option<T>;
|
||||
}
|
||||
|
||||
impl<T, E: std::fmt::Display> ResultLogErr<T> for Result<T, E> {
|
||||
fn log_err(self) -> Option<T> {
|
||||
match self {
|
||||
Ok(value) => Some(value),
|
||||
Err(error) => {
|
||||
log::warn!("{error}");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Extensions over [`Styled`], shared by the components.
|
||||
pub trait StyledExt: Styled + Sized {
|
||||
#[must_use]
|
||||
fn refine_style(mut self, style: &StyleRefinement) -> Self {
|
||||
self.style().refine(style);
|
||||
self
|
||||
@@ -38,6 +59,7 @@ pub fn focus_handle(id: &ElementId, window: &mut Window, cx: &mut App) -> FocusH
|
||||
}
|
||||
|
||||
/// The painted bounds of elements that tooltips anchor to, per window and element id.
|
||||
/// Entries are never evicted: bounds are bounded by live windows, though long-lived processes minting dynamic per-item ids could accumulate.
|
||||
#[derive(Default)]
|
||||
struct AnchorBoundsRegistry(HashMap<(WindowId, ElementId), Bounds<Pixels>>);
|
||||
|
||||
@@ -72,7 +94,7 @@ pub fn record_anchor_bounds(
|
||||
|
||||
/// Returns a focus ring shadow with the given color at half ink.
|
||||
pub fn focus_ring(color: Hsla) -> Vec<BoxShadow> {
|
||||
vec![BoxShadow::new(px(0.), px(0.), color.alpha(0.5)).spread_radius(px(3.))]
|
||||
vec![BoxShadow::new(px(0.), px(0.), color.alpha(0.5)).spread_radius(FOCUS_RING_SPREAD)]
|
||||
}
|
||||
|
||||
/// The next selectable row in the direction, or `None` at the ends.
|
||||
@@ -128,6 +150,7 @@ pub fn selectable_label_color(cx: &App, selected: bool, disabled: bool) -> Hsla
|
||||
}
|
||||
|
||||
/// A selectable row's background.
|
||||
#[must_use]
|
||||
pub fn paint_selectable_row<R>(cx: &App, row: R, selected: bool, disabled: bool) -> R
|
||||
where
|
||||
R: IntoElement + Styled + StatefulInteractiveElement,
|
||||
|
||||
Reference in New Issue
Block a user