buffer its independent, needs fixes
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// src/state/app.rs
|
||||
|
||||
pub mod state;
|
||||
pub mod buffer;
|
||||
|
||||
67
client/src/state/app/buffer.rs
Normal file
67
client/src/state/app/buffer.rs
Normal file
@@ -0,0 +1,67 @@
|
||||
// src/state/app/buffer.rs
|
||||
|
||||
/// Represents the distinct views or "buffers" the user can navigate.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum AppView {
|
||||
Intro,
|
||||
Login,
|
||||
Register,
|
||||
Admin,
|
||||
Form(String),
|
||||
Scratch,
|
||||
}
|
||||
|
||||
impl AppView {
|
||||
/// Returns the display name for the view.
|
||||
pub fn display_name(&self) -> &str {
|
||||
match self {
|
||||
AppView::Intro => "Intro",
|
||||
AppView::Login => "Login",
|
||||
AppView::Register => "Register",
|
||||
AppView::Admin => "Admin Panel",
|
||||
AppView::Form(name) => name.as_str(),
|
||||
AppView::Scratch => "*scratch*",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Holds the state related to buffer management (navigation history).
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct BufferState {
|
||||
pub history: Vec<AppView>,
|
||||
pub active_index: usize,
|
||||
}
|
||||
|
||||
impl Default for BufferState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
history: vec![AppView::Intro], // Start with Intro view
|
||||
active_index: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl BufferState {
|
||||
/// Updates the buffer history and active index.
|
||||
/// If the view already exists, it sets it as active.
|
||||
/// Otherwise, it adds the new view and makes it active.
|
||||
pub fn update_history(&mut self, view: AppView) {
|
||||
let existing_pos = self.history.iter().position(|v| v == &view);
|
||||
|
||||
match existing_pos {
|
||||
Some(pos) => {
|
||||
self.active_index = pos;
|
||||
}
|
||||
None => {
|
||||
self.history.push(view.clone());
|
||||
self.active_index = self.history.len() - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the currently active view.
|
||||
pub fn get_active_view(&self) -> Option<&AppView> {
|
||||
self.history.get(self.active_index)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,34 +2,10 @@
|
||||
|
||||
use std::env;
|
||||
use common::proto::multieko2::table_definition::ProfileTreeResponse;
|
||||
use crate::state::app::buffer::BufferState;
|
||||
use crate::modes::handlers::mode_manager::AppMode;
|
||||
use crate::ui::handlers::context::DialogPurpose;
|
||||
|
||||
/// Represents the distinct views or "buffers" the user can navigate.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum AppView {
|
||||
Intro,
|
||||
Login,
|
||||
Register,
|
||||
Admin,
|
||||
Form(String),
|
||||
Scratch,
|
||||
}
|
||||
|
||||
impl AppView {
|
||||
/// Returns the display name for the view.
|
||||
pub fn display_name(&self) -> &str {
|
||||
match self {
|
||||
AppView::Intro => "Intro",
|
||||
AppView::Login => "Login",
|
||||
AppView::Register => "Register",
|
||||
AppView::Admin => "Admin Panel",
|
||||
AppView::Form(name) => name.as_str(),
|
||||
AppView::Scratch => "*scratch*",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DialogState {
|
||||
pub dialog_show: bool,
|
||||
pub dialog_title: String,
|
||||
@@ -48,8 +24,6 @@ pub struct UiState {
|
||||
pub show_login: bool,
|
||||
pub show_register: bool,
|
||||
pub focus_outside_canvas: bool,
|
||||
pub buffer_history: Vec<AppView>,
|
||||
pub active_buffer_index: usize,
|
||||
pub dialog: DialogState,
|
||||
}
|
||||
|
||||
@@ -166,8 +140,6 @@ impl Default for UiState {
|
||||
show_register: false,
|
||||
show_buffer_list: false,
|
||||
focus_outside_canvas: false,
|
||||
buffer_history: vec![AppView::Intro],
|
||||
active_buffer_index: 0,
|
||||
dialog: DialogState::default(),
|
||||
}
|
||||
}
|
||||
@@ -186,20 +158,3 @@ impl Default for DialogState {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl UiState {
|
||||
/// Updates the buffer history and active index.
|
||||
pub fn update_buffer_history(&mut self, view: AppView) {
|
||||
let existing_pos = self.buffer_history.iter().position(|v| v == &view);
|
||||
|
||||
match existing_pos {
|
||||
Some(pos) => {
|
||||
self.active_buffer_index = pos;
|
||||
}
|
||||
None => {
|
||||
self.buffer_history.push(view.clone());
|
||||
self.active_buffer_index = self.buffer_history.len() - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user