Skip to content

Commit f4ae5fe

Browse files
committed
improved ui performance
1 parent 37ea660 commit f4ae5fe

File tree

5 files changed

+41
-15
lines changed

5 files changed

+41
-15
lines changed

fyrox-ui/src/control.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use crate::{
2828
};
2929
use fyrox_core::define_as_any_trait;
3030

31+
use fyrox_core::algebra::Matrix3;
3132
use std::{
3233
any::Any,
3334
ops::{Deref, DerefMut},
@@ -266,7 +267,12 @@ pub trait Control:
266267
/// for [`DrawingContext`] for more info.
267268
fn draw(&self, #[allow(unused_variables)] drawing_context: &mut DrawingContext) {}
268269

269-
fn on_visual_transform_changed(&self) {}
270+
fn on_visual_transform_changed(
271+
&self,
272+
#[allow(unused_variables)] old_transform: &Matrix3<f32>,
273+
#[allow(unused_variables)] new_transform: &Matrix3<f32>,
274+
) {
275+
}
270276

271277
/// The same as [`Self::draw`], but it runs after all descendant widgets are rendered.
272278
fn post_draw(&self, #[allow(unused_variables)] drawing_context: &mut DrawingContext) {}

fyrox-ui/src/inspector/editors/texture_slice.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,13 @@ impl Control for TextureSliceEditorWindow {
559559
self.window.draw(drawing_context)
560560
}
561561

562-
fn on_visual_transform_changed(&self) {
563-
self.window.on_visual_transform_changed()
562+
fn on_visual_transform_changed(
563+
&self,
564+
old_transform: &Matrix3<f32>,
565+
new_transform: &Matrix3<f32>,
566+
) {
567+
self.window
568+
.on_visual_transform_changed(old_transform, new_transform)
564569
}
565570

566571
fn post_draw(&self, drawing_context: &mut DrawingContext) {

fyrox-ui/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,8 +1214,9 @@ impl UserInterface {
12141214
layout_transform * widget.render_transform
12151215
};
12161216

1217-
widget.visual_transform = visual_transform;
1218-
widget.on_visual_transform_changed();
1217+
let old_transform =
1218+
std::mem::replace(&mut widget.visual_transform, visual_transform);
1219+
widget.on_visual_transform_changed(&old_transform, &visual_transform);
12191220
}
12201221
}
12211222
}

fyrox-ui/src/text.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use crate::{
4141
BuildContext, Control, HorizontalAlignment, UiNode, UserInterface, VerticalAlignment,
4242
};
4343

44+
use fyrox_core::algebra::Matrix3;
4445
use fyrox_graph::constructor::{ConstructorProvider, GraphNodeConstructor};
4546
use std::{
4647
cell::RefCell,
@@ -375,11 +376,17 @@ impl Control for Text {
375376
);
376377
}
377378

378-
fn on_visual_transform_changed(&self) {
379-
self.formatted_text
380-
.borrow_mut()
381-
.set_super_sampling_scale(self.visual_max_scaling())
382-
.build();
379+
fn on_visual_transform_changed(
380+
&self,
381+
old_transform: &Matrix3<f32>,
382+
new_transform: &Matrix3<f32>,
383+
) {
384+
if old_transform != new_transform {
385+
self.formatted_text
386+
.borrow_mut()
387+
.set_super_sampling_scale(self.visual_max_scaling())
388+
.build();
389+
}
383390
}
384391

385392
fn handle_routed_message(&mut self, ui: &mut UserInterface, message: &mut UiMessage) {

fyrox-ui/src/text_box.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ use crate::{
4848
};
4949
use copypasta::ClipboardProvider;
5050

51+
use fyrox_core::algebra::Matrix3;
5152
use fyrox_core::some_or_return;
5253
use fyrox_graph::constructor::{ConstructorProvider, GraphNodeConstructor};
5354
use std::{
@@ -952,11 +953,17 @@ impl Control for TextBox {
952953
.build()
953954
}
954955

955-
fn on_visual_transform_changed(&self) {
956-
self.formatted_text
957-
.borrow_mut()
958-
.set_super_sampling_scale(self.visual_max_scaling())
959-
.build();
956+
fn on_visual_transform_changed(
957+
&self,
958+
old_transform: &Matrix3<f32>,
959+
new_transform: &Matrix3<f32>,
960+
) {
961+
if old_transform != new_transform {
962+
self.formatted_text
963+
.borrow_mut()
964+
.set_super_sampling_scale(self.visual_max_scaling())
965+
.build();
966+
}
960967
}
961968

962969
fn draw(&self, drawing_context: &mut DrawingContext) {

0 commit comments

Comments
 (0)