From 86ae92b4893dab0810e0822575fe1ec48027f40a Mon Sep 17 00:00:00 2001 From: Florian Dehau Date: Thu, 13 Oct 2016 17:30:18 +0200 Subject: [PATCH] Add color support to the gauge widget --- examples/prototype.rs | 7 ++++--- src/widgets/gauge.rs | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/examples/prototype.rs b/examples/prototype.rs index 7ac502c..5f1fc02 100644 --- a/examples/prototype.rs +++ b/examples/prototype.rs @@ -21,6 +21,7 @@ use log4rs::config::{Appender, Config, Logger, Root}; use tui::Terminal; use tui::widgets::{Widget, Block, List, Gauge, Sparkline, border}; use tui::layout::{Group, Direction, Alignment, Size}; +use tui::style::Color; struct App { name: String, @@ -130,18 +131,18 @@ fn draw(terminal: &mut Terminal, app: &App) { let ui = Group::default() .direction(Direction::Vertical) .alignment(Alignment::Left) - .chunks(&[Size::Fixed(6), Size::Min(5), Size::Fixed(3)]) + .chunks(&[Size::Fixed(7), Size::Min(5), Size::Fixed(3)]) .render(&terminal.area(), |chunks, tree| { - info!("{:?}", terminal.area()); tree.add(Block::default().borders(border::ALL).title("Graphs").render(&chunks[0])); tree.add(Group::default() .direction(Direction::Vertical) .alignment(Alignment::Left) .margin(1) - .chunks(&[Size::Fixed(2), Size::Fixed(2)]) + .chunks(&[Size::Fixed(2), Size::Fixed(3)]) .render(&chunks[0], |chunks, tree| { tree.add(Gauge::new() .block(*Block::default().title("Gauge:")) + .bg(Color::Yellow) .percent(app.progress) .render(&chunks[0])); tree.add(Sparkline::new() diff --git a/src/widgets/gauge.rs b/src/widgets/gauge.rs index 33f3e65..1ef1124 100644 --- a/src/widgets/gauge.rs +++ b/src/widgets/gauge.rs @@ -44,6 +44,16 @@ impl<'a> Gauge<'a> { self.percent = percent; self } + + pub fn bg(&mut self, bg: Color) -> &mut Gauge<'a> { + self.bg = bg; + self + } + + pub fn fg(&mut self, fg: Color) -> &mut Gauge<'a> { + self.fg = fg; + self + } } impl<'a> Widget for Gauge<'a> {