diff --git a/firmware/application/apps/ui_settings.cpp b/firmware/application/apps/ui_settings.cpp index 3988014e2..36e3b3811 100644 --- a/firmware/application/apps/ui_settings.cpp +++ b/firmware/application/apps/ui_settings.cpp @@ -5,6 +5,7 @@ * Copyright (C) 2023 Kyle Reed * Copyright (C) 2024 Mark Thompson * Copyright (C) 2024 u-foka + * Copyright (C) 2024 HTotoo * Copyleft (ɔ) 2024 zxkmm under GPL license * * This file is part of PortaPack. @@ -876,6 +877,7 @@ SetAutostartView::SetAutostartView(NavigationView& nav) { add_children({&labels, &button_save, &button_cancel, + &button_reset, &options}); button_save.on_select = [&nav, this](Button&) { @@ -892,6 +894,12 @@ SetAutostartView::SetAutostartView(NavigationView& nav) { nav.pop(); }; + button_reset.on_select = [this](Button&) { + selected = 0; + options.set_selected_index(0); + autostart_app = ""; + }; + // options i = 0; OptionsField::option_t o{"-none-", i}; diff --git a/firmware/application/apps/ui_settings.hpp b/firmware/application/apps/ui_settings.hpp index 4a94d90cd..b3e215e87 100644 --- a/firmware/application/apps/ui_settings.hpp +++ b/firmware/application/apps/ui_settings.hpp @@ -843,14 +843,19 @@ class SetAutostartView : public View { "Save"}; OptionsField options{ - {8 * 8, 4 * 16}, - 30, - {}}; + {0 * 8, 4 * 16}, + screen_width / 8, + {}, + true}; Button button_cancel{ {16 * 8, 16 * 16, 12 * 8, 32}, "Cancel", }; + + Button button_reset{ + {2 * 8, 6 * 16, screen_width - 4 * 8, 32}, + "Reset"}; }; class SetThemeView : public View { @@ -872,15 +877,16 @@ class SetThemeView : public View { "Save"}; OptionsField options{ - {8 * 8, 4 * 16}, - 30, + {0 * 8, 4 * 16}, + screen_width / 8, { {"Default - Grey", 0}, {"Yellow", 1}, {"Aqua", 2}, {"Green", 3}, {"Red", 4}, - }}; + }, + true}; Checkbox checkbox_menuset{ {2 * 8, 6 * 16}, diff --git a/firmware/application/ui_navigation.cpp b/firmware/application/ui_navigation.cpp index 59afe8d79..c5832b960 100644 --- a/firmware/application/ui_navigation.cpp +++ b/firmware/application/ui_navigation.cpp @@ -758,14 +758,30 @@ void NavigationView::handle_autostart() { "nav"sv, {{"autostart_app"sv, &autostart_app}}}; if (!autostart_app.empty()) { - if (StartAppByName(autostart_app.c_str())) return; - // if returned false, check for external apps by that name, and try to start it - std::string appwithpath = "/" + apps_dir.string() + "/"; - appwithpath += autostart_app; - appwithpath += ".ppma"; - std::wstring_convert, char16_t> conv; - std::filesystem::path pth = conv.from_bytes(appwithpath.c_str()); - ui::ExternalItemsMenuLoader::run_external_app(*this, pth); + bool app_started = false; + + // try innerapp + if (StartAppByName(autostart_app.c_str())) { + app_started = true; + } else { + // try outside app + auto external_items = ExternalItemsMenuLoader::load_external_items(app_location_t::HOME, *this); + for (const auto& item : external_items) { + if (item.text == autostart_app) { + item.on_select(); + app_started = true; + break; + } + } + } + + if (!app_started) { + display_modal( + "Notice", "Autostart failed:\n" + + autostart_app + + "\nupdate sdcard content\n" + + "and check if .ppma exists"); + } } } diff --git a/firmware/common/ui_widget.cpp b/firmware/common/ui_widget.cpp index 5af3af6e3..1724f3194 100644 --- a/firmware/common/ui_widget.cpp +++ b/firmware/common/ui_widget.cpp @@ -1697,10 +1697,12 @@ bool ImageOptionsField::on_touch(const TouchEvent event) { OptionsField::OptionsField( Point parent_pos, size_t length, - options_t options) + options_t options, + bool centered) : Widget{{parent_pos, {8 * (int)length, 16}}}, length_{length}, - options_{std::move(options)} { + options_{std::move(options)}, + centered_{centered} { set_focusable(true); } @@ -1792,8 +1794,19 @@ void OptionsField::paint(Painter& painter) { std::string_view temp = selected_index_name(); if (temp.length() > length_) temp = temp.substr(0, length_); + + Point draw_pos = screen_pos(); + if (centered_) { + // 8 is because big font width is 8px + // type is from: struct Point : constexpr int x() const + int text_width = temp.length() * 8; + int available_width = length_ * 8; + int x_offset = (available_width - text_width) / 2; + draw_pos = {draw_pos.x() + x_offset, draw_pos.y()}; + } + painter.draw_string( - screen_pos(), + draw_pos, paint_style, temp); } @@ -2622,6 +2635,8 @@ void Waveform::set_length(const uint32_t new_length) { } void Waveform::paint(Painter& painter) { + // previously it's upside down , low level is up and high level is down, which doesn't make sense, + // if that was made for a reason, feel free to revert. size_t n; Coord y, y_offset = screen_rect().location().y(); Coord prev_x = screen_rect().location().x(), prev_y; @@ -2642,7 +2657,7 @@ void Waveform::paint(Painter& painter) { x = 0; h--; for (n = 0; n < length_; n++) { - y = *(data_start++) ? h : 0; + y = *(data_start++) ? 0 : h; if (n) { if (y != prev_y) @@ -2658,9 +2673,10 @@ void Waveform::paint(Painter& painter) { // Analog waveform: each value is a point's Y coordinate x = prev_x + x_inc; h /= 2; - prev_y = y_offset + h - (*(data_start++) * y_scale); + + prev_y = y_offset + h + (*(data_start++) * y_scale); for (n = 1; n < length_; n++) { - y = y_offset + h - (*(data_start++) * y_scale); + y = y_offset + h + (*(data_start++) * y_scale); display.draw_line({prev_x, prev_y}, {(Coord)x, y}, color_); prev_x = x; diff --git a/firmware/common/ui_widget.hpp b/firmware/common/ui_widget.hpp index 1e9504708..43a80e019 100644 --- a/firmware/common/ui_widget.hpp +++ b/firmware/common/ui_widget.hpp @@ -680,7 +680,7 @@ class OptionsField : public Widget { std::function on_change{}; std::function on_show_options{}; - OptionsField(Point parent_pos, size_t length, options_t options); + OptionsField(Point parent_pos, size_t length, options_t options, bool centered = false); options_t& options() { return options_; } const options_t& options() const { return options_; } @@ -708,6 +708,7 @@ class OptionsField : public Widget { const size_t length_; options_t options_; size_t selected_index_{0}; + bool centered_{false}; // e.g.: length as screen_width/8, x position as 0, it will be centered in x axis }; // A TextEdit is bound to a string reference and allows the string @@ -1036,4 +1037,4 @@ class OptionTabView : public View { } /* namespace ui */ -#endif /*__UI_WIDGET_H__*/ +#endif /*__UI_WIDGET_H__*/ \ No newline at end of file