gpui: Add grid_rows_min_content and grid_rows_max_content methods (#61837)
# Objective - GPUI provides `grid_cols_min_content()` and `grid_cols_max_content()`, but the `grid_rows_*_content()` methods are missing. ## Solution - This PR adds the `grid_rows_min_content()` and `grid_rows_max_content()` methods, and renames the enum `TemplateColumnMinSize` to `GridTemplateMinSize`. ## Testing - I have tested locally. ## Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [ ] Unsafe blocks (if any) have justifying comments - [ ] The content adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [ ] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Release Notes: - N/A
This commit is contained in:
1 parent
c2db0f1a97
commit
5ccbbbd88f
3 files changed
+33
-14
No files matched your search
@@ -142,13 +142,13 @@ impl ObjectFit {
|
||||
#[derive(
|
||||
Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Default, JsonSchema, Serialize, Deserialize,
|
||||
)]
|
||||
pub enum TemplateColumnMinSize {
|
||||
/// The column size may be 0
|
||||
pub enum GridTemplateMinSize {
|
||||
/// The column or row size may be 0
|
||||
#[default]
|
||||
Zero,
|
||||
/// The column size can be determined by the min content
|
||||
/// The column or row size can be determined by the min content
|
||||
MinContent,
|
||||
/// The column size can be determined by the max content
|
||||
/// The column or row size can be determined by the max content
|
||||
MaxContent,
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ pub struct GridTemplate {
|
||||
/// How this template directive should be repeated
|
||||
pub repeat: u16,
|
||||
/// The minimum size in the repeat(<>, minmax(_, 1fr)) equation
|
||||
pub min_size: TemplateColumnMinSize,
|
||||
pub min_size: GridTemplateMinSize,
|
||||
}
|
||||
|
||||
/// The CSS styling that can be applied to an element via the `Styled` trait
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::{
|
||||
self as gpui, AbsoluteLength, AlignContent, AlignItems, AlignSelf, BorderStyle, CursorStyle,
|
||||
DefiniteLength, Display, Fill, FlexDirection, FlexWrap, Font, FontFeatures, FontStyle,
|
||||
FontWeight, GridPlacement, GridTemplate, Hsla, JustifyContent, Length, SharedString,
|
||||
StrikethroughStyle, StyleRefinement, TemplateColumnMinSize, TextAlign, TextOverflow,
|
||||
FontWeight, GridPlacement, GridTemplate, GridTemplateMinSize, Hsla, JustifyContent, Length,
|
||||
SharedString, StrikethroughStyle, StyleRefinement, TextAlign, TextOverflow,
|
||||
TextStyleRefinement, UnderlineStyle, WhiteSpace, px, relative, rems,
|
||||
};
|
||||
pub use gpui_macros::{
|
||||
@@ -752,7 +752,7 @@ pub trait Styled: Sized {
|
||||
fn grid_cols(mut self, cols: u16) -> Self {
|
||||
self.style().grid_cols = Some(GridTemplate {
|
||||
repeat: cols,
|
||||
min_size: TemplateColumnMinSize::Zero,
|
||||
min_size: GridTemplateMinSize::Zero,
|
||||
});
|
||||
self
|
||||
}
|
||||
@@ -762,7 +762,7 @@ pub trait Styled: Sized {
|
||||
fn grid_cols_min_content(mut self, cols: u16) -> Self {
|
||||
self.style().grid_cols = Some(GridTemplate {
|
||||
repeat: cols,
|
||||
min_size: TemplateColumnMinSize::MinContent,
|
||||
min_size: GridTemplateMinSize::MinContent,
|
||||
});
|
||||
self
|
||||
}
|
||||
@@ -771,7 +771,7 @@ pub trait Styled: Sized {
|
||||
fn grid_cols_max_content(mut self, cols: u16) -> Self {
|
||||
self.style().grid_cols = Some(GridTemplate {
|
||||
repeat: cols,
|
||||
min_size: TemplateColumnMinSize::MaxContent,
|
||||
min_size: GridTemplateMinSize::MaxContent,
|
||||
});
|
||||
self
|
||||
}
|
||||
@@ -780,7 +780,26 @@ pub trait Styled: Sized {
|
||||
fn grid_rows(mut self, rows: u16) -> Self {
|
||||
self.style().grid_rows = Some(GridTemplate {
|
||||
repeat: rows,
|
||||
min_size: TemplateColumnMinSize::Zero,
|
||||
min_size: GridTemplateMinSize::Zero,
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the grid rows with min-content minimum sizing.
|
||||
/// Unlike grid_rows, it won't shrink to height 0 in AvailableSpace::MinContent constraints.
|
||||
fn grid_rows_min_content(mut self, rows: u16) -> Self {
|
||||
self.style().grid_rows = Some(GridTemplate {
|
||||
repeat: rows,
|
||||
min_size: GridTemplateMinSize::MinContent,
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the grid rows with max-content maximum sizing for content-based row heights.
|
||||
fn grid_rows_max_content(mut self, rows: u16) -> Self {
|
||||
self.style().grid_rows = Some(GridTemplate {
|
||||
repeat: rows,
|
||||
min_size: GridTemplateMinSize::MaxContent,
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
@@ -460,21 +460,21 @@ impl ToTaffy<taffy::style::Style> for Style {
|
||||
unit.map(|template| {
|
||||
match template.min_size {
|
||||
// grid-template-*: repeat(<number>, minmax(0, 1fr));
|
||||
crate::TemplateColumnMinSize::Zero => {
|
||||
crate::GridTemplateMinSize::Zero => {
|
||||
vec![repeat(
|
||||
template.repeat,
|
||||
vec![minmax(length(0.0_f32), fr(1.0_f32))],
|
||||
)]
|
||||
}
|
||||
// grid-template-*: repeat(<number>, minmax(min-content, 1fr));
|
||||
crate::TemplateColumnMinSize::MinContent => {
|
||||
crate::GridTemplateMinSize::MinContent => {
|
||||
vec![repeat(
|
||||
template.repeat,
|
||||
vec![minmax(min_content(), fr(1.0_f32))],
|
||||
)]
|
||||
}
|
||||
// grid-template-*: repeat(<number>, minmax(0, max-content))
|
||||
crate::TemplateColumnMinSize::MaxContent => {
|
||||
crate::GridTemplateMinSize::MaxContent => {
|
||||
vec![repeat(
|
||||
template.repeat,
|
||||
vec![minmax(length(0.0_f32), max_content())],
|
||||
|
||||
Reference in new issue
Block a user