Files · Items: one icon map, file icon, file row and file grid
The crate had two maps from a file's name to its icon, in chat and in the file tree, and they disagreed. One map now lives in primitives, over the Lucide file-* icons, and chat, agent, the file tree and the directory listing use it. FileIcon draws it for a file or a folder. FileItem is a file's row, a ListItem with its size and when it changed. FileList is the directory listing. FileGrid lays tiles in the order given, with a cursor seeded from the owner's pick: arrows by tile and by row, Home, End, Enter and a double press to open. The count of what fits a width has one home, layout's columns_for, and fit builds on it.
This commit is contained in:
1 parent
e75171c995
commit
a846e10847
36 files changed
+1024
-77
No files matched your search
+16
-2
@@ -5,11 +5,18 @@ use gpui::{
|
||||
use smallvec::SmallVec;
|
||||
|
||||
/// Columns for `width`, each at least `min`, `gap` apart.
|
||||
fn columns_for(width: Pixels, min: Pixels, gap: Pixels) -> u16 {
|
||||
pub(crate) fn columns_for(width: Pixels, min: Pixels, gap: Pixels) -> u16 {
|
||||
let fit = ((width + gap) / (min + gap)).floor();
|
||||
fit.clamp(1.0, f32::from(u16::MAX)) as u16
|
||||
}
|
||||
|
||||
/// How many items `item` wide with `gap` between fit across `width`, at least one, and the inset that centers them.
|
||||
pub(crate) fn fit(width: Pixels, item: Pixels, gap: Pixels) -> (usize, Pixels) {
|
||||
let count = columns_for(width, item, gap) as usize;
|
||||
let used = (item + gap) * count as f32 - gap;
|
||||
(count, ((width - used) / 2.0).max(Pixels::ZERO))
|
||||
}
|
||||
|
||||
/// Index of the shortest column; ties go left.
|
||||
fn shortest(heights: &[Pixels]) -> usize {
|
||||
heights
|
||||
@@ -174,7 +181,14 @@ impl RenderOnce for Masonry {
|
||||
mod tests {
|
||||
use gpui::px;
|
||||
|
||||
use super::{columns_for, shortest};
|
||||
use super::{columns_for, fit, shortest};
|
||||
|
||||
#[test]
|
||||
fn what_fits_sits_centered() {
|
||||
assert_eq!(fit(px(100.0), px(3.0), px(2.0)), (20, px(1.0)));
|
||||
assert_eq!(fit(px(98.0), px(3.0), px(2.0)), (20, px(0.0)));
|
||||
assert_eq!(fit(px(2.0), px(3.0), px(2.0)), (1, px(0.0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn columns_fit_the_width() {
|
||||
|
||||
@@ -19,6 +19,7 @@ pub use collapse::{Accordion, AccordionItem, Collapsible};
|
||||
pub use dock::{Dock, DockLayout, DockPanel, DockSide, Spot};
|
||||
pub use floating::FloatingPanel;
|
||||
pub use grid::{Masonry, SimpleGrid};
|
||||
pub(crate) use grid::{columns_for, fit};
|
||||
pub use page::{AppShell, MasterDetail, Page};
|
||||
pub use panes::{PaneGroup, PaneId, PaneLayout};
|
||||
pub(crate) use scroll::bring_into_view;
|
||||
|
||||
Reference in new issue
Block a user