Change the way the panel scrolls with long lists like the file list, now it scrolls...
authorJim Morris <morris@wolfman.com>
Thu, 7 Nov 2013 08:52:22 +0000 (00:52 -0800)
committerJim Morris <morris@wolfman.com>
Thu, 7 Nov 2013 08:52:22 +0000 (00:52 -0800)
src/modules/utils/panel/Panel.cpp
src/modules/utils/panel/Panel.h
src/modules/utils/panel/PanelScreen.cpp
src/modules/utils/panel/screens/WatchScreen.cpp

index 06ca3f7..9d62613 100644 (file)
@@ -365,7 +365,7 @@ void Panel::setup_menu(uint16_t rows, uint16_t lines)
     this->menu_current_line = 0;
     this->menu_start_line = 0;
     this->menu_rows = rows;
-    this->menu_lines = lines;
+    this->panel_lines = lines;
 }
 
 void Panel::menu_update()
@@ -373,23 +373,47 @@ void Panel::menu_update()
     // Limits, up and down
     // NOTE menu_selected_line is changed in an interrupt and can change at any time
     int msl = this->menu_selected_line; // hopefully this is atomic
+
+    #if 0
+    // this allows it to wrap but with new method we dont; want to wrap
     msl = msl % ( this->menu_rows << this->menu_offset );
     while ( msl < 0 ) {
         msl += this->menu_rows << this->menu_offset;
     }
-    this->menu_selected_line = msl; // update atomically we hope
+    #else
+        // limit selected line to screen lines available
+        if(msl >= this->menu_rows<<this->menu_offset){
+            msl= (this->menu_rows-1)<<this->menu_offset;
+        }else if(msl < 0) msl= 0;
+    #endif
 
+    this->menu_selected_line = msl; // update atomically we hope
     this->menu_current_line = msl >> this->menu_offset;
 
     // What to display
-    this->menu_start_line = 0;
-    if ( this->menu_rows > this->menu_lines ) {
+    if ( this->menu_rows > this->panel_lines ) {
+        #if 0
+        // old way of scrolling not nice....
         if ( this->menu_current_line >= 2 ) {
             this->menu_start_line = this->menu_current_line - 1;
         }
-        if ( this->menu_current_line > this->menu_rows - this->menu_lines ) {
-            this->menu_start_line = this->menu_rows - this->menu_lines;
+        if ( this->menu_current_line > this->menu_rows - this->panel_lines ) {
+            this->menu_start_line = this->menu_rows - this->panel_lines;
+        }
+        #else
+        // new way we only scroll the lines when the cursor hits the bottom of the screen or the top of the screen
+        // do we want to scroll up?
+        int sl= this->menu_current_line - this->menu_start_line; // screen line we are on
+        if(sl >= this->panel_lines) {
+            this->menu_start_line += ((sl+1)-this->panel_lines); // scroll up to keep it on the screen
+
+        }else if(sl < 0 ) { // do we want to scroll down?
+            this->menu_start_line += sl; // scroll down
         }
+        #endif
+
+    }else{
+        this->menu_start_line = 0;
     }
 
     this->menu_changed = true;
index f5688f2..8c0c1eb 100644 (file)
@@ -104,7 +104,7 @@ class Panel : public Module {
         int menu_selected_line;
         int menu_start_line;
         int menu_rows;
-        int menu_lines;
+        int panel_lines;
         bool menu_changed;
         bool control_value_changed;
         uint16_t menu_current_line;
index c503fcd..47a9ded 100644 (file)
@@ -32,7 +32,7 @@ void PanelScreen::on_enter() {}
 void PanelScreen::refresh_menu(bool clear)
 {
     if (clear) this->panel->lcd->clear();
-    for (uint16_t i = this->panel->menu_start_line; i < this->panel->menu_start_line + min( this->panel->menu_rows, this->panel->menu_lines ); i++ ) {
+    for (uint16_t i = this->panel->menu_start_line; i < this->panel->menu_start_line + min( this->panel->menu_rows, this->panel->panel_lines ); i++ ) {
         this->panel->lcd->setCursor(2, i - this->panel->menu_start_line );
         this->display_menu_line(i);
     }
@@ -43,7 +43,7 @@ void PanelScreen::refresh_menu(bool clear)
 void PanelScreen::refresh_screen(bool clear)
 {
     if (clear) this->panel->lcd->clear();
-    for (uint16_t i = this->panel->menu_start_line; i < this->panel->menu_start_line + min( this->panel->menu_rows, this->panel->menu_lines ); i++ ) {
+    for (uint16_t i = this->panel->menu_start_line; i < this->panel->menu_start_line + min( this->panel->menu_rows, this->panel->panel_lines ); i++ ) {
         this->panel->lcd->setCursor(0, i - this->panel->menu_start_line );
         this->display_menu_line(i);
     }
index ce7dbd2..3397f23 100644 (file)
@@ -155,6 +155,7 @@ void WatchScreen::get_temp_data()
         this->bedtarget = -1;
     }
 
+
     ok = THEKERNEL->public_data->get_value( temperature_control_checksum, hotend_checksum, current_temperature_checksum, &returned_data );
     if (ok) {
         struct pad_temperature temp =  *static_cast<struct pad_temperature *>(returned_data);