gui: tree indents, the indeterminate bar and the player thumbs follow UI zoom
Three raw px() in render code measured against rem-sized neighbors, so each was right only at 100% zoom: the notes/pictures tree's row indent (pl(px(8 + 16n)), written twice; audit C8), the indeterminate progress bar's slide (left(px) against a scaled() width; B1), and the scrubber and speed thumbs' centering offsets (B2 — the speed thumb's -7px was also half a pixel short of its 15px icon::SM). The indent is now INDENT_BASE/INDENT_STEP in scaled() via one row_frame shared by the editing and normal rows; the others are scaled() or derived from the thumb's own size. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e37a4b9063
commit
c7e8739eca
3 files changed
+36
-32
No files matched your search
@@ -16,10 +16,11 @@ use std::hash::Hash;
|
||||
use std::ops::Range;
|
||||
|
||||
use gpui::{
|
||||
AnyElement, App, Context, Div, Entity, EventEmitter, FocusHandle, Focusable, FontWeight,
|
||||
HighlightStyle, IntoElement, KeyDownEvent, MouseButton, MouseDownEvent, MouseMoveEvent, Pixels,
|
||||
Point, Render, ScrollHandle, ScrollStrategy, SharedString, Stateful, StyledText, Subscription,
|
||||
UniformListScrollHandle, Window, div, point, prelude::*, px, svg, uniform_list,
|
||||
AnyElement, App, Context, Div, ElementId, Entity, EventEmitter, FocusHandle, Focusable,
|
||||
FontWeight, HighlightStyle, IntoElement, KeyDownEvent, MouseButton, MouseDownEvent,
|
||||
MouseMoveEvent, Pixels, Point, Render, ScrollHandle, ScrollStrategy, SharedString, Stateful,
|
||||
StyledText, Subscription, UniformListScrollHandle, Window, div, point, prelude::*, px, svg,
|
||||
uniform_list,
|
||||
};
|
||||
use palette::IntoColor;
|
||||
|
||||
@@ -48,6 +49,26 @@ const NODE_OPEN_ICON: Icon = Icon::FolderOpen;
|
||||
/// because the virtualized list has no `gap` of its own.
|
||||
const ROW_GAP: f32 = 1.;
|
||||
|
||||
/// Left padding of a root-level row, in design pixels.
|
||||
const INDENT_BASE: f32 = 8.;
|
||||
/// How much further in each level of nesting starts, in design pixels.
|
||||
const INDENT_STEP: f32 = 16.;
|
||||
|
||||
/// The box every tree row is drawn in: one `control::ROW` tall, its indent
|
||||
/// growing the left padding (in rems, so it follows the UI zoom), and a little
|
||||
/// right padding to leave room for the cloud.
|
||||
fn row_frame(id: impl Into<ElementId>, indent: usize) -> Stateful<Div> {
|
||||
div()
|
||||
.id(id)
|
||||
.flex()
|
||||
.flex_row()
|
||||
.items_center()
|
||||
.gap(scaled(4.))
|
||||
.h(control::ROW)
|
||||
.pl(scaled(INDENT_BASE + indent as f32 * INDENT_STEP))
|
||||
.pr_1()
|
||||
}
|
||||
|
||||
/// The per-domain glyphs a tree draws. Structural geometry (indent, the twisty
|
||||
/// cell, a fixed-width icon column) is identical for every tree; only which
|
||||
/// glyph fills the icon column differs. A `None` icon leaves the (still
|
||||
@@ -928,20 +949,12 @@ impl<Id: Clone + Eq + Hash + 'static> HierarchicalSidebar<Id> {
|
||||
let twisty = if row.is_collapsed { CHEVRON_RIGHT } else { CHEVRON_DOWN };
|
||||
let structural_icon = self.style.structural_icon(row.is_expandable, row.is_collapsed);
|
||||
|
||||
div()
|
||||
.id(("tree-row-editing", ix))
|
||||
.flex()
|
||||
.flex_row()
|
||||
.items_center()
|
||||
.gap(scaled(4.))
|
||||
// Exactly one row tall, like every other row: `uniform_list` measures
|
||||
// row 0 and gives every row that height, so an editing row that grew
|
||||
// to fit its field would either set the pitch for the whole tree (if
|
||||
// it happened to be row 0) or be clipped (if it didn't). The field
|
||||
// is built `.compact()` to fit — see [`Self::ensure_editing`].
|
||||
.h(control::ROW)
|
||||
.pl(px(8. + row.indent as f32 * 16.))
|
||||
.pr_1()
|
||||
// Exactly one row tall, like every other row: `uniform_list` measures
|
||||
// row 0 and gives every row that height, so an editing row that grew
|
||||
// to fit its field would either set the pitch for the whole tree (if
|
||||
// it happened to be row 0) or be clipped (if it didn't). The field
|
||||
// is built `.compact()` to fit — see [`Self::ensure_editing`].
|
||||
row_frame(("tree-row-editing", ix), row.indent)
|
||||
.when(row.is_expandable, |r| r.child(icon_cell(theme, Some(twisty))))
|
||||
.child(icon_cell(theme, structural_icon))
|
||||
.child(div().flex_1().min_w(px(0.)).child(input))
|
||||
@@ -1016,17 +1029,8 @@ impl<Id: Clone + Eq + Hash + 'static> HierarchicalSidebar<Id> {
|
||||
this.toggle_collapsed(twisty_id.clone(), cx);
|
||||
}));
|
||||
|
||||
div()
|
||||
.id(("tree-row", ix))
|
||||
row_frame(("tree-row", ix), row.indent)
|
||||
.relative()
|
||||
.flex()
|
||||
.flex_row()
|
||||
.items_center()
|
||||
.gap(scaled(4.))
|
||||
.h(control::ROW)
|
||||
// Indent grows the left padding; right padding leaves room for the cloud.
|
||||
.pl(px(8. + row.indent as f32 * 16.))
|
||||
.pr_1()
|
||||
.cursor_pointer()
|
||||
// Selected highlight brightens to the full selected block while the
|
||||
// sidebar is focused (the cursor), and dims to the hover tint when it
|
||||
|
||||
@@ -1362,7 +1362,7 @@ impl PlayerControls {
|
||||
div()
|
||||
.absolute()
|
||||
.left(relative(fill))
|
||||
.ml(px(-SCRUBBER_THUMB_SIZE / 2.))
|
||||
.ml(scaled(-SCRUBBER_THUMB_SIZE / 2.))
|
||||
.size(scaled(SCRUBBER_THUMB_SIZE))
|
||||
.rounded(shape::PILL)
|
||||
.bg(theme.accent)
|
||||
@@ -1565,7 +1565,7 @@ impl PlayerControls {
|
||||
div()
|
||||
.absolute()
|
||||
.left(relative(ratio))
|
||||
.ml(px(-7.))
|
||||
.ml(-(icon::SM / 2.))
|
||||
.size(icon::SM)
|
||||
.rounded(shape::PILL)
|
||||
.bg(theme.accent)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use gpui::{Animation, AnimationExt, Div, ParentElement, SharedString, Styled, div, px, relative};
|
||||
use gpui::{Animation, AnimationExt, Div, ParentElement, SharedString, Styled, div, relative};
|
||||
|
||||
use crate::sizing::{control, scaled, shape};
|
||||
use crate::theme::Theme;
|
||||
@@ -63,7 +63,7 @@ pub fn indeterminate_progress_bar(
|
||||
move |this, delta| {
|
||||
// Triangle wave: 0 → fill_px → 0 over one cycle, so the
|
||||
// fill reverses at each end instead of jumping back.
|
||||
this.left(px(fill_px * (1. - (2. * delta - 1.).abs())))
|
||||
this.left(scaled(fill_px * (1. - (2. * delta - 1.).abs())))
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user