fix: apply style of header only for headers

This commit is contained in:
Cyrix126 2024-12-13 17:01:52 +01:00
parent e76c0f72fc
commit 07e3b49338

View file

@ -19,78 +19,80 @@ pub fn header_tab(
one_line_center: bool, one_line_center: bool,
) { ) {
check_header_element(logo.is_none(), links.is_empty(), subtitle.is_none()); check_header_element(logo.is_none(), links.is_empty(), subtitle.is_none());
ui.style_mut().wrap_mode = Some(TextWrapMode::Extend);
ui.style_mut().override_text_style = Some(TextStyle::Heading);
ui.add_space(SPACE); ui.add_space(SPACE);
if one_line_center { ui.scope(|ui| {
ui.style_mut().wrap_mode = Some(TextWrapMode::Extend);
ui.style_mut().override_text_style = Some(TextStyle::Heading);
ui.spacing_mut().item_spacing.x = 0.0; ui.spacing_mut().item_spacing.x = 0.0;
let height_logo = 64.0; if one_line_center {
let width_links = links let height_logo = 64.0;
.iter() let width_links = links
.map(|x| x.0.len() as f32 * ui.text_style_height(&TextStyle::Heading) / 2.0) .iter()
.collect::<Vec<f32>>(); .map(|x| x.0.len() as f32 * ui.text_style_height(&TextStyle::Heading) / 2.0)
let width_subtitle = subtitle.unwrap_or_default().len() as f32 .collect::<Vec<f32>>();
* ui.text_style_height(&TextStyle::Body) let width_subtitle = subtitle.unwrap_or_default().len() as f32
/ 2.0; * ui.text_style_height(&TextStyle::Body)
let nb_txt = links.len() + if subtitle.is_some() { 1 } else { 0 }; / 2.0;
// width of separator depends of width of ui and number of texts let nb_txt = links.len() + if subtitle.is_some() { 1 } else { 0 };
let width_separator = (ui.available_width() / ui.text_style_height(&TextStyle::Heading) // width of separator depends of width of ui and number of texts
* 4.0) let width_separator =
/ nb_txt as f32; (ui.available_width() / ui.text_style_height(&TextStyle::Heading) * 4.0)
// width available - logo and separator - total width of txt - separator for each text then divided by two / nb_txt as f32;
let border_width = (((ui.available_width() // width available - logo and separator - total width of txt - separator for each text then divided by two
- if logo.is_some() { let border_width = (((ui.available_width()
height_logo + width_separator - if logo.is_some() {
} else { height_logo + width_separator
0.0 } else {
} 0.0
- width_links.iter().sum::<f32>() }
- width_subtitle - width_links.iter().sum::<f32>()
- (nb_txt as f32 * width_separator)) - width_subtitle
+ width_separator) - (nb_txt as f32 * width_separator))
/ 2.0) + width_separator)
.max(0.0); / 2.0)
ui.horizontal(|ui| { .max(0.0);
ui.add_space(border_width); ui.horizontal(|ui| {
if let Some(logo) = logo { ui.add_space(border_width);
ui.add_sized([height_logo, height_logo], logo); if let Some(logo) = logo {
ui.add_sized( ui.add_sized([height_logo, height_logo], logo);
[width_separator, height_logo],
Separator::default().vertical().spacing(width_separator),
);
}
for (count, link) in links.iter().enumerate() {
ui.add_sized(
// [width_links[count], height_logo],
[0.0, height_logo],
Hyperlink::from_label_and_url(link.0, link.1),
);
if count != (links.len() - 1) || subtitle.is_some() {
ui.add_sized( ui.add_sized(
[0.0, height_logo], [0.0, height_logo],
Separator::default().vertical().spacing(width_separator), Separator::default().vertical().spacing(width_separator),
); );
} }
} for (count, link) in links.iter().enumerate() {
if let Some(desc) = subtitle { ui.add_sized(
ui.style_mut().override_text_style = Some(TextStyle::Body); [width_links[count], height_logo],
ui.add_sized([0.0, height_logo], Label::new(desc)); // [0.0, height_logo],
} Hyperlink::from_label_and_url(link.0, link.1),
}); );
} else { if count != (links.len() - 1) || subtitle.is_some() {
// top down ui.add_sized(
ui.vertical_centered(|ui| { [0.0, height_logo],
if let Some(source) = logo { Separator::default().vertical().spacing(width_separator),
ui.add(source); );
} }
for link in links { }
ui.hyperlink_to(link.0, link.1); if let Some(desc) = subtitle {
} ui.style_mut().override_text_style = Some(TextStyle::Body);
if let Some(desc) = subtitle { ui.add_sized([0.0, height_logo], Label::new(desc));
ui.style_mut().override_text_style = Some(TextStyle::Body); }
ui.label(desc); });
} } else {
}); // top down
} ui.vertical_centered(|ui| {
if let Some(source) = logo {
ui.add(source);
}
for link in links {
ui.hyperlink_to(link.0, link.1);
}
if let Some(desc) = subtitle {
ui.style_mut().override_text_style = Some(TextStyle::Body);
ui.label(desc);
}
});
}
});
ui.add_space(SPACE); ui.add_space(SPACE);
} }