better documentation/naming of LineDirection

This commit is contained in:
René Rössler 2022-02-09 13:09:10 +01:00
parent 6db4b929eb
commit bbc3fabcab
3 changed files with 13 additions and 11 deletions

View file

@ -53,7 +53,7 @@ impl<'a> GridBuilder<'a> {
self.ui.available_rect_before_wrap().width() - 2.0 * self.padding.outer, self.ui.available_rect_before_wrap().width() - 2.0 * self.padding.outer,
self.padding.inner, self.padding.inner,
); );
let mut layout = Layout::new(self.ui, self.padding.clone(), LineDirection::TopToBottom); let mut layout = Layout::new(self.ui, self.padding.clone(), LineDirection::Vertical);
grid(Grid { grid(Grid {
layout: &mut layout, layout: &mut layout,
direction: GridDirection::Horizontal, direction: GridDirection::Horizontal,
@ -72,7 +72,7 @@ impl<'a> GridBuilder<'a> {
self.ui.available_rect_before_wrap().height() - 2.0 * self.padding.outer, self.ui.available_rect_before_wrap().height() - 2.0 * self.padding.outer,
self.padding.inner, self.padding.inner,
); );
let mut layout = Layout::new(self.ui, self.padding.clone(), LineDirection::LeftToRight); let mut layout = Layout::new(self.ui, self.padding.clone(), LineDirection::Horizontal);
grid(Grid { grid(Grid {
layout: &mut layout, layout: &mut layout,
direction: GridDirection::Vertical, direction: GridDirection::Vertical,

View file

@ -10,10 +10,12 @@ pub(crate) enum CellSize {
} }
pub(crate) enum LineDirection { pub(crate) enum LineDirection {
/// Cells go from top to bottom /// Cells go from top to bottom on each line
LeftToRight, /// Lines go from left to right
Horizontal,
/// Cells go from left to right /// Cells go from left to right
TopToBottom, /// Lines go from top to bottom
Vertical,
} }
/// Positions cells in `[LineDirection]` and starts a new line on `[Layout::end_line]` /// Positions cells in `[LineDirection]` and starts a new line on `[Layout::end_line]`
@ -67,10 +69,10 @@ impl<'l> Layout<'l> {
fn set_pos(&mut self, rect: Rect) { fn set_pos(&mut self, rect: Rect) {
match self.direction { match self.direction {
LineDirection::LeftToRight => { LineDirection::Horizontal => {
self.pos.y = rect.bottom() + self.padding.inner; self.pos.y = rect.bottom() + self.padding.inner;
} }
LineDirection::TopToBottom => { LineDirection::Vertical => {
self.pos.x = rect.right() + self.padding.inner; self.pos.x = rect.right() + self.padding.inner;
} }
} }
@ -119,11 +121,11 @@ impl<'l> Layout<'l> {
/// only needed for layouts with multiple lines, like Table /// only needed for layouts with multiple lines, like Table
pub fn end_line(&mut self) { pub fn end_line(&mut self) {
match self.direction { match self.direction {
LineDirection::LeftToRight => { LineDirection::Horizontal => {
self.pos.x = self.max.x; self.pos.x = self.max.x;
self.pos.y = self.rect.top(); self.pos.y = self.rect.top();
} }
LineDirection::TopToBottom => { LineDirection::Vertical => {
self.pos.y = self.max.y; self.pos.y = self.max.y;
self.pos.x = self.rect.left(); self.pos.x = self.rect.left();
} }

View file

@ -66,7 +66,7 @@ impl<'a> TableBuilder<'a> {
); );
let ui = self.ui; let ui = self.ui;
{ {
let mut layout = Layout::new(ui, self.padding.clone(), LineDirection::TopToBottom); let mut layout = Layout::new(ui, self.padding.clone(), LineDirection::Vertical);
{ {
let row = TableRow { let row = TableRow {
layout: &mut layout, layout: &mut layout,
@ -131,7 +131,7 @@ impl<'a> Table<'a> {
let end_y = ui.available_rect_before_wrap().bottom(); let end_y = ui.available_rect_before_wrap().bottom();
egui::ScrollArea::new([false, self.scroll]).show(ui, move |ui| { egui::ScrollArea::new([false, self.scroll]).show(ui, move |ui| {
let layout = Layout::new(ui, padding, LineDirection::TopToBottom); let layout = Layout::new(ui, padding, LineDirection::Vertical);
body(TableBody { body(TableBody {
layout, layout,