From 7fc66610dca0d7b769ba4a65ea28590677da5597 Mon Sep 17 00:00:00 2001 From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Date: Fri, 8 Mar 2024 16:54:00 +0100 Subject: [PATCH] Automatic Font Size Adjustment for Entity Page Values Solves #1728 --- ReleaseNotes.md | 6 ++++++ esphome/nspanel_esphome_core.yaml | 22 +++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ReleaseNotes.md b/ReleaseNotes.md index d5dd9af..09be3cb 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -87,6 +87,7 @@ Our community and support channels are open for any questions or assistance you - [Introducing the Utilities Dashboard](#introducing-the-utilities-dashboard) - [Expanded Support for "Lock" Entities on Buttons and Chips](#expanded-support-for-lock-entities-on-buttons-and-chips) - [Additional Value on Home Page](#additional-value-on-home-page) +- [Automatic Font Size Adjustment for Entity Page Values](#automatic-font-size-adjustment-for-entity-page-values) ## Details of noteworthy changes ### Transition to ESP-IDF as Default Framework @@ -213,6 +214,11 @@ Whether securing your home or managing access to different areas, these updates In our continuous effort to enhance the NSPanel's utility and efficiency, we're pleased to announce that the Home page now accommodates a fourth value, complete with its icon. This addition allows for a more comprehensive at-a-glance view of your essential metrics directly from the home screen, ensuring that crucial information is always just a glance away. +### Automatic Font Size Adjustment for Entity Page Values +We've enhanced the entities pages with an automatic font size adjustment feature to improve the display of values, especially for longer strings or values with lengthy units. +This smart adjustment reduces the occurrence of truncated values by dynamically resizing the font based on the string length. +While the selection of fonts for the panel remains limited, this automatic resizing significantly enhances readability, ensuring that all displayed information is clear and fully visible at a glance. + ## Support For support or more information about this update, visit our [GitHub repository](https://github.com/Blackymas/NSPanel_HA_Blueprint) diff --git a/esphome/nspanel_esphome_core.yaml b/esphome/nspanel_esphome_core.yaml index 00e5aec..b4ce2a5 100644 --- a/esphome/nspanel_esphome_core.yaml +++ b/esphome/nspanel_esphome_core.yaml @@ -802,6 +802,26 @@ api: disp1->set_component_font_color(id.c_str(), esphome::display::ColorUtil::color_to_565(esphome::Color(value_color[0], value_color[1], value_color[2]))); + if (current_page->state.find("entitypage") == 0 and !(value.empty())) { // Adjust value's font on entities pages + // Adjusted length starts at 0 + float adjusted_length = 0.0; + + // Iterate over each character in the string + for (char const &c: value) { + // Check if character is a space or other specified exceptions + if (std::string(" iljtIf'-,;:!.\"|()[]{}").find(c) != std::string::npos) { + adjusted_length += 0.5; // Count these as half + } else { + adjusted_length += 1.0; // Count all other characters as 1 + } + } + // Decide which font to use based on adjusted length + if (adjusted_length > 8.0 and adjusted_length <= 12.0) { + disp1->send_command_printf("%s.font=1", id.c_str()); + } else if (adjusted_length > 12.0) { + disp1->send_command_printf("%s.font=0", id.c_str()); + } + } } # Wake Up Service @@ -1035,7 +1055,7 @@ globals: initial_value: '6' - id: screensaver_display_time_color type: uint16_t - restore_value: false + restore_value: true initial_value: '16904' - id: page_entity_value_horizontal_alignment