Use StyleDiff for widget::Tabs highlight_style as well

pull/317/head
Mikko Rantanen 4 years ago
parent c779b74930
commit 96f5e11bdd
No known key found for this signature in database
GPG Key ID: B680E9CE10A55798

@ -21,7 +21,7 @@ pub fn draw<B: Backend>(f: &mut Frame<B>, app: &mut App) {
.block(Block::default().borders(Borders::ALL).title(app.title))
.titles(&app.tabs.titles)
.style(Style::default().fg(Color::Green))
.highlight_style(Style::default().fg(Color::Yellow))
.highlight_style_diff(StyleDiff::default().fg(Color::Yellow))
.select(app.tabs.index);
f.render_widget(tabs, chunks[0]);
match app.tabs.index {

@ -10,7 +10,7 @@ use termion::{event::Key, input::MouseTerminal, raw::IntoRawMode, screen::Altern
use tui::{
backend::TermionBackend,
layout::{Constraint, Direction, Layout},
style::{Color, Style},
style::{Color, Style, StyleDiff},
widgets::{Block, Borders, Tabs},
Terminal,
};
@ -52,7 +52,7 @@ fn main() -> Result<(), Box<dyn Error>> {
.titles(&app.tabs.titles)
.select(app.tabs.index)
.style(Style::default().fg(Color::Cyan))
.highlight_style(Style::default().fg(Color::Yellow));
.highlight_style_diff(StyleDiff::default().fg(Color::Yellow));
f.render_widget(tabs, chunks[0]);
let inner = match app.tabs.index {
0 => Block::default().title("Inner 0").borders(Borders::ALL),

@ -2,7 +2,7 @@ use unicode_width::UnicodeWidthStr;
use crate::buffer::Buffer;
use crate::layout::Rect;
use crate::style::Style;
use crate::style::{Style, StyleDiff};
use crate::symbols::line;
use crate::widgets::{Block, Widget};
@ -35,7 +35,7 @@ where
/// The style used to draw the text
style: Style,
/// The style used to display the selected item
highlight_style: Style,
highlight_style_diff: StyleDiff,
/// Tab divider
divider: &'a str,
}
@ -50,7 +50,7 @@ where
titles: &[],
selected: 0,
style: Default::default(),
highlight_style: Default::default(),
highlight_style_diff: Default::default(),
divider: line::VERTICAL,
}
}
@ -80,8 +80,17 @@ where
self
}
#[deprecated(
since = "0.10.0",
note = "Use the `highlight_style_diff` method instead"
)]
pub fn highlight_style(mut self, style: Style) -> Tabs<'a, T> {
self.highlight_style = style;
self.highlight_style_diff = style.into();
self
}
pub fn highlight_style_diff(mut self, style: StyleDiff) -> Tabs<'a, T> {
self.highlight_style_diff = style;
self
}
@ -116,7 +125,7 @@ where
for (title, style, last_title) in self.titles.iter().enumerate().map(|(i, t)| {
let lt = i + 1 == titles_length;
if i == self.selected {
(t, self.highlight_style, lt)
(t, self.style.patch(self.highlight_style_diff), lt)
} else {
(t, self.style, lt)
}

Loading…
Cancel
Save