Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 36 additions & 11 deletions apps/desktop-gpui/src/editor_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,25 @@ pub enum GradeSlider {
}

impl GradeSlider {
/// Whether this slider writes a field
/// [`crate::editor_timeline::TimelineModel::build`] or
/// [`crate::editor_timeline::TrackLanes::from_project`] reads. The match
/// is exhaustive so a new slider has to make the choice explicitly.
pub(crate) fn changes_timeline_model(self) -> bool {
match self {
Self::Grain
| Self::Intensity
| Self::Exposure
| Self::Contrast
| Self::Saturation
| Self::Temperature
| Self::Tint
| Self::Fade
| Self::SplitTone
| Self::Vignette => false,
}
}

/// The nine rows inside "Fine-tune colors", in order.
pub const ADJUST: [GradeSlider; 9] = [
Self::Intensity,
Expand Down Expand Up @@ -492,17 +511,23 @@ impl EditorWindow {
window: &mut Window,
cx: &mut Context<Self>,
) {
self.edit_project("grade", window, cx, move |project| {
let grade = Self::grade_mut(project, target);
if (slider.read(grade) - value).abs() < f32::EPSILON {
return false;
}
slider.write(grade, value);
if !slider.keeps_preset() {
grade.preset = PRESET_CUSTOM.to_string();
}
true
});
self.edit_project_with_rebuild(
slider.changes_timeline_model(),
"grade",
window,
cx,
move |project| {
let grade = Self::grade_mut(project, target);
if (slider.read(grade) - value).abs() < f32::EPSILON {
return false;
}
slider.write(grade, value);
if !slider.keeps_preset() {
grade.preset = PRESET_CUSTOM.to_string();
}
true
},
);
}

fn preset_image(index: usize) -> Option<Arc<RenderImage>> {
Expand Down
91 changes: 88 additions & 3 deletions apps/desktop-gpui/src/editor_sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,31 @@ pub enum BgSlider {
}

impl BgSlider {
/// Whether this slider writes a field
/// [`crate::editor_timeline::TimelineModel::build`] or
/// [`crate::editor_timeline::TrackLanes::from_project`] reads. The match
/// is exhaustive so a new slider has to make the choice explicitly.
pub(crate) fn changes_timeline_model(self) -> bool {
match self {
Self::Blur
| Self::Padding
| Self::Rounding
| Self::MotionBlur
| Self::BorderWidth
| Self::BorderOpacity
| Self::NotchWidth
| Self::NotchHeight
| Self::NotchX
| Self::Shadow
| Self::ShadowSize
| Self::ShadowOpacity
| Self::ShadowBlur
| Self::GradientAngle
| Self::GradientNoise
| Self::GradientGrain => false,
}
}

/// `minValue` / `maxValue` / `step`, per call site. `NotchX`'s maximum is
/// `notchXMax()` and therefore not constant; it is patched in by
/// [`EditorWindow::slider_limits`].
Expand Down Expand Up @@ -1061,6 +1086,32 @@ impl EditorWindow {
change: impl FnOnce(&mut ProjectConfiguration) -> bool,
window: &mut Window,
cx: &mut Context<Self>,
) {
self.edit_background_inner(true, reason, change, window, cx);
}

/// [`Self::edit_background`] for edits that cannot change the timeline
/// model or its lanes -- the background tab's sliders and the
/// animated-gradient add/remove/stop/reset edits, whose fields
/// [`crate::editor_timeline::TimelineModel::build`] and
/// [`crate::editor_timeline::TrackLanes::from_project`] do not read.
fn edit_background_without_timeline(
&mut self,
reason: &'static str,
change: impl FnOnce(&mut ProjectConfiguration) -> bool,
window: &mut Window,
cx: &mut Context<Self>,
) {
self.edit_background_inner(false, reason, change, window, cx);
}

fn edit_background_inner(
&mut self,
rebuild_timeline: bool,
reason: &'static str,
change: impl FnOnce(&mut ProjectConfiguration) -> bool,
window: &mut Window,
cx: &mut Context<Self>,
) {
if !self.project_ready() {
return;
Expand All @@ -1076,7 +1127,11 @@ impl EditorWindow {
if !self.apply_control_change(change) {
return;
}
self.project_changed(window, cx);
if rebuild_timeline {
self.project_changed(window, cx);
} else {
self.project_changed_without_timeline(window, cx);
}
self.remember_animated_gradient_selection(previous_animated_gradient, window, cx);
self.note_sidebar_edit(reason);
}
Expand All @@ -1091,6 +1146,31 @@ impl EditorWindow {
window: &mut Window,
cx: &mut Context<Self>,
change: impl FnOnce(&mut ProjectConfiguration) -> bool,
) {
self.edit_project_with_rebuild(true, reason, window, cx, change);
}

/// [`Self::edit_project`] for edits that cannot change the timeline model.
pub(crate) fn edit_project_without_timeline(
&mut self,
reason: &'static str,
window: &mut Window,
cx: &mut Context<Self>,
change: impl FnOnce(&mut ProjectConfiguration) -> bool,
) {
self.edit_project_with_rebuild(false, reason, window, cx, change);
}

/// The shared project write. `rebuild_timeline` is true for edits that
/// touch a field [`crate::editor_timeline::TimelineModel::build`] or
/// [`crate::editor_timeline::TrackLanes::from_project`] reads.
pub(crate) fn edit_project_with_rebuild(
&mut self,
rebuild_timeline: bool,
reason: &'static str,
window: &mut Window,
cx: &mut Context<Self>,
change: impl FnOnce(&mut ProjectConfiguration) -> bool,
) {
if !self.project_ready() {
return;
Expand All @@ -1099,7 +1179,11 @@ impl EditorWindow {
if !self.apply_control_change(change) {
return;
}
self.project_changed(window, cx);
if rebuild_timeline {
self.project_changed(window, cx);
} else {
self.project_changed_without_timeline(window, cx);
}
self.note_project_edit(reason);
}

Expand Down Expand Up @@ -1345,7 +1429,8 @@ impl EditorWindow {
cx: &mut Context<Self>,
) {
let base = self.notch_base();
self.edit_background(
self.edit_background_inner(
slider.changes_timeline_model(),
"slider",
|project| {
let background = &mut project.background;
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-gpui/src/editor_sidebar/animated_gradient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ impl EditorWindow {
window: &mut Window,
cx: &mut Context<Self>,
) {
self.edit_background(
self.edit_background_without_timeline(
"animated-gradient-setting",
|project| match &mut project.background.source {
BackgroundSource::AnimatedGradient { config } => change(config),
Expand Down
Loading
Loading