Optional sections
This commit is contained in:
parent
054a72e4a6
commit
8c1e72b1ef
3 changed files with 128 additions and 60 deletions
132
src/ui.rs
132
src/ui.rs
|
|
@ -43,74 +43,92 @@ fn render_main(frame: &mut Frame, app: &App) {
|
|||
}
|
||||
};
|
||||
|
||||
let constraints = if bottom_height > 0 {
|
||||
vec![
|
||||
Constraint::Min(3), // At least 3 lines for each section
|
||||
Constraint::Min(3),
|
||||
Constraint::Min(3),
|
||||
Constraint::Length(bottom_height), // Command bar + optional status
|
||||
]
|
||||
} else {
|
||||
vec![Constraint::Min(3), Constraint::Min(3), Constraint::Min(3)]
|
||||
};
|
||||
// Count enabled sections
|
||||
let enabled_sections = [
|
||||
app.config.show_permanent,
|
||||
app.config.show_recurring,
|
||||
app.config.show_recent,
|
||||
]
|
||||
.iter()
|
||||
.filter(|&&x| x)
|
||||
.count();
|
||||
|
||||
if enabled_sections == 0 {
|
||||
// No sections enabled - show a message
|
||||
let block = Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title("WAT")
|
||||
.style(Style::default().fg(ACTIVE_COLOR));
|
||||
|
||||
let text = Paragraph::new("No sections enabled. Edit config (press 'c') to enable sections.")
|
||||
.block(block)
|
||||
.style(Style::default().fg(Color::Yellow))
|
||||
.alignment(Alignment::Center);
|
||||
|
||||
frame.render_widget(text, frame.size());
|
||||
return;
|
||||
}
|
||||
|
||||
// Build constraints for enabled sections
|
||||
let section_percentage = 100 / enabled_sections as u16;
|
||||
let mut constraints = vec![Constraint::Percentage(section_percentage); enabled_sections];
|
||||
if bottom_height > 0 {
|
||||
constraints.push(Constraint::Length(bottom_height));
|
||||
}
|
||||
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints(constraints)
|
||||
.split(frame.size());
|
||||
|
||||
let main_height = if bottom_height > 0 {
|
||||
chunks[0].height + chunks[1].height + chunks[2].height
|
||||
} else {
|
||||
frame.size().height
|
||||
};
|
||||
// Render enabled sections
|
||||
let mut chunk_idx = 0;
|
||||
|
||||
if app.config.show_permanent {
|
||||
render_section(
|
||||
frame,
|
||||
chunks[chunk_idx],
|
||||
"Permanent Items",
|
||||
&app.state.permanent_items,
|
||||
app.state.current_pane == 0,
|
||||
app.state.selected_indices[0],
|
||||
app.state.current_column,
|
||||
app.config.multi_column,
|
||||
);
|
||||
chunk_idx += 1;
|
||||
}
|
||||
|
||||
let section_height = main_height / 3;
|
||||
if app.config.show_recurring {
|
||||
render_section(
|
||||
frame,
|
||||
chunks[chunk_idx],
|
||||
"Recurring Items",
|
||||
&app.state.recurring_items,
|
||||
app.state.current_pane == 1,
|
||||
app.state.selected_indices[1],
|
||||
app.state.current_column,
|
||||
app.config.multi_column,
|
||||
);
|
||||
chunk_idx += 1;
|
||||
}
|
||||
|
||||
// Create sections with equal height
|
||||
let sections = vec![
|
||||
Rect::new(0, 0, frame.size().width, section_height),
|
||||
Rect::new(0, section_height, frame.size().width, section_height),
|
||||
Rect::new(0, section_height * 2, frame.size().width, section_height),
|
||||
];
|
||||
|
||||
// Render main sections
|
||||
render_section(
|
||||
frame,
|
||||
sections[0],
|
||||
"Permanent Items",
|
||||
&app.state.permanent_items,
|
||||
app.state.current_pane == 0,
|
||||
app.state.selected_indices[0],
|
||||
app.state.current_column,
|
||||
app.config.multi_column,
|
||||
);
|
||||
|
||||
render_section(
|
||||
frame,
|
||||
sections[1],
|
||||
"Recurring Items",
|
||||
&app.state.recurring_items,
|
||||
app.state.current_pane == 1,
|
||||
app.state.selected_indices[1],
|
||||
app.state.current_column,
|
||||
app.config.multi_column,
|
||||
);
|
||||
|
||||
render_section(
|
||||
frame,
|
||||
sections[2],
|
||||
"Ad-Hoc Items",
|
||||
&app.state.recent_items,
|
||||
app.state.current_pane == 2,
|
||||
app.state.selected_indices[2],
|
||||
app.state.current_column,
|
||||
app.config.multi_column,
|
||||
);
|
||||
if app.config.show_recent {
|
||||
render_section(
|
||||
frame,
|
||||
chunks[chunk_idx],
|
||||
"Ad-Hoc Items",
|
||||
&app.state.recent_items,
|
||||
app.state.current_pane == 2,
|
||||
app.state.selected_indices[2],
|
||||
app.state.current_column,
|
||||
app.config.multi_column,
|
||||
);
|
||||
chunk_idx += 1;
|
||||
}
|
||||
|
||||
// Render bottom bar if needed
|
||||
if bottom_height > 0 {
|
||||
let bottom_area = chunks[3];
|
||||
let bottom_area = chunks[chunk_idx];
|
||||
render_bottom_bar(frame, bottom_area, app);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue