mirror of
https://github.com/ratatui/ratatui.git
synced 2025-10-02 07:21:24 +00:00
Fix some display errors
This commit is contained in:
parent
dd6cdf1f11
commit
cd919e69f5
@ -22,8 +22,8 @@ use log4rs::config::{Appender, Config, Root};
|
|||||||
|
|
||||||
use tui::Terminal;
|
use tui::Terminal;
|
||||||
use tui::widgets::{Widget, Block, List, Gauge, Sparkline, Text, border, Chart, Axis, Dataset,
|
use tui::widgets::{Widget, Block, List, Gauge, Sparkline, Text, border, Chart, Axis, Dataset,
|
||||||
BarChart, Marker, Tabs};
|
BarChart, Marker, Tabs, Table};
|
||||||
use tui::widgets::canvas::{Canvas, Shape, Line, Map, MapResolution};
|
use tui::widgets::canvas::{Canvas, Line, Map, MapResolution};
|
||||||
use tui::layout::{Group, Direction, Size, Rect};
|
use tui::layout::{Group, Direction, Size, Rect};
|
||||||
use tui::style::Color;
|
use tui::style::Color;
|
||||||
|
|
||||||
@ -287,19 +287,24 @@ fn draw(t: &mut Terminal, app: &App) {
|
|||||||
draw_main(t, app, &chunks[1]);
|
draw_main(t, app, &chunks[1]);
|
||||||
}
|
}
|
||||||
1 => {
|
1 => {
|
||||||
Canvas::default()
|
Group::default()
|
||||||
.block(Block::default().title("World").borders(border::ALL))
|
.direction(Direction::Vertical)
|
||||||
.layers(&[&[Map::default().resolution(MapResolution::High)],
|
.sizes(&[Size::Percent(50), Size::Percent(50)])
|
||||||
&[&Line {
|
.render(t, &chunks[1], |t, chunks| {
|
||||||
x1: 0.0,
|
Table::default()
|
||||||
y1: 0.0,
|
.block(Block::default().title("Servers").borders(border::ALL))
|
||||||
x2: 10.0,
|
.titles(&["Server", "Location", "Status"])
|
||||||
y2: 10.0,
|
.widths(&[20, 20, 20])
|
||||||
color: Color::Red,
|
.rows(&[&["Europe#1", "Paris", "Up"],
|
||||||
}]])
|
&["Europe#2", "Berlin", "Up"]])
|
||||||
.x_bounds([180.0, 0.0])
|
.render(&chunks[0], t);
|
||||||
.y_bounds([0.0, 90.0])
|
Canvas::default()
|
||||||
.render(&chunks[1], t);
|
.block(Block::default().title("World").borders(border::ALL))
|
||||||
|
.layers(&[&[Map::default().resolution(MapResolution::High)]])
|
||||||
|
.x_bounds([180.0, -180.0])
|
||||||
|
.y_bounds([-90.0, 90.0])
|
||||||
|
.render(&chunks[1], t);
|
||||||
|
})
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
|
@ -15,10 +15,4 @@ pub mod widgets;
|
|||||||
pub mod style;
|
pub mod style;
|
||||||
pub mod layout;
|
pub mod layout;
|
||||||
|
|
||||||
pub use self::terminal::Terminal;
|
pub use self::terminal::Terminal;
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
#[test]
|
|
||||||
fn it_works() {}
|
|
||||||
}
|
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
use buffer::Buffer;
|
use buffer::Buffer;
|
||||||
use layout::Rect;
|
use layout::Rect;
|
||||||
use style::Color;
|
use style::Color;
|
||||||
@ -119,17 +118,27 @@ impl<'a> Widget for Block<'a> {
|
|||||||
if self.borders.contains(border::RIGHT | border::BOTTOM) {
|
if self.borders.contains(border::RIGHT | border::BOTTOM) {
|
||||||
buf.set_symbol(area.right() - 1, area.bottom() - 1, line::BOTTOM_RIGHT);
|
buf.set_symbol(area.right() - 1, area.bottom() - 1, line::BOTTOM_RIGHT);
|
||||||
}
|
}
|
||||||
if let Some(title) = self.title {
|
|
||||||
let dx = if self.borders.intersects(border::LEFT) {
|
if area.width > 2 {
|
||||||
1
|
if let Some(title) = self.title {
|
||||||
} else {
|
let lx = if self.borders.intersects(border::LEFT) {
|
||||||
0
|
1
|
||||||
};
|
} else {
|
||||||
buf.set_string(area.left() + dx,
|
0
|
||||||
area.top(),
|
};
|
||||||
title,
|
let rx = if self.borders.intersects(border::RIGHT) {
|
||||||
self.title_color,
|
1
|
||||||
self.bg);
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
let width = area.width - lx - rx;
|
||||||
|
buf.set_stringn(area.left() + lx,
|
||||||
|
area.top(),
|
||||||
|
title,
|
||||||
|
width as usize,
|
||||||
|
self.title_color,
|
||||||
|
self.bg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,19 +95,24 @@ impl<'a> Widget for List<'a> {
|
|||||||
Some(s) => (s.width() + 1) as u16 + list_area.left(),
|
Some(s) => (s.width() + 1) as u16 + list_area.left(),
|
||||||
None => list_area.left(),
|
None => list_area.left(),
|
||||||
};
|
};
|
||||||
for i in 0..bound {
|
|
||||||
let index = i + offset;
|
if x < list_area.right() {
|
||||||
let item = self.items[index];
|
let width = (list_area.right() - x) as usize;
|
||||||
let color = if index == self.selected {
|
for i in 0..bound {
|
||||||
self.selection_color
|
let index = i + offset;
|
||||||
} else {
|
let item = self.items[index];
|
||||||
self.color
|
let color = if index == self.selected {
|
||||||
};
|
self.selection_color
|
||||||
buf.set_string(x,
|
} else {
|
||||||
list_area.top() + i as u16,
|
self.color
|
||||||
item,
|
};
|
||||||
color,
|
buf.set_stringn(x,
|
||||||
self.background_color);
|
list_area.top() + i as u16,
|
||||||
|
item,
|
||||||
|
width,
|
||||||
|
color,
|
||||||
|
self.background_color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let Some(s) = self.selection_symbol {
|
if let Some(s) = self.selection_symbol {
|
||||||
buf.set_string(list_area.left(),
|
buf.set_string(list_area.left(),
|
||||||
|
@ -6,6 +6,7 @@ mod sparkline;
|
|||||||
mod chart;
|
mod chart;
|
||||||
mod barchart;
|
mod barchart;
|
||||||
mod tabs;
|
mod tabs;
|
||||||
|
mod table;
|
||||||
pub mod canvas;
|
pub mod canvas;
|
||||||
|
|
||||||
pub use self::block::Block;
|
pub use self::block::Block;
|
||||||
@ -16,6 +17,7 @@ pub use self::sparkline::Sparkline;
|
|||||||
pub use self::chart::{Chart, Axis, Dataset, Marker};
|
pub use self::chart::{Chart, Axis, Dataset, Marker};
|
||||||
pub use self::barchart::BarChart;
|
pub use self::barchart::BarChart;
|
||||||
pub use self::tabs::Tabs;
|
pub use self::tabs::Tabs;
|
||||||
|
pub use self::table::Table;
|
||||||
|
|
||||||
use buffer::Buffer;
|
use buffer::Buffer;
|
||||||
use layout::Rect;
|
use layout::Rect;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user