mirror of
https://github.com/Cyrix126/gupaxx.git
synced 2024-12-22 06:39:21 +00:00
fix: apply style of header only for headers
This commit is contained in:
parent
e76c0f72fc
commit
07e3b49338
1 changed files with 68 additions and 66 deletions
|
@ -19,78 +19,80 @@ pub fn header_tab(
|
|||
one_line_center: bool,
|
||||
) {
|
||||
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);
|
||||
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;
|
||||
let height_logo = 64.0;
|
||||
let width_links = links
|
||||
.iter()
|
||||
.map(|x| x.0.len() as f32 * ui.text_style_height(&TextStyle::Heading) / 2.0)
|
||||
.collect::<Vec<f32>>();
|
||||
let width_subtitle = subtitle.unwrap_or_default().len() as f32
|
||||
* ui.text_style_height(&TextStyle::Body)
|
||||
/ 2.0;
|
||||
let nb_txt = links.len() + if subtitle.is_some() { 1 } else { 0 };
|
||||
// width of separator depends of width of ui and number of texts
|
||||
let width_separator = (ui.available_width() / ui.text_style_height(&TextStyle::Heading)
|
||||
* 4.0)
|
||||
/ nb_txt as f32;
|
||||
// width available - logo and separator - total width of txt - separator for each text then divided by two
|
||||
let border_width = (((ui.available_width()
|
||||
- if logo.is_some() {
|
||||
height_logo + width_separator
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
- width_links.iter().sum::<f32>()
|
||||
- width_subtitle
|
||||
- (nb_txt as f32 * width_separator))
|
||||
+ width_separator)
|
||||
/ 2.0)
|
||||
.max(0.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(border_width);
|
||||
if let Some(logo) = logo {
|
||||
ui.add_sized([height_logo, height_logo], logo);
|
||||
ui.add_sized(
|
||||
[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() {
|
||||
if one_line_center {
|
||||
let height_logo = 64.0;
|
||||
let width_links = links
|
||||
.iter()
|
||||
.map(|x| x.0.len() as f32 * ui.text_style_height(&TextStyle::Heading) / 2.0)
|
||||
.collect::<Vec<f32>>();
|
||||
let width_subtitle = subtitle.unwrap_or_default().len() as f32
|
||||
* ui.text_style_height(&TextStyle::Body)
|
||||
/ 2.0;
|
||||
let nb_txt = links.len() + if subtitle.is_some() { 1 } else { 0 };
|
||||
// width of separator depends of width of ui and number of texts
|
||||
let width_separator =
|
||||
(ui.available_width() / ui.text_style_height(&TextStyle::Heading) * 4.0)
|
||||
/ nb_txt as f32;
|
||||
// width available - logo and separator - total width of txt - separator for each text then divided by two
|
||||
let border_width = (((ui.available_width()
|
||||
- if logo.is_some() {
|
||||
height_logo + width_separator
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
- width_links.iter().sum::<f32>()
|
||||
- width_subtitle
|
||||
- (nb_txt as f32 * width_separator))
|
||||
+ width_separator)
|
||||
/ 2.0)
|
||||
.max(0.0);
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_space(border_width);
|
||||
if let Some(logo) = logo {
|
||||
ui.add_sized([height_logo, height_logo], logo);
|
||||
ui.add_sized(
|
||||
[0.0, height_logo],
|
||||
Separator::default().vertical().spacing(width_separator),
|
||||
);
|
||||
}
|
||||
}
|
||||
if let Some(desc) = subtitle {
|
||||
ui.style_mut().override_text_style = Some(TextStyle::Body);
|
||||
ui.add_sized([0.0, height_logo], Label::new(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);
|
||||
}
|
||||
});
|
||||
}
|
||||
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(
|
||||
[0.0, height_logo],
|
||||
Separator::default().vertical().spacing(width_separator),
|
||||
);
|
||||
}
|
||||
}
|
||||
if let Some(desc) = subtitle {
|
||||
ui.style_mut().override_text_style = Some(TextStyle::Body);
|
||||
ui.add_sized([0.0, height_logo], Label::new(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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue