mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 00:34:25 +00:00
Timeline panel: headers sized by content, ruler on the lanes' origin, whole timecode
- HeaderColumns: one set of header columns per pass, worked out from the model before the view shows. The switch columns are the ones some track has; the name column is the widest track name with its pads and indent, or the width the user dragged; the headers are at least as wide as the timecode and toolbar block over them. Every pane's TrackStack, the top strip's head column and the TimelineView's inset (header_extent) take the same extent. - The top strip's head column is the header extent and its columns touch; the marker strip and the ruler sit in a fill-width stack, so they span the time area from where the lanes start. - BodyLayout::grid takes owned or borrowed columns. - TimecodeField::large keeps the timecode face (equal-width digits), so its widest sample is its widest text. - MeasureCx::field_text: an editable text's room with the caret past its last letter. TextField, NumberField, TimecodeField, DateField, ComboBox and the font picker size by it. - Trial: the ruler starts where the lanes do, and no header has a column no track has.
This commit is contained in:
@@ -455,7 +455,7 @@ impl Component for FontPicker<'_> {
|
||||
/// The width of the longest family names in common use, so the field keeps its size whichever family is picked.
|
||||
fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 {
|
||||
let current = cx.value().map_or("", String::as_str);
|
||||
let widest = [NAME_SAMPLE, current].into_iter().map(|text| cx.layout(&TextRun::new(text)).size()).fold(Vec2::ZERO, Vec2::max);
|
||||
let widest = [NAME_SAMPLE, current].into_iter().map(|text| cx.field_text(&TextRun::new(text))).fold(Vec2::ZERO, Vec2::max);
|
||||
let name = cx.words::<FontPickerWords>().list.clone();
|
||||
Vec2::new(widest.x + reserve(cx.style, &[], &Self::trailing(name)), widest.y)
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ pub use render_queue::{
|
||||
RenderItemId, RenderQueueEvent, RenderQueueItem, RenderQueueList, RenderQueueListOutput, RenderQueueWords, RenderStatus, format_eta,
|
||||
};
|
||||
pub use ruler::{RenderBarState, RenderSpan, SplitMarks, TimeTick, TimelineRuler, TimelineRulerResponse, ruler_ladder, ruler_ticks};
|
||||
pub use stack::{TrackRow, TrackStack};
|
||||
pub use stack::{HeaderColumns, TrackRow, TrackStack};
|
||||
pub use timecode::{
|
||||
TimecodeCodec, TimecodeField, TimecodeFieldOutput, TimecodePanel, TimecodePanelOutput, TimecodePanelSettings, TimecodeRow, TimecodeRowKind,
|
||||
TimecodeSource, TimecodeText, TimecodeWords,
|
||||
|
||||
@@ -6,7 +6,7 @@ use super::clips::{ClipContent, ClipLane, TimelineTool};
|
||||
use super::markers::{MarkerEdit, MarkerSpan, MarkerStrip};
|
||||
use super::ruler::TimelineRuler;
|
||||
use super::stack::{
|
||||
LANE, LOCK, MUTE, MovePointer, MoveTarget, NAME, NAME_DEFAULT, OUTPUT, RowGeom, SOLO, SYNC_LOCK, Side, TARGET, TrackEvent, TrackRow, TrackStack,
|
||||
HeaderColumns, LANE, LOCK, MUTE, MovePointer, MoveTarget, NAME, OUTPUT, RowGeom, SOLO, SYNC_LOCK, Side, TARGET, TrackEvent, TrackRow, TrackStack,
|
||||
Tracks, resolve_move, set_event,
|
||||
};
|
||||
use super::view::{Overlay, TimelineView, TimelineWords, time_axis};
|
||||
@@ -16,13 +16,14 @@ use crate::clock::FollowMode;
|
||||
use crate::markers::MarkerColor;
|
||||
use crate::model::{ClipId, ClipInfo, TimelineModel, TrackId, TrackInfo, TrackKind};
|
||||
use crate::time::{Tick, TimeRange};
|
||||
use crate::timecode::TimeFormat;
|
||||
use craft_behavior::{
|
||||
Axis, ColumnKey, ColumnWidth, CursorIcon, CursorPriority, EditEvent, EditEvents, GestureId, IconId, MarqueeSelect, Metrics, Mixed,
|
||||
Axis, ColumnKey, ColumnWidth, CursorIcon, CursorPriority, EditEvent, EditEvents, GestureId, IconId, MarqueeSelect, Metrics, Mixed, Proposal,
|
||||
SelectionChange,
|
||||
};
|
||||
use craft_ui::buttons::{IconButton, ToggleButton};
|
||||
use craft_ui::contract::{
|
||||
Bind, BodyCx, BodyLayout, CollectionEvent, CollectionResponse, ColumnEvent, Common, Component, Container, ContainerProps, Cx, EditResponse,
|
||||
Bind, BodyCx, BodyLayout, CollectionEvent, CollectionResponse, ColumnEvent, Common, Component, Container, ContainerProps, Cx, EditResponse, Gap,
|
||||
NoValue, Outcome, Pattern, Props, Remember as _, Role, Show as _, ShowCollection as _, ShowContainer as _, ShownRow, SizeLimits, Sizing,
|
||||
SweepApply, SweepStep,
|
||||
};
|
||||
@@ -177,8 +178,10 @@ pub struct TimelineToolbar {
|
||||
/// Layout, top to bottom: the large [`TimecodeField`] and the toolbar over the headers beside the [`MarkerStrip`] and the
|
||||
/// [`TimelineRuler`]; then the caption tracks, the video tracks (V1 nearest the divider), the divider, the audio tracks
|
||||
/// and the Mix row when the model has a master volume; the bar of the [`TimelineView`] at the bottom. The headers are the
|
||||
/// header columns of each [`TrackStack`], `header_width` wide at the name column and resizable
|
||||
/// ([`TimelineEdit::HeaderWidth`]); the lanes paint their clips' content through [`content`](Self::content).
|
||||
/// [`HeaderColumns`] of every [`TrackStack`]: the colour strip, the name column and the switches some track has. The name
|
||||
/// column is as wide as the widest track name until the user drags it ([`TimelineEdit::HeaderWidth`], kept as
|
||||
/// `header_width`), and the headers are never narrower than the timecode and the toolbar over them. The lanes paint
|
||||
/// their clips' content through [`content`](Self::content).
|
||||
///
|
||||
/// Input: the wheel, the pinch and the keys of [`TimelineView`]; the colour strip of a header opens the label menu; the
|
||||
/// Menu key and Shift+F10 report [`TimelineEdit::ContextMenu`] for the selection's last clip, else the first targeted
|
||||
@@ -282,7 +285,7 @@ struct PlacedRow {
|
||||
/// What the panes share in a pass.
|
||||
struct Panes<'p, 'a> {
|
||||
words: &'p TimelineWords,
|
||||
name: Option<ColumnWidth>,
|
||||
header: &'p HeaderColumns,
|
||||
selection: &'p [ClipId],
|
||||
targets: Option<&'p SnapTargets>,
|
||||
tool: TimelineTool,
|
||||
@@ -299,7 +302,7 @@ impl Panes<'_, '_> {
|
||||
Side::Upper => "Video",
|
||||
Side::Lower => "Audio",
|
||||
};
|
||||
let mut stack = TrackStack::new(label, self.name, self.words).tracks(pane);
|
||||
let mut stack = TrackStack::new(label, self.header, self.words).tracks(pane);
|
||||
match side {
|
||||
Side::Upper => stack = stack.anchored_at_end(),
|
||||
// The caption tracks take the height their rows need, so the video and audio panes keep the rest.
|
||||
@@ -330,7 +333,7 @@ impl Panes<'_, '_> {
|
||||
struct Mapping<'p> {
|
||||
pane: &'p [TrackInfo<'p>],
|
||||
words: &'p TimelineWords,
|
||||
name: Option<ColumnWidth>,
|
||||
header: &'p HeaderColumns,
|
||||
palette: &'p LabelPalette,
|
||||
}
|
||||
|
||||
@@ -396,7 +399,7 @@ impl Mapping<'_> {
|
||||
}
|
||||
CollectionEvent::Column(ColumnEvent::Resized { key, width, .. }) if *key == NAME => {
|
||||
edits.push(TimelineEdit::HeaderWidth(set_event(
|
||||
self.name.unwrap_or(NAME_DEFAULT),
|
||||
ColumnWidth::Fixed(self.header.name),
|
||||
ColumnWidth::Fixed(*width),
|
||||
self.words.header_width.as_str(),
|
||||
)));
|
||||
@@ -524,9 +527,13 @@ impl<M: TimelineModel> Timeline<'_, M> {
|
||||
(Side::Upper, of_kind(|kind| kind == TrackKind::Video)),
|
||||
(Side::Lower, of_kind(|kind| !matches!(kind, TrackKind::Caption | TrackKind::Video))),
|
||||
];
|
||||
// The head block over the headers sets their least width; the headers are worked out before the view shows,
|
||||
// since its inset and every pane's columns take them.
|
||||
let least = Stack::new().measure_in(ui, Proposal::Ideal, |ui, _| head_block(ui, &words, playhead, format, snap, linked_selection)).x;
|
||||
let header = HeaderColumns::measure(ui, &tracks, header_width, least);
|
||||
let shared = Panes {
|
||||
words: &words,
|
||||
name: header_width,
|
||||
header: &header,
|
||||
selection: &selection,
|
||||
targets: targets.as_ref(),
|
||||
tool,
|
||||
@@ -541,22 +548,17 @@ impl<M: TimelineModel> Timeline<'_, M> {
|
||||
|
||||
let overlay = Overlay::default();
|
||||
let area = TimelineView::new(label, Bind::given(view), format, duration)
|
||||
.headers(true)
|
||||
.header_extent(header.extent())
|
||||
.follow(follow, playing, playhead)
|
||||
.edit_points(&points)
|
||||
.overlay(&overlay);
|
||||
let area = match header_width {
|
||||
Some(width) => area.header_width(width),
|
||||
None => area,
|
||||
};
|
||||
let body = |ui: &mut Ui, cx: &mut BodyCx<'_>| {
|
||||
TopStrip::new().show(ui, |ui, _| {
|
||||
TopStrip::new(header.extent()).show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
let field = TimecodeField::new(words.panel.clone(), Bind::given(playhead), format).large().show(ui);
|
||||
timecode_edit = field.edit.events;
|
||||
toolbar = toolbar_row(ui, &words, snap, linked_selection);
|
||||
(timecode_edit, toolbar) = head_block(ui, &words, playhead, format, snap, linked_selection);
|
||||
});
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
// The marker strip and the ruler fill the cell over the time area.
|
||||
Stack::new().fill_width().show(ui, |ui, _| {
|
||||
let strip = MarkerStrip::new(words.overview.clone(), markers);
|
||||
let strip = match shared.targets {
|
||||
Some(targets) => strip.snap(targets),
|
||||
@@ -585,7 +587,7 @@ impl<M: TimelineModel> Timeline<'_, M> {
|
||||
let pane: Vec<TrackInfo<'_>> = indices.iter().map(|&i| tracks[i].clone()).collect();
|
||||
let out = shared.show(ui, side, &pane, indices);
|
||||
pane_rects.push(out.response.rect);
|
||||
let mapping = Mapping { pane: &pane, words: &words, name: header_width, palette: &palette };
|
||||
let mapping = Mapping { pane: &pane, words: &words, header: &header, palette: &palette };
|
||||
mapping.collect(&out, &mut edits, &mut memory, &mut reports);
|
||||
mapping.label_menu(ui, &out.response, &mut memory, &mut edits);
|
||||
};
|
||||
@@ -787,6 +789,20 @@ fn retarget(event: &mut EditEvent<ClipEdit>, target: MoveTarget) {
|
||||
}
|
||||
|
||||
/// The toolbar under the timecode: Snap, Linked Selection, Add Marker and the display settings.
|
||||
/// The block over the headers, a stack's body: the large timecode, then the toolbar. The panel measures it for the
|
||||
/// headers' least width and shows it in the top strip's head cell.
|
||||
fn head_block(
|
||||
ui: &mut Ui,
|
||||
words: &TimelineWords,
|
||||
playhead: Tick,
|
||||
format: TimeFormat,
|
||||
snap: bool,
|
||||
linked_selection: bool,
|
||||
) -> (EditEvents<Tick>, Option<TimelineToolbar>) {
|
||||
let field = TimecodeField::new(words.panel.clone(), Bind::given(playhead), format).large().show(ui);
|
||||
(field.edit.events, toolbar_row(ui, words, snap, linked_selection))
|
||||
}
|
||||
|
||||
fn toolbar_row(ui: &mut Ui, words: &TimelineWords, snap: bool, linked_selection: bool) -> Option<TimelineToolbar> {
|
||||
let shown = Row::new().show(ui, |ui, _| {
|
||||
let snap = ToggleButton::new(words.snap.clone(), Bind::given(snap)).icon(IconSpec::svg(IconId::new("snap"))).icon_only().show(ui);
|
||||
@@ -809,7 +825,8 @@ fn mix_row(ui: &mut Ui, words: &TimelineWords, value: &str) {
|
||||
});
|
||||
}
|
||||
|
||||
/// The top strip: the head block over the headers, then the marker strip and the ruler over the time area.
|
||||
/// The top strip: the head block over the headers, then the marker strip and the ruler over the time area. Its head
|
||||
/// column is the headers' extent and its columns touch, so the ruler starts where the lanes do.
|
||||
#[derive(Component)]
|
||||
#[component(container)]
|
||||
struct TopStrip {
|
||||
@@ -820,9 +837,13 @@ struct TopStrip {
|
||||
}
|
||||
|
||||
impl TopStrip {
|
||||
fn new() -> Self {
|
||||
const COLUMNS: &[ColumnWidth] = &[ColumnWidth::Content, ColumnWidth::fill(1.0)];
|
||||
TopStrip { common: Common::new(), props: ContainerProps::new().sizing(Sizing::FillWidth).layout(BodyLayout::grid(COLUMNS)) }
|
||||
/// A strip whose head column is `headers` wide.
|
||||
fn new(headers: f32) -> Self {
|
||||
let columns = vec![ColumnWidth::Fixed(headers), ColumnWidth::fill(1.0)];
|
||||
TopStrip {
|
||||
common: Common::new(),
|
||||
props: ContainerProps::new().sizing(Sizing::FillWidth).layout(BodyLayout::grid(columns)).body_gap(Gap::None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::model::{ClipId, ClipInfo, TimelineModel, TrackId, TrackInfo, TrackKin
|
||||
use crate::rates::FrameRate;
|
||||
use crate::time::{Tick, TimeRange, TimeView};
|
||||
use crate::timecode::TimeFormat;
|
||||
use craft_behavior::{ColumnWidth, Selection, SelectionModel as _};
|
||||
use craft_behavior::{ColumnWidth, Proposal, Selection, SelectionModel as _};
|
||||
use craft_ui::contract::{Show as _, ShowContainer as _};
|
||||
use craft_ui::display::Text;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
@@ -233,7 +233,9 @@ fn timeline_panel(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
/// The strip over the headers and the time area: the head block in the first column, the ruler row in the second.
|
||||
#[story(TopStrip, covers = [Default], drive = Drive::Never)]
|
||||
fn top_strip(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let out = TopStrip::new().show(ui, |ui, _| {
|
||||
// The head column is as wide as its text, as the panel's is as wide as the headers.
|
||||
let head = Text::new("Head").measure_in(ui, Proposal::Ideal).x;
|
||||
let out = TopStrip::new(head).show(ui, |ui, _| {
|
||||
Text::new("Head").show(ui);
|
||||
Text::new("Ruler").show(ui);
|
||||
});
|
||||
|
||||
+105
-80
@@ -1,10 +1,11 @@
|
||||
//! `TrackStack` and `TrackRow`: the tracks of one pane of a timeline on the collection contract (20.6).
|
||||
//!
|
||||
//! A stack is one collection keyed by [`TrackId`]. Its columns are the colour strip, the track name (the header width the
|
||||
//! app keeps, frozen and resizable), one sweepable toggle column per switch of the [`TrackInfo`] and the lane. A row paints
|
||||
//! its header in the cells and registers the lane's clips as parts of the lane cell through [`ClipLane`], so a track of
|
||||
//! any number of clips costs one pipeline run. Switches reach the app as the collection's `Toggle` events, the width of
|
||||
//! the header as its `Column` events; everything else a row reports is its [`TrackEvent`].
|
||||
//! A stack is one collection keyed by [`TrackId`]. Its columns are the colour strip, the track name (frozen and
|
||||
//! resizable), one sweepable toggle column per switch some track of the timeline has and the lane, as one
|
||||
//! [`HeaderColumns`] gives them to every pane. A row paints its header in the cells and registers the lane's clips as
|
||||
//! parts of the lane cell through [`ClipLane`], so a track of any number of clips costs one pipeline run. Switches
|
||||
//! reach the app as the collection's `Toggle` events, the width of the header as its `Column` events; everything else a
|
||||
//! row reports is its [`TrackEvent`].
|
||||
|
||||
use super::clips::{ClipLane, ClipLaneEvents, ClipLook};
|
||||
use super::view::{TimelineWords, time_axis};
|
||||
@@ -14,19 +15,20 @@ use crate::model::{ClipId, TrackId, TrackInfo, TrackKind};
|
||||
use crate::time::Tick;
|
||||
use craft_behavior::{
|
||||
ColumnKey, ColumnWidth, CursorIcon, DisplayOrder, EditEvent, EditEvents, HitLevel, HitPriority, IconId, ItemSource, MarqueeSelect, Metrics,
|
||||
Mixed, PartKey, PressPhase, Selection, SelectionChange, Sense, SizeHint, SpanLayout,
|
||||
Mixed, PartKey, PressPhase, Proposal, Selection, SelectionChange, Sense, SizeHint, SpanLayout,
|
||||
};
|
||||
use craft_theme::Opacity;
|
||||
use craft_ui::contract::{
|
||||
Access, Bind, BindMut, Collection, CollectionProps, CollectionResponse, ColumnKind, ColumnSpec, Common, Component, ContainerProps, Cx, Edit as _,
|
||||
ItemKeys, ItemOutput, MeasureCx, Name, Outcome, PaintUi, PartsCx, Pointer as _, Props, Remember as _, Role, Scroll, ScrollAnchor, SelectMode,
|
||||
Sizing, Styled as _, ToggleColumn, WordSetCx as _,
|
||||
Show as _, Sizing, Styled as _, ToggleColumn, WordSetCx as _,
|
||||
};
|
||||
use craft_ui::display::Text;
|
||||
use craft_ui::primitives::{IconSpec, PaintShape, RectSide, RuleKind};
|
||||
use craft_ui::runtime::commands::FireSource;
|
||||
use craft_ui::runtime::env::Label;
|
||||
use craft_ui::runtime::env::{Env, Label};
|
||||
use craft_ui::style::{ComponentStyle, DataColor, IconLook, Stateful, StyleColor, StyleCx, SurfaceLook, TextLook, TypeRole, UiTokens};
|
||||
use egui::{CornerRadius, Pos2, Rect, Response, Vec2};
|
||||
use egui::{CornerRadius, Pos2, Rect, Response, Ui, Vec2};
|
||||
use std::sync::Arc;
|
||||
|
||||
/// The colour strip: a click on it opens the label menu.
|
||||
@@ -83,12 +85,10 @@ pub struct TrackSizes {
|
||||
|
||||
/// A track grows to at most this many heights of a large thumbnail.
|
||||
const MOST_IN_THUMBS: f32 = 4.0;
|
||||
/// The name column's width until the user drags it.
|
||||
pub(crate) const NAME_DEFAULT: ColumnWidth = ColumnWidth::Controls(6.0);
|
||||
/// A switch column is one control wide.
|
||||
const SWITCH_WIDTH: ColumnWidth = ColumnWidth::Controls(1.0);
|
||||
/// The colour strip is a quarter of a control wide.
|
||||
const STRIP_WIDTH: ColumnWidth = ColumnWidth::Controls(0.25);
|
||||
/// The colour strip is this share of a switch column wide.
|
||||
const STRIP_SHARE: f32 = 0.25;
|
||||
/// The role the track name paints in, and is measured in for the name column.
|
||||
const NAME_ROLE: TypeRole = TypeRole::Label;
|
||||
|
||||
impl TrackSizes {
|
||||
/// The sizes the tokens give.
|
||||
@@ -120,18 +120,85 @@ impl TrackSizes {
|
||||
let (short, tall) = (self.caption, self.video);
|
||||
if now < (short + tall) / 2.0 { tall } else { short }
|
||||
}
|
||||
}
|
||||
|
||||
/// The width of the headers (colour strip, name and the switches) for a name column `name` wide: where the lane
|
||||
/// begins. The view reads it before its body has laid the stacks out, so it sums the same column widths the stacks
|
||||
/// declare.
|
||||
pub fn header_extent(&self, name: Option<ColumnWidth>) -> f32 {
|
||||
let fixed = |width: ColumnWidth| match width.in_unit(self.unit) {
|
||||
/// The track headers of a timeline in one pass: the switch columns some track has and the name column's width. Every
|
||||
/// pane's [`TrackStack`] declares these columns, and the panel's head cell and the view's inset take
|
||||
/// [`extent`](Self::extent), so the lanes, the ruler and the time area start at one x however the panes split the
|
||||
/// tracks. The view reads the extent before its body runs, so it is worked out from the model before the view shows.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub struct HeaderColumns {
|
||||
/// The switch columns some track of the timeline has, in header order. A track without one leaves its cell empty.
|
||||
pub switches: Vec<ColumnKey>,
|
||||
/// The name column's width, in points.
|
||||
pub name: f32,
|
||||
/// A switch column's width: one control height.
|
||||
pub switch: f32,
|
||||
}
|
||||
|
||||
impl HeaderColumns {
|
||||
/// The headers of `tracks` under `ui`. The name column is `dragged` wide once the user dragged it, else as wide as
|
||||
/// the widest track name with its pads and indent. It widens until the headers are `least` wide: the block over
|
||||
/// them (the timecode and the toolbar) sets their least width, as Premiere's does.
|
||||
pub fn measure(ui: &Ui, tracks: &[TrackInfo<'_>], dragged: Option<ColumnWidth>, least: f32) -> HeaderColumns {
|
||||
let env = Env::of(ui);
|
||||
let (switch, pad) = (env.tokens.size.control.md, name_pad(&env.tokens));
|
||||
let switches =
|
||||
SWITCHES.iter().map(|(key, _, _)| key.clone()).filter(|key| tracks.iter().any(|track| switch_of(track, key).is_some())).collect();
|
||||
let dragged = dragged.and_then(|width| match width.in_unit(switch) {
|
||||
ColumnWidth::Fixed(width) => Some(width),
|
||||
_ => None,
|
||||
};
|
||||
let name = name.and_then(fixed).or_else(|| fixed(NAME_DEFAULT)).unwrap_or(0.0);
|
||||
let switches = SWITCHES.len() as f32 * fixed(SWITCH_WIDTH).unwrap_or(0.0);
|
||||
fixed(STRIP_WIDTH).unwrap_or(0.0) + name + switches
|
||||
});
|
||||
let name = dragged.unwrap_or_else(|| {
|
||||
tracks
|
||||
.iter()
|
||||
.map(|track| {
|
||||
let text = Text::new(track.name.to_owned()).role(NAME_ROLE).measure_in(ui, Proposal::Ideal).x;
|
||||
text + 2.0 * name_inset(pad, track)
|
||||
})
|
||||
.fold(0.0, f32::max)
|
||||
});
|
||||
let mut header = HeaderColumns { switches, name, switch };
|
||||
header.name += (least - header.extent()).max(0.0);
|
||||
header
|
||||
}
|
||||
|
||||
/// The colour strip's width.
|
||||
pub fn strip(&self) -> f32 {
|
||||
self.switch * STRIP_SHARE
|
||||
}
|
||||
|
||||
/// The width of the headers: the colour strip, the name and the switches. The lanes begin here.
|
||||
pub fn extent(&self) -> f32 {
|
||||
self.strip() + self.name + self.switches.len() as f32 * self.switch
|
||||
}
|
||||
}
|
||||
|
||||
/// The pad between the colour strip and the name, and the indent of one level of depth.
|
||||
fn name_pad(tokens: &UiTokens) -> f32 {
|
||||
tokens.space.pad.regular
|
||||
}
|
||||
|
||||
/// The inset of `track`'s name from each side of the name cell: one pad and its depth's indent.
|
||||
fn name_inset(pad: f32, track: &TrackInfo<'_>) -> f32 {
|
||||
pad * (1.0 + f32::from(track.depth))
|
||||
}
|
||||
|
||||
/// Whether `track`'s switch in `column` is on; `None` when the track has no such switch.
|
||||
fn switch_of(track: &TrackInfo<'_>, column: &ColumnKey) -> Option<bool> {
|
||||
if *column == LOCK {
|
||||
track.locked
|
||||
} else if *column == TARGET {
|
||||
track.targeted
|
||||
} else if *column == SYNC_LOCK {
|
||||
track.sync_lock
|
||||
} else if *column == OUTPUT {
|
||||
track.enabled
|
||||
} else if *column == MUTE {
|
||||
track.muted
|
||||
} else {
|
||||
track.solo
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,39 +232,11 @@ impl DisplayOrder<TrackId> for Tracks<'_> {
|
||||
|
||||
impl ItemSource<TrackId> for Tracks<'_> {
|
||||
fn toggled(&self, at: usize, column: &ColumnKey) -> bool {
|
||||
let track = &self.tracks[at];
|
||||
let on = if *column == LOCK {
|
||||
track.locked
|
||||
} else if *column == TARGET {
|
||||
track.targeted
|
||||
} else if *column == SYNC_LOCK {
|
||||
track.sync_lock
|
||||
} else if *column == OUTPUT {
|
||||
track.enabled
|
||||
} else if *column == MUTE {
|
||||
track.muted
|
||||
} else {
|
||||
track.solo
|
||||
};
|
||||
on.unwrap_or(false)
|
||||
switch_of(&self.tracks[at], column).unwrap_or(false)
|
||||
}
|
||||
|
||||
fn toggle_enabled(&self, at: usize, column: &ColumnKey) -> bool {
|
||||
let track = &self.tracks[at];
|
||||
let switch = if *column == LOCK {
|
||||
track.locked
|
||||
} else if *column == TARGET {
|
||||
track.targeted
|
||||
} else if *column == SYNC_LOCK {
|
||||
track.sync_lock
|
||||
} else if *column == OUTPUT {
|
||||
track.enabled
|
||||
} else if *column == MUTE {
|
||||
track.muted
|
||||
} else {
|
||||
track.solo
|
||||
};
|
||||
switch.is_some()
|
||||
switch_of(&self.tracks[at], column).is_some()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,8 +309,8 @@ pub struct TrackStack {
|
||||
}
|
||||
|
||||
impl TrackStack {
|
||||
/// A stack named `label` whose name column is `name` wide (the default until the user drags it).
|
||||
pub fn new(label: impl Into<Label>, name: Option<ColumnWidth>, words: &TimelineWords) -> Self {
|
||||
/// A stack named `label` with the header columns `header`: the same for every pane of a timeline.
|
||||
pub fn new(label: impl Into<Label>, header: &HeaderColumns, words: &TimelineWords) -> Self {
|
||||
let switch_name = |key: &ColumnKey| match () {
|
||||
_ if *key == LOCK => words.lock.clone(),
|
||||
_ if *key == TARGET => words.target.clone(),
|
||||
@@ -281,12 +320,12 @@ impl TrackStack {
|
||||
_ => words.solo.clone(),
|
||||
};
|
||||
let mut columns = vec![
|
||||
ColumnSpec::new(STRIP, words.track_color.clone(), STRIP_WIDTH),
|
||||
ColumnSpec::new(NAME, "", name.unwrap_or(NAME_DEFAULT)).resizable().frozen(),
|
||||
ColumnSpec::new(STRIP, words.track_color.clone(), ColumnWidth::Fixed(header.strip())),
|
||||
ColumnSpec::new(NAME, "", ColumnWidth::Fixed(header.name)).resizable().frozen(),
|
||||
];
|
||||
for (key, _, _) in SWITCHES {
|
||||
let header = switch_name(&key);
|
||||
columns.push(ColumnSpec::new(key, header, SWITCH_WIDTH).kind(ColumnKind::Toggle(ToggleColumn::sweepable())));
|
||||
for key in &header.switches {
|
||||
let name = switch_name(key);
|
||||
columns.push(ColumnSpec::new(key.clone(), name, ColumnWidth::Fixed(header.switch)).kind(ColumnKind::Toggle(ToggleColumn::sweepable())));
|
||||
}
|
||||
columns.push(ColumnSpec::new(LANE, "", ColumnWidth::fill(1.0)));
|
||||
TrackStack {
|
||||
@@ -464,11 +503,11 @@ impl Component for TrackRow<'_> {
|
||||
TrackRowStyle {
|
||||
surface: SurfaceLook::new(Stateful::new(cx.color(color.surface.panel))),
|
||||
metrics: Metrics::new(),
|
||||
name: TextLook::new(TypeRole::Caption, Stateful::new(cx.color(color.text.normal))),
|
||||
name: TextLook::new(NAME_ROLE, Stateful::new(cx.color(color.text.normal))),
|
||||
on: IconLook::new(cx.control().icon, Stateful::new(cx.color(color.text.normal))),
|
||||
off: IconLook::new(cx.control().icon, Stateful::new(cx.color(color.text.faint))),
|
||||
hover: cx.color(color.state.hover),
|
||||
pad: cx.tokens.space.pad.regular,
|
||||
pad: name_pad(cx.tokens),
|
||||
edge: cx.tokens.size.hit.target / 2.0,
|
||||
clip: ClipLook::of(cx),
|
||||
sizes: TrackSizes::of(cx.tokens),
|
||||
@@ -606,10 +645,9 @@ impl Component for TrackRow<'_> {
|
||||
}
|
||||
draw.edge_rule(RuleKind::Divider, headers, RectSide::Bottom);
|
||||
if let Some(cell) = self.cell(&NAME) {
|
||||
let indent = f32::from(self.track.depth) * style.pad;
|
||||
let flow = craft_behavior::Flow::new(cell, rtl);
|
||||
let text = flow.inset(craft_behavior::Insets::horizontal(style.pad + indent));
|
||||
draw.text(text, &craft_ui::primitives::TextRun::new(self.track.name).elide());
|
||||
let text = flow.inset(craft_behavior::Insets::horizontal(name_inset(style.pad, self.track)));
|
||||
draw.text(text, &craft_ui::primitives::TextRun::new(self.track.name).role(NAME_ROLE).elide());
|
||||
}
|
||||
for (key, on_icon, off_icon) in SWITCHES {
|
||||
let Some(cell) = self.cell(&key) else { continue };
|
||||
@@ -635,20 +673,7 @@ impl Component for TrackRow<'_> {
|
||||
impl TrackRow<'_> {
|
||||
/// Whether the track's switch in `column` is on; `None` when the track has no such switch.
|
||||
fn switch(&self, column: &ColumnKey) -> Option<bool> {
|
||||
let track = self.track;
|
||||
if *column == LOCK {
|
||||
track.locked
|
||||
} else if *column == TARGET {
|
||||
track.targeted
|
||||
} else if *column == SYNC_LOCK {
|
||||
track.sync_lock
|
||||
} else if *column == OUTPUT {
|
||||
track.enabled
|
||||
} else if *column == MUTE {
|
||||
track.muted
|
||||
} else {
|
||||
track.solo
|
||||
}
|
||||
switch_of(self.track, column)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Stories of `TrackStack`: no tracks, one track and many.
|
||||
|
||||
use super::{TrackRow, TrackStack, Tracks};
|
||||
use super::{HeaderColumns, TrackRow, TrackStack, Tracks};
|
||||
use crate::model::{TrackId, TrackInfo, TrackKind};
|
||||
use craft_ui::contract::CollectionEvent;
|
||||
use craft_ui::contract::ShowCollection as _;
|
||||
@@ -30,7 +30,8 @@ fn stack(ui: &mut Ui, names: &[&str]) -> StoryOutput {
|
||||
let words = Env::of(ui).words::<crate::ui::view::TimelineWords>();
|
||||
let source = Tracks::new(&tracks);
|
||||
let none: [crate::model::ClipInfo<'_>; 0] = [];
|
||||
let out = TrackStack::new("Tracks", None, &words).tracks(&tracks).show_items(ui, &source, &mut |key, icx| {
|
||||
let header = HeaderColumns::measure(ui, &tracks, None, 0.0);
|
||||
let out = TrackStack::new("Tracks", &header, &words).tracks(&tracks).show_items(ui, &source, &mut |key, icx| {
|
||||
let at = tracks.iter().position(|t| t.id == *key).unwrap_or(0);
|
||||
let lane = crate::ui::clips::ClipLane::new(&none);
|
||||
TrackRow::new(&tracks[at], icx.cells().to_vec(), lane, false, false)
|
||||
|
||||
@@ -214,11 +214,10 @@ impl<'a> TimecodeField<'a> {
|
||||
TimecodeField { common: Common::new(), value, format, min: Tick::ZERO, options }.label(label)
|
||||
}
|
||||
|
||||
/// The large readout: the prominent text role in the accent ink.
|
||||
/// The large readout: the timecode face in the accent ink. The face keeps every digit one width, so the field's
|
||||
/// widest time is its widest text and the readout holds still while the time runs.
|
||||
#[must_use]
|
||||
pub fn large(mut self) -> Self {
|
||||
self.options.mono = false;
|
||||
self.options.role = TypeRole::BodyLarge;
|
||||
self.options.ink = Some(Ink::Accent);
|
||||
self
|
||||
}
|
||||
@@ -255,8 +254,7 @@ impl Component for TimecodeField<'_> {
|
||||
fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 {
|
||||
let codec = self.codec();
|
||||
let sample = codec.sample(cx.value().unwrap_or(&Tick::ZERO));
|
||||
let role = if self.options.mono { TypeRole::Mono } else { self.options.role };
|
||||
cx.layout(&TextRun::new(sample.as_ref()).role(role)).size()
|
||||
cx.field_text(&TextRun::new(sample.as_ref()).role(TypeRole::Mono))
|
||||
}
|
||||
|
||||
fn parts(&mut self, _: Rect, cx: &mut PartsCx<'_, Self>) {
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
//! playhead, and shows the horizontal scroll bar as a scroll part over the view (a thumb end drag zooms).
|
||||
|
||||
use super::ruler::{SHIFT_STEP_FRAMES, STEP_FRAMES};
|
||||
use super::stack::TrackSizes;
|
||||
use crate::clock::{Follow, FollowMode};
|
||||
use crate::time::{Tick, TimeRange, TimeView, VIEW_EXTENT_PAST_END};
|
||||
use crate::timecode::TimeFormat;
|
||||
use craft_behavior::scroll::ScrollSpan;
|
||||
use craft_behavior::{Axis, ColumnWidth, EditEvent, Granularity, Intent, Metrics, Mixed, NavMove, PartKey, Sense, Wheel};
|
||||
use craft_behavior::{Axis, EditEvent, Granularity, Intent, Metrics, Mixed, NavMove, PartKey, Sense, Wheel};
|
||||
use craft_ui::contract::{
|
||||
Access, Bind, BindMut, CommandSet, Commands as _, Common, Component, Container, ContainerProps, Cx, Edit as _, EditResponse, Focus as _, Name,
|
||||
Outcome, PaintUi, PartsCx, Pointer as _, Props, Remember as _, Role, Sizing, THUMB, WordSetCx as _,
|
||||
@@ -194,8 +193,6 @@ pub struct TimelineViewStyle {
|
||||
#[style(metrics)]
|
||||
metrics: Metrics,
|
||||
look: ScrollBarLook,
|
||||
/// The sizes of the headers left of the time area.
|
||||
sizes: TrackSizes,
|
||||
/// The playhead's line over the panes.
|
||||
playhead: StyleColor,
|
||||
/// The line at the time a drag snapped to.
|
||||
@@ -251,13 +248,10 @@ pub struct TimelineView<'a> {
|
||||
view: Bind<'a, TimeView>,
|
||||
format: TimeFormat,
|
||||
end: Tick,
|
||||
/// The name column's width of the headers left of the time area; the headers take the default until the user drags
|
||||
/// it.
|
||||
#[prop(into)]
|
||||
header_width: Option<ColumnWidth>,
|
||||
/// Whether track headers sit left of the time area; the time area spans the whole width without them.
|
||||
#[prop]
|
||||
headers: bool,
|
||||
/// The width of the track headers left of the time area (`HeaderColumns::extent`); with none the time area spans the
|
||||
/// whole width.
|
||||
#[prop(quantity = "points")]
|
||||
header_extent: f32,
|
||||
follow: FollowMode,
|
||||
playing: bool,
|
||||
playhead: Tick,
|
||||
@@ -285,8 +279,7 @@ impl<'a> TimelineView<'a> {
|
||||
view,
|
||||
format,
|
||||
end,
|
||||
header_width: None,
|
||||
headers: false,
|
||||
header_extent: 0.0,
|
||||
follow: FollowMode::Page,
|
||||
playing: false,
|
||||
playhead: Tick::ZERO,
|
||||
@@ -317,13 +310,13 @@ impl<'a> TimelineView<'a> {
|
||||
}
|
||||
|
||||
/// The width of the time area in a view `rect` wide.
|
||||
fn width(&self, rect: Rect, style: &TimelineViewStyle) -> f32 {
|
||||
(rect.width() - self.inset(style)).max(0.0)
|
||||
fn width(&self, rect: Rect) -> f32 {
|
||||
(rect.width() - self.inset()).max(0.0)
|
||||
}
|
||||
|
||||
/// The width of the headers, left of the time area, along the start edge.
|
||||
fn inset(&self, style: &TimelineViewStyle) -> f32 {
|
||||
if self.headers { style.sizes.header_extent(self.header_width) } else { 0.0 }
|
||||
fn inset(&self) -> f32 {
|
||||
self.header_extent.max(0.0)
|
||||
}
|
||||
|
||||
/// The playhead moved to `to`: one `Set` event, as a key gives it.
|
||||
@@ -455,7 +448,6 @@ impl Component for TimelineView<'_> {
|
||||
TimelineViewStyle {
|
||||
metrics: Metrics::new(),
|
||||
look: cx.scroll_bar(ScrollBarKind::Docked),
|
||||
sizes: TrackSizes::of(cx.tokens),
|
||||
playhead: cx.color(cx.tokens.color.accent.solid),
|
||||
snap: cx.color(cx.tokens.color.overlay.line),
|
||||
marquee_fill: cx.color(cx.tokens.color.accent.soft),
|
||||
@@ -478,7 +470,7 @@ impl Component for TimelineView<'_> {
|
||||
return;
|
||||
}
|
||||
let Some(view) = cx.value().copied() else { return };
|
||||
let width = self.width(rect, cx.style);
|
||||
let width = self.width(rect);
|
||||
if !(view.points_per_second > 0.0 && view.points_per_second.is_finite() && width > 0.0) {
|
||||
return;
|
||||
}
|
||||
@@ -489,14 +481,14 @@ impl Component for TimelineView<'_> {
|
||||
fn update(&mut self, cx: &mut Cx<'_, Self>) {
|
||||
self.anim = *cx.memory::<Anim>();
|
||||
let Some(target) = cx.value().copied() else { return };
|
||||
let width = self.width(cx.rect, cx.style);
|
||||
let width = self.width(cx.rect);
|
||||
let valid = target.points_per_second > 0.0 && target.points_per_second.is_finite() && width > 0.0;
|
||||
if !valid {
|
||||
return;
|
||||
}
|
||||
let mut next = target;
|
||||
let pointer = cx.response.hover_pos().unwrap_or_else(|| cx.rect.center());
|
||||
let left = cx.flow.span(self.inset(cx.style), width).left();
|
||||
let left = cx.flow.span(self.inset(), width).left();
|
||||
if let Some(wheel) = cx.take_wheel() {
|
||||
// The wheel's own point: over a child (the ruler) the view itself has no hover.
|
||||
let pointer = wheel.at.unwrap_or(pointer);
|
||||
@@ -542,11 +534,11 @@ impl Component for TimelineView<'_> {
|
||||
if !self.full {
|
||||
return;
|
||||
}
|
||||
let span = cx.flow.span(self.inset(cx.style), self.width(cx.rect, cx.style));
|
||||
let span = cx.flow.span(self.inset(), self.width(cx.rect));
|
||||
let area = Rect::from_min_max(Pos2::new(span.left(), cx.rect.top()), Pos2::new(span.right(), cx.rect.bottom()));
|
||||
ui.draw().fill(&PaintShape::Rect(area, CornerRadius::ZERO), cx.style.well);
|
||||
let Some(view) = cx.value().copied() else { return };
|
||||
let width = self.width(cx.rect, cx.style);
|
||||
let width = self.width(cx.rect);
|
||||
if !(view.points_per_second > 0.0 && view.points_per_second.is_finite() && width > 0.0) {
|
||||
return;
|
||||
}
|
||||
@@ -579,7 +571,7 @@ impl Component for TimelineView<'_> {
|
||||
|
||||
fn access(&self, access: &mut Access, cx: &Cx<'_, Self>) {
|
||||
let Some(view) = cx.value().copied() else { return };
|
||||
let width = self.width(cx.rect, cx.style);
|
||||
let width = self.width(cx.rect);
|
||||
if !(view.points_per_second > 0.0 && view.points_per_second.is_finite() && width > 0.0) {
|
||||
return;
|
||||
}
|
||||
@@ -599,7 +591,7 @@ impl Component for TimelineView<'_> {
|
||||
impl TimelineView<'_> {
|
||||
/// The bar's rect: the bottom edge of `rect`, from the end of the headers to the end edge.
|
||||
fn bar(&self, rect: Rect, flow: craft_behavior::Flow, style: &TimelineViewStyle) -> Rect {
|
||||
let (inset, thickness) = (self.inset(style), style.look.thickness);
|
||||
let (inset, thickness) = (self.inset(), style.look.thickness);
|
||||
let span = flow.span(inset, (rect.width() - inset).max(0.0));
|
||||
Rect::from_min_max(Pos2::new(span.left(), rect.bottom() - thickness), Pos2::new(span.right(), rect.bottom()))
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! The track stack: resizing rows.
|
||||
//! The Timeline panel: resizing rows, and the headers, the ruler and the lanes on one time origin.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
@@ -6,6 +6,7 @@ use std::rc::Rc;
|
||||
use craft_timeline::ui::{Timeline, TimelineEdit};
|
||||
use craft_timeline::{ClipId, ClipInfo, TimeRange, TimelineModel, TrackId, TrackInfo};
|
||||
use craft_timeline::{FrameRate, Tick, TimeFormat, TimeView, TrackKind};
|
||||
use craft_ui::contract::Role;
|
||||
use craft_ui::testing::{Fixture, Target, trial};
|
||||
use egui::{Rect, Vec2};
|
||||
|
||||
@@ -22,6 +23,8 @@ const V2: TrackId = TrackId(2);
|
||||
const A1: TrackId = TrackId(3);
|
||||
/// The panel's room.
|
||||
const PANEL_ROOM: Vec2 = Vec2::new(900.0, 500.0);
|
||||
/// Where every clip of the sequence starts.
|
||||
const CLIP_START_SECONDS: f64 = 2.0;
|
||||
/// The time the panel's view shows per second of room.
|
||||
const PANEL_POINTS_PER_SECOND: f64 = 20.0;
|
||||
|
||||
@@ -77,7 +80,7 @@ impl TimelineModel for Sequence {
|
||||
let clip = |id: u64| ClipInfo {
|
||||
id: ClipId(id),
|
||||
track,
|
||||
range: TimeRange::from_bounds(secs(2.0), secs(6.0)),
|
||||
range: TimeRange::from_bounds(secs(CLIP_START_SECONDS), secs(6.0)),
|
||||
name: "Clip",
|
||||
label: None,
|
||||
enabled: !self.disabled.contains(&ClipId(id)),
|
||||
@@ -206,3 +209,29 @@ const RESIZE_TRAVEL: f32 = 10.0;
|
||||
|
||||
/// The rounding slack of a measured point.
|
||||
const SLACK: f32 = 0.5;
|
||||
|
||||
/// The ruler and the lanes share one time origin: the ruler starts where the lanes do and spans the time area, so a clip
|
||||
/// sits under its time on the ruler. The headers hold only the switches some track has: no track here has a sync lock.
|
||||
#[trial]
|
||||
fn the_ruler_starts_where_the_lanes_do_and_the_headers_hold_only_switches_some_track_has() {
|
||||
let panel = panel();
|
||||
let tree = panel.fixture.tree();
|
||||
let ruler = panel
|
||||
.fixture
|
||||
.by_role(Role::SLIDER)
|
||||
.into_iter()
|
||||
.find(|target| tree.name_of(target.node) == Some("Overview"))
|
||||
.expect("the ruler is a slider named Overview");
|
||||
assert!(ruler.rect.width() > PANEL_ROOM.x / 2.0, "the ruler spans the time area: {:?}", ruler.rect);
|
||||
let clip = panel.in_row("Clip", panel.row("V1"));
|
||||
let at = CLIP_START_SECONDS as f32 * PANEL_POINTS_PER_SECOND as f32;
|
||||
assert!(
|
||||
(clip.rect.left() - ruler.rect.left() - at).abs() < SLACK,
|
||||
"the clip at {CLIP_START_SECONDS} s sits {at} pt from the ruler's start: clip {:?}, ruler {:?}",
|
||||
clip.rect,
|
||||
ruler.rect
|
||||
);
|
||||
let named = |words: &str| tree.keys().into_iter().any(|key| tree.name_of(key).is_some_and(|name| name.contains(words)));
|
||||
assert!(named("Toggle track targeting"), "every track has a target switch");
|
||||
assert!(!named("Toggle Sync Lock"), "no track has a sync lock, so no header has its column");
|
||||
}
|
||||
|
||||
@@ -111,6 +111,13 @@ impl<C: Component> MeasureCx<'_, C> {
|
||||
run.layout(self.ui.ctx(), &env, width)
|
||||
}
|
||||
|
||||
/// The room an editable text in a control sized by its text needs for `run`: the laid-out text and the caret the
|
||||
/// editor draws past its last letter, so the caret stays inside the control and the text never scrolls.
|
||||
pub fn field_text(&self, run: &TextRun<'_>) -> Vec2 {
|
||||
let text = self.layout(run).size();
|
||||
Vec2::new(text.x + self.ui.visuals().text_cursor.stroke.width, text.y)
|
||||
}
|
||||
|
||||
/// Lays document `text` out `text.wrap` wide, as `ContentPainterCx::layout` will paint it: the galley a content
|
||||
/// painter's measure sizes its band by is the one its paint draws.
|
||||
pub fn layout_doc(&self, text: &crate::primitives::DocText<'_>) -> TextLayout {
|
||||
|
||||
@@ -63,9 +63,9 @@ impl BodyLayout {
|
||||
BodyLayout::Row { wrap: false, align: RowAlign::Start }
|
||||
}
|
||||
|
||||
/// Children row-major over `columns`.
|
||||
pub const fn grid(columns: &'static [ColumnWidth]) -> Self {
|
||||
BodyLayout::Grid { columns: Cow::Borrowed(columns) }
|
||||
/// Children row-major over `columns`: a `'static` slice, or columns built in the pass.
|
||||
pub fn grid(columns: impl Into<Cow<'static, [ColumnWidth]>>) -> Self {
|
||||
BodyLayout::Grid { columns: columns.into() }
|
||||
}
|
||||
|
||||
/// A `Row` that wraps; any other layout is unchanged.
|
||||
|
||||
@@ -121,7 +121,7 @@ impl Component for ComboBox<'_> {
|
||||
let current = cx.value().map_or("", String::as_str);
|
||||
let placeholder = self.placeholder.as_ref().map_or("", Label::as_str);
|
||||
let texts = self.options.iter().filter_map(|option| option.value().map(String::as_str)).chain([current, placeholder]);
|
||||
let widest = texts.map(|text| cx.layout(&TextRun::new(text)).size()).fold(Vec2::ZERO, Vec2::max);
|
||||
let widest = texts.map(|text| cx.field_text(&TextRun::new(text))).fold(Vec2::ZERO, Vec2::max);
|
||||
let name = cx.words::<PickerWords>().combo_options.clone();
|
||||
Vec2::new(widest.x + reserve(cx.style, &[], &Self::trailing(name)), widest.y)
|
||||
}
|
||||
|
||||
@@ -252,7 +252,7 @@ impl Component for DatePicker<'_> {
|
||||
use craft_behavior::Codec as _;
|
||||
let codec = self.codec(cx.env.dates(), false);
|
||||
let sample = codec.sample(&None);
|
||||
let text = cx.layout(&TextRun::new(sample.as_ref())).size();
|
||||
let text = cx.field_text(&TextRun::new(sample.as_ref()));
|
||||
let name = cx.words::<PickerWords>().date_pick.clone();
|
||||
Vec2::new(text.x + reserve(cx.style, &[], &Self::trailing(name)), text.y)
|
||||
}
|
||||
|
||||
@@ -368,15 +368,13 @@ impl<V: NumberValue + 'static> Component for NumberField<'_, V> {
|
||||
self.settle_lengths(&cx.env.units());
|
||||
let codec = self.ruled(&cx.env.units(), false, self.names(|row| cx.env.resolve(&row.label().clone())));
|
||||
// The number's room is one digit and the caret; a field sized to its range (`fit_range`) or to its content
|
||||
// (`Sizing::Content`) takes the widest value.
|
||||
// (`Sizing::Content`) takes the widest value and the caret.
|
||||
let content = cx.resolved.sizing() == Some(Sizing::Content);
|
||||
let caret = cx.ui.visuals().text_cursor.stroke.width;
|
||||
let text = if self.fit_range || content {
|
||||
let sample = cx.value().map_or(Cow::Borrowed(""), |value| codec.sample(value));
|
||||
cx.layout(&TextRun::new(sample.as_ref())).size()
|
||||
cx.field_text(&TextRun::new(sample.as_ref()))
|
||||
} else {
|
||||
let digit = cx.layout(&TextRun::new("0")).size();
|
||||
Vec2::new(digit.x + caret, digit.y)
|
||||
cx.field_text(&TextRun::new("0"))
|
||||
};
|
||||
self.leading = Self::before_text(cx);
|
||||
self.trailing = self.after_text(cx, &self.chevrons(&cx.words::<TextWords>()));
|
||||
|
||||
@@ -254,7 +254,7 @@ impl<C: Codec + Clone + 'static> Component for TextField<'_, C> {
|
||||
None => Cow::Borrowed(""),
|
||||
};
|
||||
let text = if sample.is_empty() { self.options.placeholder.as_ref().map_or("", Label::as_str) } else { sample.as_ref() };
|
||||
let mut size = cx.layout(&TextRun::new(text).role(self.options.role)).size();
|
||||
let mut size = cx.field_text(&TextRun::new(text).role(self.options.role));
|
||||
// A multi-line field takes the height of its lines, and grows past them with longer text, as the editor does.
|
||||
if let Some(lines) = self.options.lines.filter(|_| self.options.multiline()) {
|
||||
let line = cx.layout(&TextRun::new("M").role(self.options.role)).size().y;
|
||||
|
||||
@@ -1800,7 +1800,7 @@ The component traits, context types, `PaintUi`, `Looks`, the pipeline and its st
|
||||
- `craft_ui::contract::BodyLayout`: `pub enum BodyLayout { Stack, Row { wrap: bool, align: RowAlign }, Grid { columns: Cow<'static, [ColumnWidth]> } }`. How a body lays out its children, in reading order: mirrored under a right-to-left direction.
|
||||
- `pub const fn stack() -> Self`. Children one under another.
|
||||
- `pub const fn row() -> Self`. Children side by side from the start edge, with no wrap.
|
||||
- `pub const fn grid(columns: &'static [ColumnWidth]) -> Self`. Children row-major over `columns`.
|
||||
- `pub fn grid(columns: impl Into<Cow<'static, [ColumnWidth]>>) -> Self`. Children row-major over `columns`: a `'static` slice, or columns built in the pass.
|
||||
- `pub fn wrap(self, on: bool) -> Self`. A `Row` that wraps; any other layout is unchanged.
|
||||
- `pub fn align(self, align: RowAlign) -> Self`. A `Row` with `align`; any other layout is unchanged.
|
||||
- `craft_ui::contract::CellWidth`: `pub type CellWidth = ColumnWidth`. The width of a caption's cell.
|
||||
@@ -2103,6 +2103,7 @@ The component traits, context types, `PaintUi`, `Looks`, the pipeline and its st
|
||||
- `pub fn cell_width(&self, column: &craft_behavior::ColumnKey, width: f32)`. Reports, from the `Ideal` measure of a collection's item, the width its content in `column` takes unclipped,
|
||||
- `pub fn layout(&self, run: &TextRun<'_>) -> TextLayout`. Lays `run` out in the content's room, as `Draw::text` will paint it.
|
||||
- `pub fn layout_at(&self, run: &TextRun<'_>, width: f32) -> TextLayout`. Lays `run` out `width` wide, for a text that paints in a band narrower than the room.
|
||||
- `pub fn field_text(&self, run: &TextRun<'_>) -> Vec2`. The room an editable text in a control sized by its text needs for `run`: the laid-out text and the caret the
|
||||
- `pub fn layout_doc(&self, text: &crate::primitives::DocText<'_>) -> TextLayout`. Lays document `text` out `text.wrap` wide, as `ContentPainterCx::layout` will paint it: the galley a content
|
||||
- `pub fn child<D: Show>(&self, key: impl Hash + Debug, child: &mut D, proposal: Proposal) -> Vec2`. Measures a child under the composite's resolved `enabled` and `size`, as `PaintUi::child` will show it.
|
||||
- `pub fn labelled<D: Show>(&self, key: impl Hash + Debug, side: &crate::contract::SideLabel, child: &mut D, proposal: Proposal) -> Vec2`. Measures a child as `PaintUi::labelled` will show it with `side`: under the inside label `side` gives it
|
||||
@@ -2509,7 +2510,7 @@ The layout services: `LabelColumn`, `ColumnGroup`, the `Grid` cursor, `measure_s
|
||||
- `craft_ui::layout::BodyLayout`: `pub enum BodyLayout { Stack, Row { wrap: bool, align: RowAlign }, Grid { columns: Cow<'static, [ColumnWidth]> } }`. How a body lays out its children, in reading order: mirrored under a right-to-left direction.
|
||||
- `pub const fn stack() -> Self`. Children one under another.
|
||||
- `pub const fn row() -> Self`. Children side by side from the start edge, with no wrap.
|
||||
- `pub const fn grid(columns: &'static [ColumnWidth]) -> Self`. Children row-major over `columns`.
|
||||
- `pub fn grid(columns: impl Into<Cow<'static, [ColumnWidth]>>) -> Self`. Children row-major over `columns`: a `'static` slice, or columns built in the pass.
|
||||
- `pub fn wrap(self, on: bool) -> Self`. A `Row` that wraps; any other layout is unchanged.
|
||||
- `pub fn align(self, align: RowAlign) -> Self`. A `Row` with `align`; any other layout is unchanged.
|
||||
- `craft_ui::layout::ColumnGroup`: `pub struct ColumnGroup`. The widest content per column key of one scope, measured through the same `LayoutMemory` rule as a `Grid`
|
||||
|
||||
Reference in New Issue
Block a user