mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-01-09 19:03:38 +00:00
setting&autostart&widgets (OptionField and Waveform) imp (#2286)
* test * test * format * format * tune order
This commit is contained in:
parent
536d25db64
commit
d4edb5f5f9
@ -5,6 +5,7 @@
|
|||||||
* Copyright (C) 2023 Kyle Reed
|
* Copyright (C) 2023 Kyle Reed
|
||||||
* Copyright (C) 2024 Mark Thompson
|
* Copyright (C) 2024 Mark Thompson
|
||||||
* Copyright (C) 2024 u-foka
|
* Copyright (C) 2024 u-foka
|
||||||
|
* Copyright (C) 2024 HTotoo
|
||||||
* Copyleft (ɔ) 2024 zxkmm under GPL license
|
* Copyleft (ɔ) 2024 zxkmm under GPL license
|
||||||
*
|
*
|
||||||
* This file is part of PortaPack.
|
* This file is part of PortaPack.
|
||||||
@ -876,6 +877,7 @@ SetAutostartView::SetAutostartView(NavigationView& nav) {
|
|||||||
add_children({&labels,
|
add_children({&labels,
|
||||||
&button_save,
|
&button_save,
|
||||||
&button_cancel,
|
&button_cancel,
|
||||||
|
&button_reset,
|
||||||
&options});
|
&options});
|
||||||
|
|
||||||
button_save.on_select = [&nav, this](Button&) {
|
button_save.on_select = [&nav, this](Button&) {
|
||||||
@ -892,6 +894,12 @@ SetAutostartView::SetAutostartView(NavigationView& nav) {
|
|||||||
nav.pop();
|
nav.pop();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
button_reset.on_select = [this](Button&) {
|
||||||
|
selected = 0;
|
||||||
|
options.set_selected_index(0);
|
||||||
|
autostart_app = "";
|
||||||
|
};
|
||||||
|
|
||||||
// options
|
// options
|
||||||
i = 0;
|
i = 0;
|
||||||
OptionsField::option_t o{"-none-", i};
|
OptionsField::option_t o{"-none-", i};
|
||||||
|
@ -843,14 +843,19 @@ class SetAutostartView : public View {
|
|||||||
"Save"};
|
"Save"};
|
||||||
|
|
||||||
OptionsField options{
|
OptionsField options{
|
||||||
{8 * 8, 4 * 16},
|
{0 * 8, 4 * 16},
|
||||||
30,
|
screen_width / 8,
|
||||||
{}};
|
{},
|
||||||
|
true};
|
||||||
|
|
||||||
Button button_cancel{
|
Button button_cancel{
|
||||||
{16 * 8, 16 * 16, 12 * 8, 32},
|
{16 * 8, 16 * 16, 12 * 8, 32},
|
||||||
"Cancel",
|
"Cancel",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Button button_reset{
|
||||||
|
{2 * 8, 6 * 16, screen_width - 4 * 8, 32},
|
||||||
|
"Reset"};
|
||||||
};
|
};
|
||||||
|
|
||||||
class SetThemeView : public View {
|
class SetThemeView : public View {
|
||||||
@ -872,15 +877,16 @@ class SetThemeView : public View {
|
|||||||
"Save"};
|
"Save"};
|
||||||
|
|
||||||
OptionsField options{
|
OptionsField options{
|
||||||
{8 * 8, 4 * 16},
|
{0 * 8, 4 * 16},
|
||||||
30,
|
screen_width / 8,
|
||||||
{
|
{
|
||||||
{"Default - Grey", 0},
|
{"Default - Grey", 0},
|
||||||
{"Yellow", 1},
|
{"Yellow", 1},
|
||||||
{"Aqua", 2},
|
{"Aqua", 2},
|
||||||
{"Green", 3},
|
{"Green", 3},
|
||||||
{"Red", 4},
|
{"Red", 4},
|
||||||
}};
|
},
|
||||||
|
true};
|
||||||
|
|
||||||
Checkbox checkbox_menuset{
|
Checkbox checkbox_menuset{
|
||||||
{2 * 8, 6 * 16},
|
{2 * 8, 6 * 16},
|
||||||
|
@ -758,14 +758,30 @@ void NavigationView::handle_autostart() {
|
|||||||
"nav"sv,
|
"nav"sv,
|
||||||
{{"autostart_app"sv, &autostart_app}}};
|
{{"autostart_app"sv, &autostart_app}}};
|
||||||
if (!autostart_app.empty()) {
|
if (!autostart_app.empty()) {
|
||||||
if (StartAppByName(autostart_app.c_str())) return;
|
bool app_started = false;
|
||||||
// if returned false, check for external apps by that name, and try to start it
|
|
||||||
std::string appwithpath = "/" + apps_dir.string() + "/";
|
// try innerapp
|
||||||
appwithpath += autostart_app;
|
if (StartAppByName(autostart_app.c_str())) {
|
||||||
appwithpath += ".ppma";
|
app_started = true;
|
||||||
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> conv;
|
} else {
|
||||||
std::filesystem::path pth = conv.from_bytes(appwithpath.c_str());
|
// try outside app
|
||||||
ui::ExternalItemsMenuLoader::run_external_app(*this, pth);
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1697,10 +1697,12 @@ bool ImageOptionsField::on_touch(const TouchEvent event) {
|
|||||||
OptionsField::OptionsField(
|
OptionsField::OptionsField(
|
||||||
Point parent_pos,
|
Point parent_pos,
|
||||||
size_t length,
|
size_t length,
|
||||||
options_t options)
|
options_t options,
|
||||||
|
bool centered)
|
||||||
: Widget{{parent_pos, {8 * (int)length, 16}}},
|
: Widget{{parent_pos, {8 * (int)length, 16}}},
|
||||||
length_{length},
|
length_{length},
|
||||||
options_{std::move(options)} {
|
options_{std::move(options)},
|
||||||
|
centered_{centered} {
|
||||||
set_focusable(true);
|
set_focusable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1792,8 +1794,19 @@ void OptionsField::paint(Painter& painter) {
|
|||||||
std::string_view temp = selected_index_name();
|
std::string_view temp = selected_index_name();
|
||||||
if (temp.length() > length_)
|
if (temp.length() > length_)
|
||||||
temp = temp.substr(0, 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(
|
painter.draw_string(
|
||||||
screen_pos(),
|
draw_pos,
|
||||||
paint_style,
|
paint_style,
|
||||||
temp);
|
temp);
|
||||||
}
|
}
|
||||||
@ -2622,6 +2635,8 @@ void Waveform::set_length(const uint32_t new_length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Waveform::paint(Painter& painter) {
|
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;
|
size_t n;
|
||||||
Coord y, y_offset = screen_rect().location().y();
|
Coord y, y_offset = screen_rect().location().y();
|
||||||
Coord prev_x = screen_rect().location().x(), prev_y;
|
Coord prev_x = screen_rect().location().x(), prev_y;
|
||||||
@ -2642,7 +2657,7 @@ void Waveform::paint(Painter& painter) {
|
|||||||
x = 0;
|
x = 0;
|
||||||
h--;
|
h--;
|
||||||
for (n = 0; n < length_; n++) {
|
for (n = 0; n < length_; n++) {
|
||||||
y = *(data_start++) ? h : 0;
|
y = *(data_start++) ? 0 : h;
|
||||||
|
|
||||||
if (n) {
|
if (n) {
|
||||||
if (y != prev_y)
|
if (y != prev_y)
|
||||||
@ -2658,9 +2673,10 @@ void Waveform::paint(Painter& painter) {
|
|||||||
// Analog waveform: each value is a point's Y coordinate
|
// Analog waveform: each value is a point's Y coordinate
|
||||||
x = prev_x + x_inc;
|
x = prev_x + x_inc;
|
||||||
h /= 2;
|
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++) {
|
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_);
|
display.draw_line({prev_x, prev_y}, {(Coord)x, y}, color_);
|
||||||
|
|
||||||
prev_x = x;
|
prev_x = x;
|
||||||
|
@ -680,7 +680,7 @@ class OptionsField : public Widget {
|
|||||||
std::function<void(size_t, value_t)> on_change{};
|
std::function<void(size_t, value_t)> on_change{};
|
||||||
std::function<void(void)> on_show_options{};
|
std::function<void(void)> 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_; }
|
options_t& options() { return options_; }
|
||||||
const options_t& options() const { return options_; }
|
const options_t& options() const { return options_; }
|
||||||
@ -708,6 +708,7 @@ class OptionsField : public Widget {
|
|||||||
const size_t length_;
|
const size_t length_;
|
||||||
options_t options_;
|
options_t options_;
|
||||||
size_t selected_index_{0};
|
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
|
// A TextEdit is bound to a string reference and allows the string
|
||||||
@ -1036,4 +1037,4 @@ class OptionTabView : public View {
|
|||||||
|
|
||||||
} /* namespace ui */
|
} /* namespace ui */
|
||||||
|
|
||||||
#endif /*__UI_WIDGET_H__*/
|
#endif /*__UI_WIDGET_H__*/
|
Loading…
x
Reference in New Issue
Block a user