Skip to content

Commit

Permalink
BuildContext::send_message
Browse files Browse the repository at this point in the history
  • Loading branch information
mrDIMAS committed Dec 26, 2024
1 parent 8f002d3 commit e58a118
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 53 deletions.
12 changes: 5 additions & 7 deletions editor/src/menu/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,11 @@ impl CreateEntityMenu {
root_items.push(group);
group
});
ctx.sender()
.send(MenuItemMessage::add_item(
group,
MessageDirection::ToWidget,
item,
))
.unwrap()
ctx.send_message(MenuItemMessage::add_item(
group,
MessageDirection::ToWidget,
item,
))
}
}
}
Expand Down
22 changes: 10 additions & 12 deletions editor/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,16 @@ impl StatisticsWindow {
.with_title(WindowTitle::text("Rendering Statistics"))
.build(ctx);

ctx.sender()
.send(WindowMessage::open_and_align(
window,
MessageDirection::ToWidget,
anchor,
HorizontalAlignment::Right,
VerticalAlignment::Top,
Thickness::uniform(2.0),
false,
false,
))
.unwrap();
ctx.send_message(WindowMessage::open_and_align(
window,
MessageDirection::ToWidget,
anchor,
HorizontalAlignment::Right,
VerticalAlignment::Top,
Thickness::uniform(2.0),
false,
false,
));

Self { window, text }
}
Expand Down
9 changes: 9 additions & 0 deletions fyrox-ui/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,13 @@ impl BuildContext<'_> {
pub fn inner_mut(&mut self) -> &mut UserInterface {
self.ui
}

/// Sends a message during build stage. It has quite limited use, but could be unavoidable in
/// for cases when you need to do some action that relies on fully performed layout stage. When a
/// widget is being built, you can't fetch any layout info of it since it wasn't calculated yet.
/// In this case all you can do is to "postpone" your action for later moment in current frame
/// by sending a message.
pub fn send_message(&self, message: UiMessage) {
self.ui.send_message(message);
}
}
6 changes: 2 additions & 4 deletions fyrox-ui/src/inspector/editors/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,11 @@ impl PropertyEditorDefinition for CurvePropertyEditorDefinition {
.with_curves(vec![value.clone()])
.build(ctx.build_context);
ctx.build_context
.sender()
.send(CurveEditorMessage::zoom_to_fit(
.send_message(CurveEditorMessage::zoom_to_fit(
editor,
MessageDirection::ToWidget,
true,
))
.unwrap();
));
Ok(PropertyEditorInstance::Simple { editor })
}

Expand Down
10 changes: 4 additions & 6 deletions project-manager/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,12 +613,10 @@ impl ProjectManager {
.add_column(Column::stretch())
.build(ctx);

ctx.sender()
.send(WidgetMessage::focus(
navigation_layer,
MessageDirection::ToWidget,
))
.unwrap();
ctx.send_message(WidgetMessage::focus(
navigation_layer,
MessageDirection::ToWidget,
));

Self {
root_grid,
Expand Down
14 changes: 6 additions & 8 deletions project-manager/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,12 @@ impl ProjectWizard {
.with_title(WindowTitle::text("Project Wizard"))
.build(ctx);

ctx.sender()
.send(WindowMessage::open_modal(
window,
MessageDirection::ToWidget,
true,
true,
))
.unwrap();
ctx.send_message(WindowMessage::open_modal(
window,
MessageDirection::ToWidget,
true,
true,
));

Self {
window,
Expand Down
14 changes: 6 additions & 8 deletions project-manager/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,12 @@ impl SettingsWindow {
.with_remove_on_close(true)
.build(ctx);

ctx.sender()
.send(WindowMessage::open_modal(
window,
MessageDirection::ToWidget,
true,
true,
))
.unwrap();
ctx.send_message(WindowMessage::open_modal(
window,
MessageDirection::ToWidget,
true,
true,
));

Self { window, inspector }
}
Expand Down
14 changes: 6 additions & 8 deletions project-manager/src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,12 @@ impl UpgradeTool {
.with_remove_on_close(true)
.build(ctx);

ctx.sender()
.send(WindowMessage::open_modal(
window,
MessageDirection::ToWidget,
true,
true,
))
.unwrap();
ctx.send_message(WindowMessage::open_modal(
window,
MessageDirection::ToWidget,
true,
true,
));

Self {
window,
Expand Down

0 comments on commit e58a118

Please sign in to comment.