Skip to content

Commit

Permalink
fixed blurry fonts for newly created text widgets when hi-dpi is used
Browse files Browse the repository at this point in the history
  • Loading branch information
mrDIMAS committed Dec 19, 2024
1 parent 6803b29 commit 5fc5a3f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fyrox-ui/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ pub trait Control:
/// for [`DrawingContext`] for more info.
fn draw(&self, #[allow(unused_variables)] drawing_context: &mut DrawingContext) {}

fn on_visual_transform_changed(&self) {}

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

Expand Down
1 change: 1 addition & 0 deletions fyrox-ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,7 @@ impl UserInterface {
};

widget.visual_transform = visual_transform;
widget.on_visual_transform_changed();
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions fyrox-ui/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,13 @@ impl Control for Text {
);
}

fn on_visual_transform_changed(&self) {
self.formatted_text
.borrow_mut()
.set_super_sampling_scale(self.visual_max_scaling())
.build();
}

fn handle_routed_message(&mut self, ui: &mut UserInterface, message: &mut UiMessage) {
self.widget.handle_routed_message(ui, message);

Expand Down
7 changes: 7 additions & 0 deletions fyrox-ui/src/text_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,13 @@ impl Control for TextBox {
.build()
}

fn on_visual_transform_changed(&self) {
self.formatted_text
.borrow_mut()
.set_super_sampling_scale(self.visual_max_scaling())
.build();
}

fn draw(&self, drawing_context: &mut DrawingContext) {
let bounds = self.widget.bounding_rect();
drawing_context.push_rect_filled(&bounds, None);
Expand Down

0 comments on commit 5fc5a3f

Please sign in to comment.