tui-core: Fix label style function

3cb7e9e2ef7c09ae3785a39d497a45bbfaa51291
Alexis Sellier committed ago 1 parent 913b7a52
crates/tui-core/src/label.rs +17 -0
88 88
        }
89 89
    }
90 90
91 91
    /// Styles the label.
92 92
    pub fn style(self, style: Style) -> Self {
93 +
        let style = self.paint.style.merge(style);
93 94
        Self {
94 95
            paint: self.paint.with_style(style),
95 96
            metrics: self.metrics,
96 97
        }
97 98
    }
188 189
    if input.as_bytes().contains(&b'\n') || input.as_bytes().contains(&b'\r') {
189 190
        input.retain(|c| c != '\n' && c != '\r');
190 191
    }
191 192
    input
192 193
}
194 +
195 +
#[cfg(test)]
196 +
mod tests {
197 +
    use super::*;
198 +
199 +
    #[test]
200 +
    fn style_merges_with_existing_label_colors() {
201 +
        let label = Label::new("x")
202 +
            .fg(Color::White)
203 +
            .bg(Color::Blue)
204 +
            .style(Style::default().bold());
205 +
206 +
        assert_eq!(label.paint.style().fg_color(), Color::White);
207 +
        assert_eq!(label.paint.style().bg_color(), Color::Blue);
208 +
    }
209 +
}