Explorar el Código

chore: simplifying unnecessary struct fields/functions

Berke hace 1 año
padre
commit
f888f9d671
Se han modificado 2 ficheros con 13 adiciones y 33 borrados
  1. 11 24
      src/main.rs
  2. 2 9
      src/screen/dashboard.rs

+ 11 - 24
src/main.rs

@@ -418,8 +418,6 @@ impl State {
                     self.dashboard.focus = focus_pane;
                 }
 
-                self.dashboard.last_axis_split = Some(axis);
-
                 Task::none()
             },
             Message::Clicked(pane) => {
@@ -448,14 +446,11 @@ impl State {
                 self.dashboard.panes.restore();
                 Task::none()
             },
-            Message::Close(pane) => {       
-                let pane_state = self.dashboard.panes.get(pane).unwrap();
-                
-                self.dashboard.pane_state_cache.insert(pane_state.id, (pane_state.settings.selected_ticker, pane_state.settings.selected_timeframe, pane_state.settings.min_tick_size));
-
+            Message::Close(pane) => {                       
                 if let Some((_, sibling)) = self.dashboard.panes.close(pane) {
                     self.dashboard.focus = Some(sibling);
                 }
+                
                 Task::none()
             },
             Message::ToggleLayoutLock => {
@@ -827,30 +822,22 @@ impl State {
             );
 
         if self.dashboard.show_layout_modal {
-            let pane_to_split = self.dashboard.focus.unwrap_or_else(|| { dbg!("No focused pane found"); self.dashboard.first_pane });
-
-            let mut axis_to_split = if rand::random() { pane_grid::Axis::Horizontal } else { pane_grid::Axis::Vertical };
-
-            if let Some(axis) = self.dashboard.last_axis_split {
-                if axis == pane_grid::Axis::Horizontal {
-                    axis_to_split = pane_grid::Axis::Vertical;
-                } else {
-                    axis_to_split = pane_grid::Axis::Horizontal;
-                }
-            } 
+            let pane_to_split = self.dashboard.focus
+                .unwrap_or_else(
+                    || { 
+                        dbg!("No focused pane found"); 
+                        *self.dashboard.panes.iter().next().unwrap().0
+                    }
+                );
 
-            let add_pane_button = button("add new pane").width(iced::Pixels(200.0)).on_press(
-                Message::Split(axis_to_split, pane_to_split)
+            let add_pane_button = button("Add a new pane").width(iced::Pixels(200.0)).on_press(
+                Message::Split(pane_grid::Axis::Horizontal, pane_to_split)
             );
 
             let signup = container(
                 Column::new()
                     .spacing(10)
                     .align_items(Alignment::Center)
-                    .push(
-                        Text::new("Add a new pane")
-                            .size(20)
-                    )
                     .push(add_pane_button)
                     .push(
                         Column::new()

+ 2 - 9
src/screen/dashboard.rs

@@ -15,26 +15,19 @@ use iced::widget::pane_grid::{self, Configuration};
 
 pub struct Dashboard {
     pub panes: pane_grid::State<PaneState>,
-    pub show_layout_modal: bool,
     pub focus: Option<pane_grid::Pane>,
-    pub first_pane: pane_grid::Pane,
     pub pane_lock: bool,
-    pub pane_state_cache: HashMap<Uuid, (Option<Ticker>, Option<Timeframe>, Option<f32>)>,
-    pub last_axis_split: Option<pane_grid::Axis>,
+    pub show_layout_modal: bool,
 }
 impl Dashboard {
     pub fn empty(pane_config: Configuration<PaneState>) -> Self {
         let panes: pane_grid::State<PaneState> = pane_grid::State::with_configuration(pane_config);
-        let first_pane: pane_grid::Pane = *panes.panes.iter().next().unwrap().0;
         
         Self { 
-            show_layout_modal: false,
             panes,
             focus: None,
-            first_pane,
             pane_lock: false,
-            pane_state_cache: HashMap::new(),
-            last_axis_split: None,
+            show_layout_modal: false,
         }
     }