Skip to content

Commit e473964

Browse files
committed
Improve menu bar diffing
1 parent f567d15 commit e473964

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

editor/src/messages/layout/utility_types/layout_widget.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,13 +484,19 @@ impl LayoutGroup {
484484
}
485485
}
486486

487-
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, specta::Type)]
487+
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, specta::Type)]
488488
pub struct WidgetHolder {
489489
#[serde(rename = "widgetId")]
490490
pub widget_id: WidgetId,
491491
pub widget: Widget,
492492
}
493493

494+
impl PartialEq for WidgetHolder {
495+
fn eq(&self, other: &Self) -> bool {
496+
self.widget == other.widget
497+
}
498+
}
499+
494500
impl WidgetHolder {
495501
#[deprecated(since = "0.0.0", note = "Please use the builder pattern, e.g. TextLabel::new(\"hello\").widget_holder()")]
496502
pub fn new(widget: Widget) -> Self {
@@ -502,6 +508,26 @@ impl WidgetHolder {
502508

503509
/// Diffing updates self (where self is old) based on new, updating the list of modifications as it does so.
504510
pub fn diff(&mut self, new: Self, widget_path: &mut [usize], widget_diffs: &mut Vec<WidgetDiff>) {
511+
if let (Widget::PopoverButton(button1), Widget::PopoverButton(button2)) = (&mut self.widget, &new.widget) {
512+
if button1.disabled == button2.disabled
513+
&& button1.style == button2.style
514+
&& button1.menu_direction == button2.menu_direction
515+
&& button1.icon == button2.icon
516+
&& button1.tooltip == button2.tooltip
517+
&& button1.tooltip_shortcut == button2.tooltip_shortcut
518+
&& button1.popover_min_width == button2.popover_min_width
519+
{
520+
let mut new_widget_path = widget_path.to_vec();
521+
for (i, (a, b)) in button1.popover_layout.iter_mut().zip(button2.popover_layout.iter()).enumerate() {
522+
new_widget_path.push(i);
523+
a.diff(b.clone(), &mut new_widget_path, widget_diffs);
524+
new_widget_path.pop();
525+
}
526+
self.widget = new.widget;
527+
return;
528+
}
529+
}
530+
505531
// If there have been changes to the actual widget (not just the id)
506532
if self.widget != new.widget {
507533
// We should update to the new widget value as well as a new widget id

editor/src/messages/layout/utility_types/widgets/input_widgets.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub struct CheckboxInput {
1919
pub tooltip: String,
2020

2121
#[serde(rename = "forLabel")]
22+
#[derivative(Debug = "ignore", PartialEq = "ignore")]
2223
pub for_label: CheckboxId,
2324

2425
#[serde(skip)]

editor/src/messages/layout/utility_types/widgets/label_widgets.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ pub enum SeparatorType {
3636
Section,
3737
}
3838

39-
#[derive(Clone, serde::Serialize, serde::Deserialize, Derivative, Debug, PartialEq, Eq, Default, WidgetBuilder, specta::Type)]
39+
#[derive(Clone, serde::Serialize, serde::Deserialize, Derivative, Debug, Eq, Default, WidgetBuilder, specta::Type)]
40+
#[derivative(PartialEq)]
4041
pub struct TextLabel {
4142
pub disabled: bool,
4243

@@ -62,6 +63,7 @@ pub struct TextLabel {
6263
pub tooltip: String,
6364

6465
#[serde(rename = "forCheckbox")]
66+
#[derivative(PartialEq = "ignore")]
6567
pub for_checkbox: CheckboxId,
6668

6769
// Body

0 commit comments

Comments
 (0)