mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-07-28 01:05:58 -04:00
Formatted code (#1007)
* Updated style * Updated files * fixed new line * Updated spacing * File fix WIP * Updated to clang 13 * updated comment style * Removed old comment code
This commit is contained in:
parent
7aca7ce74d
commit
033c4e9a5b
599 changed files with 70746 additions and 66896 deletions
|
@ -29,176 +29,170 @@ namespace ui {
|
|||
/* BtnGridView **************************************************************/
|
||||
|
||||
BtnGridView::BtnGridView(
|
||||
Rect new_parent_rect,
|
||||
bool keep_highlight
|
||||
) : keep_highlight { keep_highlight }
|
||||
{
|
||||
set_parent_rect(new_parent_rect);
|
||||
Rect new_parent_rect,
|
||||
bool keep_highlight)
|
||||
: keep_highlight{keep_highlight} {
|
||||
set_parent_rect(new_parent_rect);
|
||||
|
||||
set_focusable(true);
|
||||
set_focusable(true);
|
||||
|
||||
signal_token_tick_second = rtc_time::signal_tick_second += [this]() {
|
||||
this->on_tick_second();
|
||||
};
|
||||
signal_token_tick_second = rtc_time::signal_tick_second += [this]() {
|
||||
this->on_tick_second();
|
||||
};
|
||||
|
||||
add_child(&arrow_more);
|
||||
arrow_more.set_focusable(false);
|
||||
arrow_more.set_foreground(Color::black());
|
||||
add_child(&arrow_more);
|
||||
arrow_more.set_focusable(false);
|
||||
arrow_more.set_foreground(Color::black());
|
||||
}
|
||||
|
||||
BtnGridView::~BtnGridView() {
|
||||
rtc_time::signal_tick_second -= signal_token_tick_second;
|
||||
rtc_time::signal_tick_second -= signal_token_tick_second;
|
||||
|
||||
for (auto item : menu_item_views) {
|
||||
delete item;
|
||||
}
|
||||
for (auto item : menu_item_views) {
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
void BtnGridView::set_max_rows(int rows) {
|
||||
rows_ = rows;
|
||||
rows_ = rows;
|
||||
}
|
||||
|
||||
int BtnGridView::rows() {
|
||||
return rows_;
|
||||
return rows_;
|
||||
}
|
||||
|
||||
void BtnGridView::set_parent_rect(const Rect new_parent_rect) {
|
||||
View::set_parent_rect(new_parent_rect);
|
||||
View::set_parent_rect(new_parent_rect);
|
||||
|
||||
displayed_max = (parent_rect().size().height() / button_h);
|
||||
arrow_more.set_parent_rect( { 228, (Coord)(displayed_max * button_h), 8, 8 } );
|
||||
displayed_max *= rows_;
|
||||
displayed_max = (parent_rect().size().height() / button_h);
|
||||
arrow_more.set_parent_rect({228, (Coord)(displayed_max * button_h), 8, 8});
|
||||
displayed_max *= rows_;
|
||||
|
||||
// TODO: Clean this up :(
|
||||
if (menu_item_views.size()) {
|
||||
// TODO: Clean this up :(
|
||||
if (menu_item_views.size()) {
|
||||
for (auto item : menu_item_views) {
|
||||
remove_child(item);
|
||||
delete item;
|
||||
}
|
||||
menu_item_views.clear();
|
||||
}
|
||||
|
||||
for (auto item : menu_item_views) {
|
||||
remove_child(item);
|
||||
delete item;
|
||||
}
|
||||
menu_item_views.clear();
|
||||
}
|
||||
button_w = 240 / rows_;
|
||||
for (size_t c = 0; c < displayed_max; c++) {
|
||||
auto item = new NewButton{};
|
||||
menu_item_views.push_back(item);
|
||||
add_child(item);
|
||||
|
||||
button_w = 240 / rows_;
|
||||
for (size_t c = 0; c < displayed_max; c++) {
|
||||
auto item = new NewButton { };
|
||||
menu_item_views.push_back(item);
|
||||
add_child(item);
|
||||
item->set_parent_rect({(int)(c % rows_) * button_w,
|
||||
(int)(c / rows_) * button_h,
|
||||
button_w, button_h});
|
||||
}
|
||||
|
||||
item->set_parent_rect({
|
||||
(int)(c % rows_) * button_w,
|
||||
(int)(c / rows_) * button_h,
|
||||
button_w, button_h
|
||||
});
|
||||
}
|
||||
|
||||
update_items();
|
||||
update_items();
|
||||
}
|
||||
|
||||
void BtnGridView::set_arrow_enabled(bool new_value) {
|
||||
if(new_value){
|
||||
add_child(&arrow_more);
|
||||
}
|
||||
else{
|
||||
remove_child(&arrow_more);
|
||||
}
|
||||
if (new_value) {
|
||||
add_child(&arrow_more);
|
||||
} else {
|
||||
remove_child(&arrow_more);
|
||||
}
|
||||
};
|
||||
|
||||
void BtnGridView::on_tick_second() {
|
||||
if (more && blink)
|
||||
arrow_more.set_foreground(Color::white());
|
||||
else
|
||||
arrow_more.set_foreground(Color::black());
|
||||
if (more && blink)
|
||||
arrow_more.set_foreground(Color::white());
|
||||
else
|
||||
arrow_more.set_foreground(Color::black());
|
||||
|
||||
blink = !blink;
|
||||
blink = !blink;
|
||||
|
||||
arrow_more.set_dirty();
|
||||
arrow_more.set_dirty();
|
||||
}
|
||||
|
||||
void BtnGridView::clear() {
|
||||
menu_items.clear();
|
||||
menu_items.clear();
|
||||
}
|
||||
|
||||
void BtnGridView::add_items(std::initializer_list<GridItem> new_items) {
|
||||
for (auto item : new_items) {
|
||||
menu_items.push_back(item);
|
||||
}
|
||||
update_items();
|
||||
for (auto item : new_items) {
|
||||
menu_items.push_back(item);
|
||||
}
|
||||
update_items();
|
||||
}
|
||||
|
||||
void BtnGridView::update_items() {
|
||||
size_t i = 0;
|
||||
size_t i = 0;
|
||||
|
||||
if ((menu_items.size()) > (displayed_max + offset)) {
|
||||
more = true;
|
||||
blink = true;
|
||||
} else
|
||||
more = false;
|
||||
if ((menu_items.size()) > (displayed_max + offset)) {
|
||||
more = true;
|
||||
blink = true;
|
||||
} else
|
||||
more = false;
|
||||
|
||||
for (NewButton* item : menu_item_views) {
|
||||
if ((i + offset) >= menu_items.size()) {
|
||||
item->hidden(true);
|
||||
item->set_text(" ");
|
||||
item->set_bitmap(nullptr);
|
||||
item->on_select = [](){};
|
||||
item->set_dirty();
|
||||
}
|
||||
else {
|
||||
// Assign item data to NewButtons according to offset
|
||||
item->hidden(false);
|
||||
item->set_text(menu_items[i + offset].text);
|
||||
item->set_bitmap(menu_items[i + offset].bitmap);
|
||||
item->set_color(menu_items[i + offset].color);
|
||||
item->on_select = menu_items[i + offset].on_select;
|
||||
item->set_dirty();
|
||||
}
|
||||
for (NewButton* item : menu_item_views) {
|
||||
if ((i + offset) >= menu_items.size()) {
|
||||
item->hidden(true);
|
||||
item->set_text(" ");
|
||||
item->set_bitmap(nullptr);
|
||||
item->on_select = []() {};
|
||||
item->set_dirty();
|
||||
} else {
|
||||
// Assign item data to NewButtons according to offset
|
||||
item->hidden(false);
|
||||
item->set_text(menu_items[i + offset].text);
|
||||
item->set_bitmap(menu_items[i + offset].bitmap);
|
||||
item->set_color(menu_items[i + offset].color);
|
||||
item->on_select = menu_items[i + offset].on_select;
|
||||
item->set_dirty();
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
NewButton* BtnGridView::item_view(size_t index) const {
|
||||
return menu_item_views[index];
|
||||
return menu_item_views[index];
|
||||
}
|
||||
|
||||
bool BtnGridView::set_highlighted(int32_t new_value) {
|
||||
int32_t item_count = (int32_t)menu_items.size();
|
||||
int32_t item_count = (int32_t)menu_items.size();
|
||||
|
||||
if (new_value < 0)
|
||||
return false;
|
||||
if (new_value < 0)
|
||||
return false;
|
||||
|
||||
if (new_value >= item_count)
|
||||
new_value = item_count - 1;
|
||||
if (new_value >= item_count)
|
||||
new_value = item_count - 1;
|
||||
|
||||
if (((uint32_t)new_value > offset) && ((new_value - offset) >= displayed_max)) {
|
||||
// Shift BtnGridView up
|
||||
highlighted_item = new_value;
|
||||
offset = new_value - displayed_max + rows_;
|
||||
update_items();
|
||||
set_dirty();
|
||||
} else if ((uint32_t)new_value < offset) {
|
||||
// Shift BtnGridView down
|
||||
highlighted_item = new_value;
|
||||
offset = (new_value / rows_) * rows_;
|
||||
update_items();
|
||||
set_dirty();
|
||||
} else {
|
||||
// Just update highlight
|
||||
highlighted_item = new_value;
|
||||
}
|
||||
if (((uint32_t)new_value > offset) && ((new_value - offset) >= displayed_max)) {
|
||||
// Shift BtnGridView up
|
||||
highlighted_item = new_value;
|
||||
offset = new_value - displayed_max + rows_;
|
||||
update_items();
|
||||
set_dirty();
|
||||
} else if ((uint32_t)new_value < offset) {
|
||||
// Shift BtnGridView down
|
||||
highlighted_item = new_value;
|
||||
offset = (new_value / rows_) * rows_;
|
||||
update_items();
|
||||
set_dirty();
|
||||
} else {
|
||||
// Just update highlight
|
||||
highlighted_item = new_value;
|
||||
}
|
||||
|
||||
if (visible())
|
||||
item_view(highlighted_item - offset)->focus();
|
||||
if (visible())
|
||||
item_view(highlighted_item - offset)->focus();
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t BtnGridView::highlighted_index() {
|
||||
return highlighted_item;
|
||||
return highlighted_item;
|
||||
}
|
||||
|
||||
void BtnGridView::on_focus() {
|
||||
item_view(highlighted_item - offset)->focus();
|
||||
item_view(highlighted_item - offset)->focus();
|
||||
}
|
||||
|
||||
void BtnGridView::on_blur() {
|
||||
|
@ -209,32 +203,32 @@ void BtnGridView::on_blur() {
|
|||
}
|
||||
|
||||
bool BtnGridView::on_key(const KeyEvent key) {
|
||||
switch(key) {
|
||||
case KeyEvent::Up:
|
||||
return set_highlighted(highlighted_item - rows_);
|
||||
switch (key) {
|
||||
case KeyEvent::Up:
|
||||
return set_highlighted(highlighted_item - rows_);
|
||||
|
||||
case KeyEvent::Down:
|
||||
return set_highlighted(highlighted_item + rows_);
|
||||
case KeyEvent::Down:
|
||||
return set_highlighted(highlighted_item + rows_);
|
||||
|
||||
case KeyEvent::Right:
|
||||
return set_highlighted(highlighted_item + 1);
|
||||
case KeyEvent::Right:
|
||||
return set_highlighted(highlighted_item + 1);
|
||||
|
||||
case KeyEvent::Left:
|
||||
return set_highlighted(highlighted_item - 1);
|
||||
case KeyEvent::Left:
|
||||
return set_highlighted(highlighted_item - 1);
|
||||
|
||||
case KeyEvent::Select:
|
||||
if( menu_items[highlighted_item].on_select ) {
|
||||
menu_items[highlighted_item].on_select();
|
||||
}
|
||||
return true;
|
||||
case KeyEvent::Select:
|
||||
if (menu_items[highlighted_item].on_select) {
|
||||
menu_items[highlighted_item].on_select();
|
||||
}
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool BtnGridView::on_encoder(const EncoderEvent event) {
|
||||
return set_highlighted(highlighted_item + event);
|
||||
return set_highlighted(highlighted_item + event);
|
||||
}
|
||||
|
||||
} /* namespace ui */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue