Skip to content

Commit

Permalink
label reset layout if font changed
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhou121 committed Sep 1, 2023
1 parent d891dd6 commit 11ed15c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,22 @@ pub trait View {
}

cx.save();
let style = cx.app_state_mut().get_computed_style(self.id()).clone();
if style.font_size.is_some() {
cx.font_size = style.font_size;
}
if style.font_family.is_some() {
cx.font_family = style.font_family;
}
if style.font_weight.is_some() {
cx.font_weight = style.font_weight;
}
if style.font_style.is_some() {
cx.font_style = style.font_style;
}
if style.line_height.is_some() {
cx.line_height = style.line_height;
}

let layout = cx
.app_state()
Expand Down
13 changes: 13 additions & 0 deletions src/views/label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ impl View for Label {
self.font_style = cx.font_style;
self.line_height = cx.line_height;
self.text_overflow = text_overflow;
self.text_layout = None;
self.available_text = None;
self.available_width = None;
self.available_text_layout = None;
self.set_text_layout();
}
if self.text_layout.is_none() {
Expand Down Expand Up @@ -212,6 +216,15 @@ impl View for Label {
return None;
}

if self.font_size != cx.font_size
|| self.font_family.as_deref() != cx.current_font_family()
|| self.font_weight != cx.font_weight
|| self.font_style != cx.font_style
|| self.line_height != cx.line_height
{
cx.app_state_mut().request_layout(self.id());
}

let layout = cx.get_layout(self.id()).unwrap();
let style = cx.app_state_mut().get_computed_style(self.id);
let text_overflow = style.text_overflow;
Expand Down

0 comments on commit 11ed15c

Please sign in to comment.