Optional sections
This commit is contained in:
parent
054a72e4a6
commit
8c1e72b1ef
3 changed files with 128 additions and 60 deletions
43
src/app.rs
43
src/app.rs
|
|
@ -87,9 +87,24 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new() -> anyhow::Result<Self> {
|
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 {
|
Ok(Self {
|
||||||
state: AppState::load()?,
|
state,
|
||||||
config: Config::load()?,
|
config,
|
||||||
current_screen: Screen::Main,
|
current_screen: Screen::Main,
|
||||||
needs_clear: false,
|
needs_clear: false,
|
||||||
new_entry_buffer: String::new(),
|
new_entry_buffer: String::new(),
|
||||||
|
|
@ -1213,7 +1228,29 @@ impl App {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn change_pane(&mut self, delta: i32) {
|
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;
|
self.state.current_column = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,12 @@ pub struct Config {
|
||||||
pub strict_projects: bool,
|
pub strict_projects: bool,
|
||||||
#[serde(default = "default_multi_column")]
|
#[serde(default = "default_multi_column")]
|
||||||
pub multi_column: bool,
|
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 {
|
fn default_show_help_hint() -> bool {
|
||||||
|
|
@ -25,6 +31,10 @@ fn default_multi_column() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn default_true() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
@ -32,6 +42,9 @@ impl Default for Config {
|
||||||
projects: Vec::new(),
|
projects: Vec::new(),
|
||||||
strict_projects: default_strict_projects(),
|
strict_projects: default_strict_projects(),
|
||||||
multi_column: default_multi_column(),
|
multi_column: default_multi_column(),
|
||||||
|
show_permanent: default_true(),
|
||||||
|
show_recurring: default_true(),
|
||||||
|
show_recent: default_true(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
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 {
|
// Count enabled sections
|
||||||
vec![
|
let enabled_sections = [
|
||||||
Constraint::Min(3), // At least 3 lines for each section
|
app.config.show_permanent,
|
||||||
Constraint::Min(3),
|
app.config.show_recurring,
|
||||||
Constraint::Min(3),
|
app.config.show_recent,
|
||||||
Constraint::Length(bottom_height), // Command bar + optional status
|
]
|
||||||
]
|
.iter()
|
||||||
} else {
|
.filter(|&&x| x)
|
||||||
vec![Constraint::Min(3), Constraint::Min(3), Constraint::Min(3)]
|
.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()
|
let chunks = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints(constraints)
|
.constraints(constraints)
|
||||||
.split(frame.size());
|
.split(frame.size());
|
||||||
|
|
||||||
let main_height = if bottom_height > 0 {
|
// Render enabled sections
|
||||||
chunks[0].height + chunks[1].height + chunks[2].height
|
let mut chunk_idx = 0;
|
||||||
} else {
|
|
||||||
frame.size().height
|
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
|
if app.config.show_recent {
|
||||||
let sections = vec![
|
render_section(
|
||||||
Rect::new(0, 0, frame.size().width, section_height),
|
frame,
|
||||||
Rect::new(0, section_height, frame.size().width, section_height),
|
chunks[chunk_idx],
|
||||||
Rect::new(0, section_height * 2, frame.size().width, section_height),
|
"Ad-Hoc Items",
|
||||||
];
|
&app.state.recent_items,
|
||||||
|
app.state.current_pane == 2,
|
||||||
// Render main sections
|
app.state.selected_indices[2],
|
||||||
render_section(
|
app.state.current_column,
|
||||||
frame,
|
app.config.multi_column,
|
||||||
sections[0],
|
);
|
||||||
"Permanent Items",
|
chunk_idx += 1;
|
||||||
&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,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Render bottom bar if needed
|
// Render bottom bar if needed
|
||||||
if bottom_height > 0 {
|
if bottom_height > 0 {
|
||||||
let bottom_area = chunks[3];
|
let bottom_area = chunks[chunk_idx];
|
||||||
render_bottom_bar(frame, bottom_area, app);
|
render_bottom_bar(frame, bottom_area, app);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue