/// Returns this `Value` with the specified `font_style`.
pub fn with_font_style(mut self, font_style: FontStyle) -> Self {
- self.styling_mut().font_style = Some(font_style);
+ self.set_font_style(font_style);
self
}
+ /// Sets the `Value`'s font style.
+ pub fn set_font_style(&mut self, font_style: FontStyle) {
+ self.styling_mut().font_style = Some(font_style);
+ }
+
/// Returns this `Value` with the specified `cell_style`.
pub fn with_cell_style(mut self, cell_style: CellStyle) -> Self {
- self.styling_mut().cell_style = Some(cell_style);
+ self.set_cell_style(cell_style);
self
}
+ /// Sets the `Value`'s cell style.
+ pub fn set_cell_style(&mut self, cell_style: CellStyle) {
+ self.styling_mut().cell_style = Some(cell_style);
+ }
+
/// Returns this `Value` with the specified `styling`.
pub fn with_styling(self, styling: Option<Box<ValueStyle>>) -> Self {
Self { styling, ..self }
dims: &mut Vec<Dim<'a>>,
) {
let base_level = variables[0].1;
- let (show_label, dimension_style) = if let Ok(a) = Axis2::try_from(a)
+ let (show_label, dim_cell, dim_font) = if let Ok(a) = Axis2::try_from(a)
&& let Some(axis) = axes.get(&(base_level + variables.len()))
&& let Some(label) = &axis.label
{
let mut dimension_style = AreaStyle::default_for_area(Area::Labels(a));
let style = label.style.get(&styles);
- Style::decode_area(
- style,
- label.text_frame_style.as_ref().and_then(|r| r.get(styles)),
- &mut dimension_style,
- );
+ let fg = style;
+ let bg = label.text_frame_style.as_ref().and_then(|r| r.get(styles));
(
style.is_some_and(|s| s.visible.unwrap_or(true)),
- Some(dimension_style),
+ Style::decode_cell_style(fg, &mut dimension_style.cell_style)
+ .then_some(dimension_style.cell_style),
+ Style::decode_font_style(fg, bg, &mut dimension_style.font_style)
+ .then_some(dimension_style.font_style),
)
} else {
- (false, None)
+ (false, None, None)
};
if let Ok(a) = Axis2::try_from(a)
&& let Some(axis) = axes.get(&(base_level + variables.len() - 1))
cats = next_cats;
}
- let dimension_label = variables[0]
+ let mut dimension_label = variables[0]
.label
.as_ref()
.map_or_else(|| Value::new_empty(), |label| Value::new_user_text(label));
- let dimension_label = if let Some(style) = dimension_style {
- dimension_label
- .with_cell_style(style.cell_style)
- .with_font_style(style.font_style)
- } else {
- dimension_label
- };
+ if let Some(dim_cell) = dim_cell {
+ dimension_label.set_cell_style(dim_cell);
+ }
+ if let Some(dim_font) = dim_font {
+ dimension_label.set_font_style(dim_font);
+ }
let dimension = Dimension::new(
Group::new(dimension_label)
cell_style: &mut CellStyle,
font_style: &mut look::FontStyle,
) {
+ Self::decode_font_style(fg, bg, font_style);
+ Self::decode_cell_style(fg, cell_style);
+ }
+
+ fn decode_font_style(
+ fg: Option<&Style>,
+ bg: Option<&Style>,
+ font_style: &mut look::FontStyle,
+ ) -> bool {
+ let mut updated = false;
if let Some(fg) = fg {
if let Some(weight) = fg.font_weight {
font_style.bold = weight.is_bold();
+ updated = true;
}
if let Some(style) = fg.font_style {
font_style.italic = style.is_italic();
+ updated = true;
}
if let Some(underline) = fg.font_underline {
font_style.underline = underline.is_underline();
+ updated = true;
}
if let Some(color) = fg.color {
font_style.fg = color;
+ updated = true;
}
if let Some(font_size) = &fg.font_size {
if let Ok(size) = font_size
.parse()
{
font_style.size = size;
+ updated = true;
} else {
// XXX warn?
}
}
+ }
+ if let Some(bg) = bg
+ && let Some(color) = bg.color
+ {
+ font_style.bg = color;
+ updated = true;
+ }
+ updated
+ }
+
+ fn decode_cell_style(fg: Option<&Style>, cell_style: &mut CellStyle) -> bool {
+ let mut updated = false;
+ if let Some(fg) = fg {
if let Some(alignment) = fg.text_alignment {
cell_style.horz_align = alignment.as_horz_align(fg.decimal_offset);
+ updated = true;
}
if let Some(label_local_vertical) = fg.label_location_vertical {
cell_style.vert_align = label_local_vertical.into();
+ updated = true;
}
+ // XXX margins?
}
- if let Some(bg) = bg {
- if let Some(color) = bg.color {
- font_style.bg = color;
- }
- }
+ updated
}
fn decode_area(fg: Option<&Style>, bg: Option<&Style>, out: &mut AreaStyle) {