Make sidebar ajustable

This commit is contained in:
suchmememanyskill
2024-01-28 00:48:06 +01:00
parent 1c50efa500
commit 939a9f6547
4 changed files with 38 additions and 78 deletions

View File

@@ -3,6 +3,7 @@
#include "../core/data_setup.h"
#include "nav_buttons.h"
#include <HTTPClient.h>
#include "ui_utils.h"
static lv_style_t nav_button_style;
@@ -75,92 +76,54 @@ static void btn_click_macros(lv_event_t * e){
nav_buttons_setup(4);
}
void create_button(const char* icon, const char* name, lv_event_cb_t button_click, lv_event_cb_t label_update, lv_obj_t * root){
lv_obj_t* btn = lv_btn_create(root);
lv_obj_set_flex_grow(btn, 1);
lv_obj_set_width(btn, CYD_SCREEN_SIDEBAR_SIZE_PX);
lv_obj_add_style(btn, &nav_button_style, 0);
if (button_click != NULL)
lv_obj_add_event_cb(btn, button_click, LV_EVENT_CLICKED, NULL);
lv_obj_t* label = lv_label_create(btn);
lv_label_set_text(label, icon);
lv_obj_align(label, LV_ALIGN_CENTER, 0, -1 * CYD_SCREEN_BIG_GAP_PX);
label = lv_label_create(btn);
lv_label_set_text(label, name);
lv_obj_align(label, LV_ALIGN_CENTER, 0, CYD_SCREEN_BIG_GAP_PX);
lv_obj_add_event_cb(label, label_update, LV_EVENT_MSG_RECEIVED, NULL);
lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL);
lv_obj_add_style(label, &nav_button_text_style, 0);
}
void nav_buttons_setup(unsigned char active_panel){
lv_obj_clean(lv_scr_act());
lv_obj_clear_flag(lv_scr_act(), LV_OBJ_FLAG_SCROLLABLE);
sprintf(temp_buffer, "%.0f/%.0f", printer.extruder_temp, printer.bed_temp);
sprintf(z_pos_buffer, "Z%.2f", printer.position[2]);
const int button_width = 40;
const int button_height = 60;
const int icon_text_spacing = 10;
lv_obj_t * root_panel = lv_create_empty_panel(lv_scr_act());
lv_obj_set_size(root_panel, CYD_SCREEN_SIDEBAR_SIZE_PX, CYD_SCREEN_HEIGHT);
lv_obj_align(root_panel, LV_ALIGN_TOP_LEFT, 0, 0);
lv_obj_set_layout(root_panel, LV_LAYOUT_FLEX);
lv_obj_set_flex_flow(root_panel, LV_FLEX_FLOW_COLUMN);
lv_obj_set_flex_align(root_panel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_set_style_pad_column(root_panel, 0, 0);
lv_obj_set_style_pad_row(root_panel, 0, 0);
// Files/Print
lv_obj_t * btn = lv_btn_create(lv_scr_act());
lv_obj_set_size(btn, button_width, button_height);
lv_obj_align(btn, LV_ALIGN_TOP_LEFT, 0, 0);
lv_obj_add_style(btn, &nav_button_style, 0);
lv_obj_add_event_cb(btn, btn_click_files, LV_EVENT_CLICKED, NULL);
lv_obj_t * label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_COPY);
lv_obj_align(label, LV_ALIGN_CENTER, 0, -1 * icon_text_spacing);
label = lv_label_create(btn);
lv_label_set_text(label, "Idle");
lv_obj_align(label, LV_ALIGN_CENTER, 0, icon_text_spacing);
lv_obj_add_style(label, &nav_button_text_style, 0);
lv_obj_add_event_cb(label, update_printer_data_time, LV_EVENT_MSG_RECEIVED, NULL);
lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL);
create_button(LV_SYMBOL_COPY, "Idle", btn_click_files, update_printer_data_time, root_panel);
// Move
btn = lv_btn_create(lv_scr_act());
lv_obj_set_size(btn, button_width, button_height);
lv_obj_align(btn, LV_ALIGN_TOP_LEFT, 0, button_height);
lv_obj_add_style(btn, &nav_button_style, 0);
lv_obj_add_event_cb(btn, btn_click_move, LV_EVENT_CLICKED, NULL);
label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_CHARGE);
lv_obj_align(label, LV_ALIGN_CENTER, 0, -1 * icon_text_spacing);
label = lv_label_create(btn);
lv_label_set_text(label, z_pos_buffer);
lv_obj_align(label, LV_ALIGN_CENTER, 0, icon_text_spacing);
lv_obj_add_event_cb(label, update_printer_data_z_pos, LV_EVENT_MSG_RECEIVED, NULL);
lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL);
lv_obj_add_style(label, &nav_button_text_style, 0);
create_button(LV_SYMBOL_CHARGE, "Z?", btn_click_move, update_printer_data_z_pos, root_panel);
// Extrude/Temp
btn = lv_btn_create(lv_scr_act());
lv_obj_set_size(btn, button_width, button_height);
lv_obj_align(btn, LV_ALIGN_TOP_LEFT, 0, button_height * 2);
lv_obj_add_style(btn, &nav_button_style, 0);
lv_obj_add_event_cb(btn, btn_click_extrude, LV_EVENT_CLICKED, NULL);
create_button(LV_SYMBOL_WARNING, "?/?", btn_click_extrude, update_printer_data_temp, root_panel);
label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_WARNING);
lv_obj_align(label, LV_ALIGN_CENTER, 0, -1 * icon_text_spacing);
// Macros
create_button(LV_SYMBOL_GPS, "Macro", btn_click_macros, NULL, root_panel);
label = lv_label_create(btn);
lv_label_set_text(label, temp_buffer);
lv_obj_align(label, LV_ALIGN_CENTER, 0, icon_text_spacing);
lv_obj_add_event_cb(label, update_printer_data_temp, LV_EVENT_MSG_RECEIVED, NULL);
lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL);
lv_obj_add_style(label, &nav_button_text_style, 0);
// Settings
btn = lv_btn_create(lv_scr_act());
lv_obj_set_size(btn, button_width, button_height);
lv_obj_align(btn, LV_ALIGN_TOP_LEFT, 0, button_height * 3);
lv_obj_add_style(btn, &nav_button_style, 0);
lv_obj_add_event_cb(btn, btn_click_macros, LV_EVENT_CLICKED, NULL);
label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_GPS);
lv_obj_align(label, LV_ALIGN_CENTER, 0, -1 * icon_text_spacing);
label = lv_label_create(btn);
lv_label_set_text(label, "Macro");
lv_obj_align(label, LV_ALIGN_CENTER, 0, icon_text_spacing);
lv_obj_add_style(label, &nav_button_text_style, 0);
lv_obj_t * panel = lv_obj_create(lv_scr_act());
lv_obj_set_size(panel, TFT_HEIGHT - button_width, TFT_WIDTH);
lv_obj_t * panel = lv_create_empty_panel(lv_scr_act());
lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH, CYD_SCREEN_HEIGHT);
lv_obj_align(panel, LV_ALIGN_TOP_RIGHT, 0, 0);
lv_obj_set_style_border_width(panel, 0, 0);
lv_obj_set_style_bg_opa(panel, LV_OPA_TRANSP, 0);
lv_obj_set_style_pad_all(panel, 0, 0);
switch (active_panel){
case 0:
@@ -179,6 +142,8 @@ void nav_buttons_setup(unsigned char active_panel){
macros_panel_init(panel);
break;
}
lv_msg_send(DATA_PRINTER_DATA, &printer);
}
void nav_style_setup(){

View File

@@ -204,6 +204,4 @@ void move_panel_init(lv_obj_t* panel){
y_pos += 60;
}
lv_msg_send(DATA_PRINTER_DATA, &printer);
}

View File

@@ -117,6 +117,4 @@ void progress_panel_init(lv_obj_t* panel){
lv_label_set_text(label, LV_SYMBOL_PAUSE);
lv_obj_center(label);
}
lv_msg_send(DATA_PRINTER_DATA, &printer);
}

View File

@@ -302,6 +302,5 @@ void temp_panel_init(lv_obj_t* panel){
lv_label_set_text(label, LV_SYMBOL_UP " Retract");
lv_obj_center(label);
lv_msg_send(DATA_PRINTER_DATA, &printer);
lv_msg_send(DATA_PRINTER_TEMP_PRESET, &printer);
}