mirror of
https://github.com/suchmememanyskill/CYD-Klipper.git
synced 2026-03-21 05:33:24 +00:00
Small refactor
This commit is contained in:
@@ -13,7 +13,7 @@ static char* power_devices[16] = {0};
|
||||
static bool power_device_states[16] = {0};
|
||||
static int power_devices_count = 0;
|
||||
|
||||
static void _macros_query_internal(){
|
||||
void _macros_query_internal(){
|
||||
SETUP_HTTP_CLIENT("/printer/gcode/help")
|
||||
|
||||
int httpCode = client.GET();
|
||||
@@ -52,13 +52,16 @@ void _power_devices_query_internal(){
|
||||
SETUP_HTTP_CLIENT("/machine/device_power/devices")
|
||||
|
||||
int httpCode = client.GET();
|
||||
|
||||
if (httpCode == 200 || httpCode == 404 || httpCode == 500){
|
||||
power_devices_clear();
|
||||
}
|
||||
|
||||
if (httpCode == 200){
|
||||
JsonDocument doc;
|
||||
deserializeJson(doc, client.getStream());
|
||||
auto result = doc["result"]["devices"].as<JsonArray>();
|
||||
|
||||
power_devices_clear();
|
||||
|
||||
for (auto i : result){
|
||||
const char * device_name = i["device"];
|
||||
const char * device_state = i["status"];
|
||||
|
||||
@@ -16,4 +16,5 @@ POWERQUERY power_devices_query();
|
||||
void macros_query_setup();
|
||||
bool set_power_state(const char* device_name, bool state);
|
||||
void _power_devices_query_internal();
|
||||
void _macros_query_internal();
|
||||
void power_devices_clear();
|
||||
@@ -23,28 +23,7 @@ static void btn_goto_settings(lv_event_t * e){
|
||||
void macros_panel_add_macros_to_panel(lv_obj_t * root_panel, MACROSQUERY query){
|
||||
for (int i = 0; i < query.count; i++){
|
||||
const char* macro = query.macros[i];
|
||||
|
||||
lv_obj_t * panel = lv_create_empty_panel(root_panel);
|
||||
lv_layout_flex_row(panel, LV_FLEX_ALIGN_END);
|
||||
lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
|
||||
|
||||
lv_obj_t * label = lv_label_create(panel);
|
||||
lv_label_set_text(label, macro);
|
||||
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
|
||||
lv_obj_set_flex_grow(label, 1);
|
||||
|
||||
lv_obj_t * btn = lv_btn_create(panel);
|
||||
lv_obj_add_event_cb(btn, btn_press, LV_EVENT_CLICKED, (void*)macro);
|
||||
lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Run");
|
||||
lv_obj_center(label);
|
||||
|
||||
lv_obj_t * line = lv_line_create(root_panel);
|
||||
lv_line_set_points(line, line_points, 2);
|
||||
lv_obj_set_style_line_width(line, 1, 0);
|
||||
lv_obj_set_style_line_color(line, lv_color_hex(0xAAAAAA), 0);
|
||||
lv_create_custom_menu_button(macro, root_panel, btn_press, "Run", (void*)macro);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,26 +40,7 @@ void macros_panel_add_power_devices_to_panel(lv_obj_t * root_panel, POWERQUERY q
|
||||
for (int i = 0; i < query.count; i++){
|
||||
const char* power_device_name = query.power_devices[i];
|
||||
const bool power_device_state = query.power_states[i];
|
||||
|
||||
lv_obj_t * panel = lv_create_empty_panel(root_panel);
|
||||
lv_layout_flex_row(panel, LV_FLEX_ALIGN_END);
|
||||
lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
|
||||
|
||||
lv_obj_t * label = lv_label_create(panel);
|
||||
lv_label_set_text(label, power_device_name);
|
||||
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
|
||||
lv_obj_set_flex_grow(label, 1);
|
||||
|
||||
lv_obj_t * toggle = lv_switch_create(panel);
|
||||
lv_obj_add_event_cb(toggle, power_device_toggle, LV_EVENT_VALUE_CHANGED, (void*)power_device_name);
|
||||
lv_obj_set_size(toggle, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
|
||||
if (power_device_state)
|
||||
lv_obj_add_state(toggle, LV_STATE_CHECKED);
|
||||
|
||||
lv_obj_t * line = lv_line_create(root_panel);
|
||||
lv_line_set_points(line, line_points, 2);
|
||||
lv_obj_set_style_line_width(line, 1, 0);
|
||||
lv_obj_set_style_line_color(line, lv_color_hex(0xAAAAAA), 0);
|
||||
lv_create_custom_menu_switch(power_device_name, root_panel, power_device_toggle, power_device_state, (void*)power_device_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "../../core/lv_setup.h"
|
||||
#include <stdio.h>
|
||||
#include "../nav_buttons.h"
|
||||
#include "../../core/macros_query.h"
|
||||
|
||||
const char * printer_status[] = {
|
||||
"Error",
|
||||
@@ -109,23 +110,15 @@ static void btn_disable_if_controlled_or_offline(lv_event_t * e)
|
||||
PRINTER_CONFIG * keyboard_config = NULL;
|
||||
|
||||
static void keyboard_callback(lv_event_t * e){
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
lv_obj_t * ta = lv_event_get_target(e);
|
||||
lv_obj_t * kb = (lv_obj_t *)lv_event_get_user_data(e);
|
||||
|
||||
if (code == LV_EVENT_READY) {
|
||||
const char * text = lv_textarea_get_text(ta);
|
||||
strcpy(keyboard_config->printer_name, text);
|
||||
write_global_config();
|
||||
lv_msg_send(DATA_PRINTER_MINIMAL, NULL);
|
||||
}
|
||||
|
||||
if(code == LV_EVENT_DEFOCUSED || code == LV_EVENT_CANCEL || code == LV_EVENT_READY) {
|
||||
lv_keyboard_set_textarea(kb, NULL);
|
||||
lv_obj_del(lv_obj_get_parent(kb));
|
||||
}
|
||||
}
|
||||
|
||||
static void btn_printer_delete(lv_event_t * e)
|
||||
{
|
||||
lv_obj_t * btn = lv_event_get_target(e);
|
||||
@@ -146,24 +139,7 @@ static void btn_printer_delete(lv_event_t * e)
|
||||
static void btn_printer_rename(lv_event_t * e)
|
||||
{
|
||||
keyboard_config = (PRINTER_CONFIG*)lv_event_get_user_data(e);
|
||||
|
||||
lv_obj_t * parent = lv_create_empty_panel(lv_scr_act());
|
||||
lv_obj_set_style_bg_opa(parent, LV_OPA_50, 0);
|
||||
lv_obj_set_size(parent, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX);
|
||||
lv_layout_flex_column(parent, LV_FLEX_ALIGN_SPACE_BETWEEN);
|
||||
|
||||
lv_obj_t * empty_panel = lv_create_empty_panel(parent);
|
||||
lv_obj_set_flex_grow(empty_panel, 1);
|
||||
|
||||
lv_obj_t * ta = lv_textarea_create(parent);
|
||||
lv_obj_t * keyboard = lv_keyboard_create(parent);
|
||||
|
||||
lv_obj_set_width(ta, CYD_SCREEN_WIDTH_PX * 0.75);
|
||||
lv_textarea_set_max_length(ta, 24);
|
||||
lv_textarea_set_one_line(ta, true);
|
||||
lv_textarea_set_text(ta, keyboard_config->printer_name);
|
||||
lv_obj_add_event_cb(ta, keyboard_callback, LV_EVENT_ALL, keyboard);
|
||||
lv_keyboard_set_textarea(keyboard, ta);
|
||||
lv_create_keyboard_text_entry(keyboard_callback, LV_KEYBOARD_MODE_TEXT_LOWER, CYD_SCREEN_WIDTH_PX * 0.75, 24, keyboard_config->printer_name, false);
|
||||
}
|
||||
|
||||
static void btn_printer_activate(lv_event_t * e)
|
||||
@@ -174,6 +150,8 @@ static void btn_printer_activate(lv_event_t * e)
|
||||
|
||||
set_printer_config_index(index);
|
||||
set_color_scheme();
|
||||
_macros_query_internal();
|
||||
_power_devices_query_internal();
|
||||
lv_msg_send(DATA_PRINTER_MINIMAL, NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ static void theme_dropdown(lv_event_t * e){
|
||||
}
|
||||
|
||||
const char* brightness_options = "100%\n75%\n50%\n25%";
|
||||
const char brightness_options_values[] = { 255, 192, 128, 64 };
|
||||
const unsigned char brightness_options_values[] = { 255, 192, 128, 64 };
|
||||
|
||||
static void brightness_dropdown(lv_event_t * e){
|
||||
lv_obj_t * dropdown = lv_event_get_target(e);
|
||||
@@ -122,193 +122,76 @@ static void estimated_time_dropdown(lv_event_t * e){
|
||||
write_global_config();
|
||||
}
|
||||
|
||||
const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2) * 0.85f), 0} };
|
||||
|
||||
void create_settings_widget(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel, bool set_height = true){
|
||||
lv_obj_t * panel = lv_create_empty_panel(root_panel);
|
||||
lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
|
||||
|
||||
lv_obj_t * label = lv_label_create(panel);
|
||||
lv_label_set_text(label, label_text);
|
||||
lv_obj_align(label, LV_ALIGN_LEFT_MID, 0, 0);
|
||||
|
||||
lv_obj_set_parent(object, panel);
|
||||
lv_obj_align(object, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||
|
||||
if (set_height)
|
||||
lv_obj_set_height(object, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
|
||||
|
||||
lv_obj_t * line = lv_line_create(root_panel);
|
||||
lv_line_set_points(line, line_points, 2);
|
||||
lv_obj_set_style_line_width(line, 1, 0);
|
||||
lv_obj_set_style_line_color(line, lv_color_hex(0xAAAAAA), 0);
|
||||
}
|
||||
|
||||
#define DROPDOWN_WIDTH CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 3.75
|
||||
#define TOGGLE_WIDTH CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 2
|
||||
|
||||
void settings_panel_init(lv_obj_t* panel){
|
||||
lv_obj_t * toggle = NULL;
|
||||
lv_obj_t * btn = NULL;
|
||||
lv_obj_t * label = NULL;
|
||||
lv_obj_t * dropdown = NULL;
|
||||
|
||||
lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX, 0);
|
||||
lv_layout_flex_column(panel);
|
||||
lv_obj_set_scrollbar_mode(panel, LV_SCROLLBAR_MODE_OFF);
|
||||
|
||||
btn = lv_btn_create(panel);
|
||||
lv_obj_add_event_cb(btn, reset_wifi_click, LV_EVENT_CLICKED, NULL);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Restart");
|
||||
lv_obj_center(label);
|
||||
|
||||
create_settings_widget("Configure WiFi", btn, panel);
|
||||
|
||||
btn = lv_btn_create(panel);
|
||||
lv_obj_add_event_cb(btn, reset_ip_click, LV_EVENT_CLICKED, NULL);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Restart");
|
||||
lv_obj_center(label);
|
||||
|
||||
create_settings_widget("Configure IP", btn, panel);
|
||||
lv_create_custom_menu_button("Configure WiFi", panel, reset_wifi_click, "Restart");
|
||||
lv_create_custom_menu_button("Configure IP", panel, reset_ip_click, "Restart");
|
||||
|
||||
#ifndef CYD_SCREEN_DISABLE_TOUCH_CALIBRATION
|
||||
btn = lv_btn_create(panel);
|
||||
lv_obj_add_event_cb(btn, reset_calibration_click, LV_EVENT_CLICKED, NULL);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text(label, "Restart");
|
||||
lv_obj_center(label);
|
||||
|
||||
create_settings_widget("Calibrate Touch", btn, panel);
|
||||
lv_create_custom_menu_button("Calibrate Touch", panel, reset_calibration_click, "Restart");
|
||||
#endif // CYD_SCREEN_DISABLE_TOUCH_CALIBRATION
|
||||
|
||||
#ifndef CYD_SCREEN_DISABLE_INVERT_COLORS
|
||||
toggle = lv_switch_create(panel);
|
||||
lv_obj_set_width(toggle, TOGGLE_WIDTH);
|
||||
lv_obj_add_event_cb(toggle, invert_color_switch, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
|
||||
if (get_current_printer_config()->invert_colors)
|
||||
lv_obj_add_state(toggle, LV_STATE_CHECKED);
|
||||
|
||||
create_settings_widget("Invert Colors", toggle, panel);
|
||||
lv_create_custom_menu_switch("Invert Colors", panel, invert_color_switch, get_current_printer_config()->invert_colors);
|
||||
#endif // CYD_SCREEN_DISABLE_INVERT_COLORS
|
||||
|
||||
toggle = lv_switch_create(panel);
|
||||
lv_obj_set_width(toggle, TOGGLE_WIDTH);
|
||||
lv_obj_add_event_cb(toggle, light_mode_switch, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
|
||||
if (get_current_printer_config()->light_mode)
|
||||
lv_obj_add_state(toggle, LV_STATE_CHECKED);
|
||||
|
||||
create_settings_widget("Light Mode", toggle, panel);
|
||||
|
||||
dropdown = lv_dropdown_create(panel);
|
||||
lv_dropdown_set_options(dropdown, "Blue\nGreen\nGrey\nYellow\nOrange\nRed\nPurple");
|
||||
lv_dropdown_set_selected(dropdown, get_current_printer_config()->color_scheme);
|
||||
lv_obj_set_width(dropdown, DROPDOWN_WIDTH);
|
||||
lv_obj_add_event_cb(dropdown, theme_dropdown, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
|
||||
create_settings_widget("Theme", dropdown, panel);
|
||||
|
||||
dropdown = lv_dropdown_create(panel);
|
||||
lv_dropdown_set_options(dropdown, brightness_options);
|
||||
lv_obj_set_width(dropdown, DROPDOWN_WIDTH);
|
||||
lv_obj_add_event_cb(dropdown, brightness_dropdown, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
lv_create_custom_menu_switch("Light Mode", panel, light_mode_switch, get_current_printer_config()->light_mode);
|
||||
lv_create_custom_menu_dropdown("Theme", panel, theme_dropdown, "Blue\nGreen\nGrey\nYellow\nOrange\nRed\nPurple", get_current_printer_config()->color_scheme);
|
||||
|
||||
int brightness_settings_index = 0;
|
||||
for (int i = 0; i < SIZEOF(brightness_options_values); i++){
|
||||
if (brightness_options_values[i] == global_config.brightness){
|
||||
lv_dropdown_set_selected(dropdown, i);
|
||||
brightness_settings_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
create_settings_widget("Brightness", dropdown, panel);
|
||||
lv_create_custom_menu_dropdown("Brightness", panel, brightness_dropdown, brightness_options, brightness_settings_index);
|
||||
|
||||
|
||||
#ifndef CYD_SCREEN_DISABLE_TIMEOUT
|
||||
dropdown = lv_dropdown_create(panel);
|
||||
lv_dropdown_set_options(dropdown, wake_timeout_options);
|
||||
lv_obj_set_width(dropdown, DROPDOWN_WIDTH);
|
||||
lv_obj_add_event_cb(dropdown, wake_timeout_dropdown, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
|
||||
int wake_timeout_settings_index = 0;
|
||||
for (int i = 0; i < SIZEOF(wake_timeout_options_values); i++){
|
||||
if (wake_timeout_options_values[i] == global_config.screen_timeout){
|
||||
lv_dropdown_set_selected(dropdown, i);
|
||||
wake_timeout_settings_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
create_settings_widget("Wake Timeout", dropdown, panel);
|
||||
lv_create_custom_menu_dropdown("Wake Timeout", panel, wake_timeout_dropdown, wake_timeout_options, wake_timeout_settings_index);
|
||||
#endif
|
||||
|
||||
dropdown = lv_dropdown_create(panel);
|
||||
lv_dropdown_set_options(dropdown, estimated_time_options);
|
||||
lv_obj_set_width(dropdown, DROPDOWN_WIDTH);
|
||||
lv_obj_add_event_cb(dropdown, estimated_time_dropdown, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
|
||||
lv_dropdown_set_selected(dropdown, get_current_printer_config()->remaining_time_calc_mode);
|
||||
create_settings_widget("Estimated Time", dropdown, panel);
|
||||
|
||||
toggle = lv_switch_create(panel);
|
||||
lv_obj_set_width(toggle, TOGGLE_WIDTH);
|
||||
lv_obj_add_event_cb(toggle, rotate_screen_switch, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
|
||||
if (global_config.rotate_screen)
|
||||
lv_obj_add_state(toggle, LV_STATE_CHECKED);
|
||||
|
||||
create_settings_widget("Rotate Screen", toggle, panel);
|
||||
lv_create_custom_menu_dropdown("Estimated Time", panel, estimated_time_dropdown, estimated_time_options, get_current_printer_config()->remaining_time_calc_mode);
|
||||
lv_create_custom_menu_switch("Rotate Screen", panel, rotate_screen_switch, global_config.rotate_screen);
|
||||
|
||||
#ifndef CYD_SCREEN_DISABLE_TIMEOUT
|
||||
toggle = lv_switch_create(panel);
|
||||
lv_obj_set_width(toggle, TOGGLE_WIDTH);
|
||||
lv_obj_add_event_cb(toggle, on_during_print_switch, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
|
||||
if (global_config.on_during_print)
|
||||
lv_obj_add_state(toggle, LV_STATE_CHECKED);
|
||||
|
||||
create_settings_widget("Screen On During Print", toggle, panel);
|
||||
lv_create_custom_menu_switch("Screen On During Print", panel, on_during_print_switch, global_config.on_during_print);
|
||||
#endif
|
||||
|
||||
toggle = lv_switch_create(panel);
|
||||
lv_obj_set_width(toggle, TOGGLE_WIDTH);
|
||||
lv_obj_add_event_cb(toggle, multi_printer_switch, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
lv_create_custom_menu_switch("Multi Printer Mode", panel, multi_printer_switch, global_config.multi_printer_mode);
|
||||
lv_create_custom_menu_switch("Auto Update", panel, auto_ota_update_switch, global_config.auto_ota_update);
|
||||
|
||||
if (global_config.multi_printer_mode)
|
||||
lv_obj_add_state(toggle, LV_STATE_CHECKED);
|
||||
|
||||
create_settings_widget("Multi Printer Mode", toggle, panel);
|
||||
|
||||
toggle = lv_switch_create(panel);
|
||||
lv_obj_set_width(toggle, TOGGLE_WIDTH);
|
||||
lv_obj_add_event_cb(toggle, auto_ota_update_switch, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
|
||||
if (global_config.auto_ota_update)
|
||||
lv_obj_add_state(toggle, LV_STATE_CHECKED);
|
||||
|
||||
create_settings_widget("Auto Update", toggle, panel);
|
||||
|
||||
label = lv_label_create(panel);
|
||||
lv_obj_t *label = lv_label_create(panel);
|
||||
lv_label_set_text(label, REPO_VERSION " ");
|
||||
|
||||
create_settings_widget("Version", label, panel, false);
|
||||
lv_create_custom_menu_entry("Version", label, panel, false);
|
||||
|
||||
if (ota_has_update()){
|
||||
btn = lv_btn_create(panel);
|
||||
lv_obj_t *btn = lv_btn_create(panel);
|
||||
lv_obj_add_event_cb(btn, btn_ota_do_update, LV_EVENT_CLICKED, NULL);
|
||||
|
||||
label = lv_label_create(btn);
|
||||
lv_label_set_text_fmt(label, "Update to %s", ota_new_version_name().c_str());
|
||||
lv_obj_center(label);
|
||||
|
||||
create_settings_widget("Device", btn, panel);
|
||||
lv_create_custom_menu_entry("Device", btn, panel);
|
||||
}
|
||||
else {
|
||||
label = lv_label_create(panel);
|
||||
lv_label_set_text(label, ARDUINO_BOARD " ");
|
||||
|
||||
create_settings_widget("Device", label, panel, false);
|
||||
lv_create_custom_menu_entry("Device", label, panel, false);
|
||||
}
|
||||
}
|
||||
@@ -67,11 +67,9 @@ void UpdateConfig(){
|
||||
}
|
||||
|
||||
static void keyboard_callback(lv_event_t * e){
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
lv_obj_t * ta = lv_event_get_target(e);
|
||||
lv_obj_t * kb = (lv_obj_t *)lv_event_get_user_data(e);
|
||||
|
||||
if (code == LV_EVENT_READY) {
|
||||
const char * text = lv_textarea_get_text(ta);
|
||||
|
||||
int temp = atoi(text);
|
||||
@@ -117,42 +115,14 @@ static void keyboard_callback(lv_event_t * e){
|
||||
}
|
||||
}
|
||||
|
||||
if(code == LV_EVENT_DEFOCUSED || code == LV_EVENT_CANCEL || code == LV_EVENT_READY) {
|
||||
lv_keyboard_set_textarea(kb, NULL);
|
||||
lv_obj_del(lv_obj_get_parent(kb));
|
||||
}
|
||||
}
|
||||
|
||||
static void show_keyboard(lv_event_t * e){
|
||||
lv_obj_t * parent = lv_create_empty_panel(root_panel);
|
||||
lv_obj_set_style_bg_opa(parent, LV_OPA_50, 0);
|
||||
lv_obj_set_size(parent, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_PANEL_HEIGHT_PX);
|
||||
lv_layout_flex_column(parent, LV_FLEX_ALIGN_SPACE_BETWEEN);
|
||||
|
||||
lv_obj_t * empty_panel = lv_create_empty_panel(parent);
|
||||
lv_obj_set_flex_grow(empty_panel, 1);
|
||||
|
||||
lv_obj_t * ta = lv_textarea_create(parent);
|
||||
lv_obj_t * keyboard = lv_keyboard_create(parent);
|
||||
|
||||
lv_obj_set_width(ta, CYD_SCREEN_PANEL_WIDTH_PX / 2);
|
||||
lv_textarea_set_max_length(ta, 3);
|
||||
lv_textarea_set_one_line(ta, true);
|
||||
lv_textarea_set_text(ta, "");
|
||||
lv_obj_add_event_cb(ta, keyboard_callback, LV_EVENT_ALL, keyboard);
|
||||
|
||||
lv_keyboard_set_mode(keyboard, LV_KEYBOARD_MODE_NUMBER);
|
||||
lv_keyboard_set_textarea(keyboard, ta);
|
||||
}
|
||||
|
||||
static void show_keyboard_with_hotend(lv_event_t * e){
|
||||
keyboard_target = TARGET_HOTEND;
|
||||
show_keyboard(e);
|
||||
lv_create_keyboard_text_entry(keyboard_callback);
|
||||
}
|
||||
|
||||
static void show_keyboard_with_bed(lv_event_t * e){
|
||||
keyboard_target = TARGET_BED;
|
||||
show_keyboard(e);
|
||||
lv_create_keyboard_text_entry(keyboard_callback);
|
||||
}
|
||||
|
||||
static void cooldown_temp(lv_event_t * e){
|
||||
@@ -179,7 +149,7 @@ static void set_temp_via_preset(lv_event_t * e){
|
||||
|
||||
if (edit_mode) {
|
||||
keyboard_target = (temp_target)target;
|
||||
show_keyboard(e);
|
||||
lv_create_keyboard_text_entry(keyboard_callback);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,3 +86,110 @@ void lv_create_fullscreen_button_matrix_popup(lv_obj_t * root, lv_event_cb_t tit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void lv_keyboard_text_entry_close(lv_event_t * e){
|
||||
lv_event_code_t code = lv_event_get_code(e);
|
||||
lv_obj_t * ta = lv_event_get_target(e);
|
||||
lv_obj_t * kb = (lv_obj_t *)lv_event_get_user_data(e);
|
||||
|
||||
if(code == LV_EVENT_DEFOCUSED || code == LV_EVENT_CANCEL || code == LV_EVENT_READY)
|
||||
{
|
||||
lv_keyboard_set_textarea(kb, NULL);
|
||||
lv_obj_del(lv_obj_get_parent(kb));
|
||||
}
|
||||
}
|
||||
|
||||
void lv_create_keyboard_text_entry(lv_event_cb_t keyboard_callback, lv_keyboard_mode_t keyboard_mode, lv_coord_t width, uint8_t max_length, const char* fill_text, bool contain_in_panel)
|
||||
{
|
||||
lv_obj_t * parent = lv_create_empty_panel(lv_scr_act());
|
||||
lv_obj_set_style_bg_opa(parent, LV_OPA_50, 0);
|
||||
lv_obj_align(parent, LV_ALIGN_TOP_RIGHT, 0, 0);
|
||||
lv_layout_flex_column(parent, LV_FLEX_ALIGN_SPACE_BETWEEN);
|
||||
|
||||
if (contain_in_panel)
|
||||
{
|
||||
lv_obj_set_size(parent, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_PANEL_HEIGHT_PX);
|
||||
}
|
||||
else
|
||||
{
|
||||
lv_obj_set_size(parent, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX);
|
||||
}
|
||||
|
||||
lv_obj_t * empty_panel = lv_create_empty_panel(parent);
|
||||
lv_obj_set_flex_grow(empty_panel, 1);
|
||||
|
||||
lv_obj_t * ta = lv_textarea_create(parent);
|
||||
lv_obj_t * keyboard = lv_keyboard_create(parent);
|
||||
|
||||
lv_obj_set_width(ta, width);
|
||||
lv_textarea_set_max_length(ta, max_length);
|
||||
lv_textarea_set_one_line(ta, true);
|
||||
lv_textarea_set_text(ta, fill_text);
|
||||
lv_obj_add_event_cb(ta, keyboard_callback, LV_EVENT_READY, keyboard);
|
||||
lv_obj_add_event_cb(ta, lv_keyboard_text_entry_close, LV_EVENT_ALL, keyboard);
|
||||
|
||||
lv_keyboard_set_mode(keyboard, keyboard_mode);
|
||||
lv_keyboard_set_textarea(keyboard, ta);
|
||||
}
|
||||
|
||||
const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2) * 0.85f), 0} };
|
||||
|
||||
void lv_create_custom_menu_entry(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel, bool set_height)
|
||||
{
|
||||
lv_obj_t * panel = lv_create_empty_panel(root_panel);
|
||||
lv_layout_flex_row(panel, LV_FLEX_ALIGN_END);
|
||||
lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
|
||||
|
||||
lv_obj_t * label = lv_label_create(panel);
|
||||
lv_label_set_text(label, label_text);
|
||||
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
|
||||
lv_obj_set_flex_grow(label, 1);
|
||||
|
||||
lv_obj_set_parent(object, panel);
|
||||
|
||||
if (set_height)
|
||||
lv_obj_set_height(object, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
|
||||
|
||||
lv_obj_t * line = lv_line_create(root_panel);
|
||||
lv_line_set_points(line, line_points, 2);
|
||||
lv_obj_set_style_line_width(line, 1, 0);
|
||||
lv_obj_set_style_line_color(line, lv_color_hex(0xAAAAAA), 0);
|
||||
}
|
||||
|
||||
#define DROPDOWN_WIDTH CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 3.75
|
||||
#define TOGGLE_WIDTH CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 2
|
||||
|
||||
void lv_create_custom_menu_button(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_click, const char *btn_text, void * user_data)
|
||||
{
|
||||
lv_obj_t * btn = lv_btn_create(lv_scr_act());
|
||||
lv_obj_add_event_cb(btn, on_click, LV_EVENT_CLICKED, user_data);
|
||||
|
||||
lv_obj_t * label = lv_label_create(btn);
|
||||
lv_label_set_text(label, btn_text);
|
||||
lv_obj_center(label);
|
||||
|
||||
lv_create_custom_menu_entry(label_text, btn, root_panel, true);
|
||||
}
|
||||
|
||||
void lv_create_custom_menu_switch(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_toggle, bool state, void * user_data)
|
||||
{
|
||||
lv_obj_t * toggle = lv_switch_create(lv_scr_act());
|
||||
lv_obj_add_event_cb(toggle, on_toggle, LV_EVENT_VALUE_CHANGED, user_data);
|
||||
lv_obj_set_width(toggle, TOGGLE_WIDTH);
|
||||
|
||||
if (state)
|
||||
lv_obj_add_state(toggle, LV_STATE_CHECKED);
|
||||
|
||||
lv_create_custom_menu_entry(label_text, toggle, root_panel, true);
|
||||
}
|
||||
|
||||
void lv_create_custom_menu_dropdown(const char *label_text, lv_obj_t *root_panel, lv_event_cb_t on_change, const char *options, int index, void * user_data)
|
||||
{
|
||||
lv_obj_t * dropdown = lv_dropdown_create(lv_scr_act());
|
||||
lv_dropdown_set_options(dropdown, options);
|
||||
lv_dropdown_set_selected(dropdown, index);
|
||||
lv_obj_set_width(dropdown, DROPDOWN_WIDTH);
|
||||
lv_obj_add_event_cb(dropdown, on_change, LV_EVENT_VALUE_CHANGED, user_data);
|
||||
|
||||
lv_create_custom_menu_entry(label_text, dropdown, root_panel, true);
|
||||
}
|
||||
@@ -38,3 +38,8 @@ void lv_layout_flex_column(lv_obj_t* obj, lv_flex_align_t allign = LV_FLEX_ALIGN
|
||||
void lv_layout_flex_row(lv_obj_t* obj, lv_flex_align_t allign = LV_FLEX_ALIGN_START, lv_coord_t pad_column = CYD_SCREEN_GAP_PX, lv_coord_t pad_row = CYD_SCREEN_GAP_PX);
|
||||
void lv_create_fullscreen_button_matrix_popup(lv_obj_t * root, lv_event_cb_t title, lv_button_column_t* columns, int column_count);
|
||||
void destroy_event_user_data(lv_event_t * e);
|
||||
void lv_create_keyboard_text_entry(lv_event_cb_t keyboard_callback, lv_keyboard_mode_t keyboard_mode = LV_KEYBOARD_MODE_NUMBER, lv_coord_t width = CYD_SCREEN_PANEL_WIDTH_PX / 2, uint8_t max_length = 3, const char* fill_text = "", bool contain_in_panel= true);
|
||||
void lv_create_custom_menu_entry(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel, bool set_height = true);
|
||||
void lv_create_custom_menu_button(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_click, const char *btn_text, void * user_data = NULL);
|
||||
void lv_create_custom_menu_switch(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_toggle, bool state, void * user_data = NULL);
|
||||
void lv_create_custom_menu_dropdown(const char *label_text, lv_obj_t *root_panel, lv_event_cb_t on_change, const char *options, int index, void * user_data = NULL);
|
||||
Reference in New Issue
Block a user