buffers are in the layers now

This commit is contained in:
filipriec
2025-04-15 19:42:12 +02:00
parent 921059bed8
commit 800b857e53
2 changed files with 29 additions and 7 deletions

View File

@@ -1,7 +1,6 @@
// src/components/handlers/buffer_list.rs
use crate::config::colors::themes::Theme;
// use crate::state::app::buffer::AppView;
use crate::state::app::buffer::BufferState;
use ratatui::{
layout::{Alignment, Rect},
@@ -11,6 +10,7 @@ use ratatui::{
Frame,
};
use unicode_width::UnicodeWidthStr;
use crate::functions::common::buffer::get_view_layer;
pub fn render_buffer_list(
f: &mut Frame,
@@ -27,12 +27,23 @@ pub fn render_buffer_list(
.fg(theme.fg)
.bg(theme.bg);
// --- Determine Active Layer ---
let active_layer = match buffer_state.history.get(buffer_state.active_index) {
Some(view) => get_view_layer(view),
None => 1,
};
// --- Create Spans ---
let mut spans = Vec::new();
let mut current_width = 0;
for (i, view) in buffer_state.history.iter().enumerate() {
let is_active = i == buffer_state.active_index;
for (original_index, view) in buffer_state.history.iter().enumerate() {
// Filter: Only process views matching the active layer
if get_view_layer(view) != active_layer {
continue;
}
let is_active = original_index == buffer_state.active_index;
let buffer_name = view.display_name();
let buffer_text = format!(" {} ", buffer_name);
let text_width = UnicodeWidthStr::width(buffer_text.as_str());
@@ -51,10 +62,12 @@ pub fn render_buffer_list(
// --- Filler Span ---
let remaining_width = area.width.saturating_sub(current_width as u16);
spans.push(Span::styled(
" ".repeat(remaining_width as usize),
inactive_style,
));
if !spans.is_empty() || remaining_width > 0 {
spans.push(Span::styled(
" ".repeat(remaining_width as usize),
inactive_style,
));
}
// --- Render ---
let buffer_line = Line::from(spans);

View File

@@ -1,6 +1,15 @@
// src/functions/common/buffer.rs
use crate::state::app::buffer::BufferState;
use crate::state::app::buffer::AppView;
pub fn get_view_layer(view: &AppView) -> u8 {
match view {
AppView::Intro => 1,
AppView::Login | AppView::Register | AppView::Admin => 2,
AppView::Form(_) | AppView::Scratch => 3,
}
}
/// Switches the active buffer index.
pub fn switch_buffer(buffer_state: &mut BufferState, next: bool) -> bool {