fix: do not publish ResponsiveMenuBar messages in a loop

This commit is contained in:
Hojjat 2026-08-05 12:14:55 -06:00 • committed by Ashley Wulber
parent 31ec448bf0
commit 1421337831

View file

@ -180,13 +180,21 @@ where
let state = tree.state.downcast_mut::<State>(); let state = tree.state.downcast_mut::<State>();
if state.needs_update { if state.needs_update {
shell.publish((self.on_action)( // `needs_update` stays set while the content cannot fit, don't publish messages in a
crate::surface::Action::ResponsiveMenuBar { // busy loop
menu_bar: self.id.clone(), let announcement = (state.limits, state.size);
limits: state.limits,
size: state.size, if state.announced != Some(announcement) {
}, state.announced = Some(announcement);
)); shell.publish((self.on_action)(
crate::surface::Action::ResponsiveMenuBar {
menu_bar: self.id.clone(),
limits: announcement.0,
size: announcement.1,
},
));
}
state.needs_update = false; state.needs_update = false;
} }
@ -328,6 +336,8 @@ struct State {
limits: Limits, limits: Limits,
size: Size, size: Size,
needs_update: bool, needs_update: bool,
/// The `(limits, size)` last announced, so an unsatisfiable layout does not announce forever
announced: Option<(Limits, Size)>,
} }
impl State { impl State {
@ -336,6 +346,7 @@ impl State {
limits: Limits::NONE, limits: Limits::NONE,
size: Size::new(0., 0.), size: Size::new(0., 0.),
needs_update: false, needs_update: false,
announced: None,
} }
} }
} }