Prepare for display orientation part 1 (#2661)

This commit is contained in:
Totoo
2025-05-22 17:24:53 +02:00
committed by GitHub
parent 6f6d863a14
commit a1d7cf2b86
85 changed files with 405 additions and 334 deletions

View File

@@ -76,10 +76,30 @@ int BtnGridView::rows() {
void BtnGridView::set_parent_rect(const Rect new_parent_rect) {
View::set_parent_rect(new_parent_rect);
button_h = 48; // btn_h_min;
/*
// DISABLED FOR NOW. TODO fix next, prev button pos
int min_remainder = parent_rect().size().height();
uint8_t max_button_count = 0;
for (int h = btn_h_min; h <= btn_h_max; ++h) {
int count = parent_rect().size().height() / h;
int remainder = parent_rect().size().height() % h;
// Prefer smaller remainder, then more buttons, then larger height
if (remainder < min_remainder ||
(remainder == min_remainder && count > max_button_count) ||
(remainder == min_remainder && count == max_button_count && h > button_h)) {
button_h = h;
min_remainder = remainder;
max_button_count = count;
}
}
*/
displayed_max = (parent_rect().size().height() / button_h);
button_pgup.set_parent_rect({0, (Coord)(displayed_max * button_h), 120, 16});
button_pgdown.set_parent_rect({120, (Coord)(displayed_max * button_h), 120, 16});
button_pgup.set_parent_rect({0, (Coord)(displayed_max * button_h), screen_width / 2, 16});
button_pgdown.set_parent_rect({screen_width / 2, (Coord)(displayed_max * button_h), screen_width / 2, 16});
displayed_max *= rows_;

View File

@@ -55,7 +55,7 @@ void load_blacklist();
class BtnGridView : public View {
public:
BtnGridView(Rect new_parent_rect = {0, 0, 240, 304}, bool keep_highlight = false);
BtnGridView(Rect new_parent_rect = {0, 0, screen_width, screen_height - 16}, bool keep_highlight = false);
~BtnGridView();
@@ -89,27 +89,33 @@ class BtnGridView : public View {
bool blacklisted_app(GridItem new_item);
void update_items();
void set_btn_min_max_height(uint8_t min, uint8_t max) {
btn_h_min = min;
btn_h_max = max;
}
protected:
virtual void on_populate() = 0;
private:
int rows_{3};
uint8_t btn_h_min{40};
uint8_t btn_h_max{60};
bool keep_highlight{false};
std::vector<GridItem> menu_items{};
std::vector<std::unique_ptr<NewButton>> menu_item_views{};
Button button_pgup{
{0, 324, 120, 16},
{0, 1324, 120, 16},
" "};
Button button_pgdown{
{121, 324, 119, 16},
{121, 1324, 119, 16},
" "};
int button_w = 240 / rows_;
static constexpr int button_h = 48;
int button_w = screen_width / rows_;
int button_h = 48;
size_t displayed_max{0};
size_t highlighted_item{0};
size_t offset{0};

View File

@@ -226,7 +226,7 @@ class FrequencyKeypadView : public View {
static constexpr int text_digits = mhz_digits + 1 + submhz_digits;
Text text_value{
{0, 4, 240, 16}};
{0, 4, screen_width, 16}};
std::array<Button, 12> buttons{};

View File

@@ -135,7 +135,7 @@ TabView::TabView(std::initializer_list<TabDef> tab_definitions) {
if (n_tabs > MAX_TABS)
n_tabs = MAX_TABS;
size_t tab_width = 240 / n_tabs;
size_t tab_width = screen_width / n_tabs;
set_parent_rect({0, 0, 30 * 8, 3 * 8});