Optional sections

This commit is contained in:
Ian Keane 2025-11-25 18:06:24 -05:00
parent 054a72e4a6
commit 8c1e72b1ef
3 changed files with 128 additions and 60 deletions

View file

@ -87,9 +87,24 @@ impl App {
}
pub fn new() -> anyhow::Result<Self> {
let config = Config::load()?;
let mut state = AppState::load()?;
// Initialize current_pane to first enabled section
let enabled = [
config.show_permanent,
config.show_recurring,
config.show_recent,
];
// Find first enabled pane
if let Some(first_enabled) = enabled.iter().position(|&x| x) {
state.current_pane = first_enabled;
}
Ok(Self {
state: AppState::load()?,
config: Config::load()?,
state,
config,
current_screen: Screen::Main,
needs_clear: false,
new_entry_buffer: String::new(),
@ -1213,7 +1228,29 @@ impl App {
}
fn change_pane(&mut self, delta: i32) {
self.state.current_pane = ((self.state.current_pane as i32 + delta).rem_euclid(3)) as usize;
// Find next enabled pane
let mut next_pane = self.state.current_pane;
let enabled = [
self.config.show_permanent,
self.config.show_recurring,
self.config.show_recent,
];
// Count enabled panes
let enabled_count = enabled.iter().filter(|&&x| x).count();
if enabled_count == 0 {
return; // No panes to switch to
}
// Find next enabled pane
for _ in 0..3 {
next_pane = ((next_pane as i32 + delta).rem_euclid(3)) as usize;
if enabled[next_pane] {
break;
}
}
self.state.current_pane = next_pane;
self.state.current_column = 0;
}

View file

@ -11,6 +11,12 @@ pub struct Config {
pub strict_projects: bool,
#[serde(default = "default_multi_column")]
pub multi_column: bool,
#[serde(default = "default_true")]
pub show_permanent: bool,
#[serde(default = "default_true")]
pub show_recurring: bool,
#[serde(default = "default_true")]
pub show_recent: bool,
}
fn default_show_help_hint() -> bool {
@ -25,6 +31,10 @@ fn default_multi_column() -> bool {
true
}
fn default_true() -> bool {
true
}
impl Default for Config {
fn default() -> Self {
Self {
@ -32,6 +42,9 @@ impl Default for Config {
projects: Vec::new(),
strict_projects: default_strict_projects(),
multi_column: default_multi_column(),
show_permanent: default_true(),
show_recurring: default_true(),
show_recent: default_true(),
}
}
}

View file

@ -43,41 +43,51 @@ 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
// Count enabled sections
let enabled_sections = [
app.config.show_permanent,
app.config.show_recurring,
app.config.show_recent,
]
} else {
vec![Constraint::Min(3), Constraint::Min(3), Constraint::Min(3)]
};
.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;
let section_height = main_height / 3;
// 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
if app.config.show_permanent {
render_section(
frame,
sections[0],
chunks[chunk_idx],
"Permanent Items",
&app.state.permanent_items,
app.state.current_pane == 0,
@ -85,10 +95,13 @@ fn render_main(frame: &mut Frame, app: &App) {
app.state.current_column,
app.config.multi_column,
);
chunk_idx += 1;
}
if app.config.show_recurring {
render_section(
frame,
sections[1],
chunks[chunk_idx],
"Recurring Items",
&app.state.recurring_items,
app.state.current_pane == 1,
@ -96,10 +109,13 @@ fn render_main(frame: &mut Frame, app: &App) {
app.state.current_column,
app.config.multi_column,
);
chunk_idx += 1;
}
if app.config.show_recent {
render_section(
frame,
sections[2],
chunks[chunk_idx],
"Ad-Hoc Items",
&app.state.recent_items,
app.state.current_pane == 2,
@ -107,10 +123,12 @@ fn render_main(frame: &mut Frame, app: &App) {
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);
}
}