Added utilities > Frequency manager + load/save

This commit is contained in:
furrtek 2016-12-26 01:31:38 +01:00
parent ad2a4b6743
commit 7df5987b3b
21 changed files with 526 additions and 219 deletions

View file

@ -46,7 +46,7 @@ void MenuItemView::unhighlight() {
void MenuItemView::paint(Painter& painter) {
const auto r = screen_rect();
const auto paint_style = (highlighted() && parent()->has_focus()) ? style().invert() : style();
const auto paint_style = (highlighted() && (parent()->has_focus() || keep_highlight_)) ? style().invert() : style();
const auto font_height = paint_style.font.line_height();
@ -75,15 +75,18 @@ void MenuItemView::paint(Painter& painter) {
/* MenuView **************************************************************/
MenuView::MenuView() {
MenuView::MenuView(
bool keep_highlight
) : keep_highlight_ { keep_highlight }
{
set_focusable(true);
add_child(&arrow_more);
signal_token_tick_second = time::signal_tick_second += [this]() {
this->on_tick_second();
};
arrow_more.set_parent_rect( { 216, 320 - 16 - 24, 16, 16 } );
add_child(&arrow_more);
arrow_more.id = 1; // Special flag
arrow_more.set_focusable(false);
arrow_more.set_foreground(Color::black());
}
@ -97,39 +100,47 @@ void MenuView::on_tick_second() {
arrow_more.set_foreground(Color::white());
else
arrow_more.set_foreground(Color::black());
blink_ = !blink_;
arrow_more.set_dirty();
}
void MenuView::clear() {
children_.erase(children_.begin() + 1, children_.end());
}
void MenuView::add_item(const MenuItem item) {
add_child(new MenuItemView { item });
add_child(new MenuItemView { item, keep_highlight_ });
}
void MenuView::set_parent_rect(const Rect new_parent_rect) {
View::set_parent_rect(new_parent_rect);
displayed_max_ = new_parent_rect.size.h / 24;
arrow_more.set_parent_rect( { 228, (Coord)(displayed_max_ * item_height), 8, 8 } );
update_items();
}
void MenuView::update_items() {
constexpr size_t item_height = 24;
size_t i = 0;
Coord y_pos;
int32_t y_pos;
if ((children_.size() - 1) > MENU_MAX + offset_)
if ((children_.size() - 1) > displayed_max_ + offset_) {
more_ = true;
else
blink_ = true;
} else
more_ = false;
for (auto child : children_) {
if (i) { // Skip arrow widget
y_pos = (i - 1 - offset_) * item_height;
if (!child->id) {
y_pos = (i - offset_ - 1) * item_height;
child->set_parent_rect({
{ 0, y_pos },
{ size().w, item_height }
{ size().w, (Coord)item_height }
});
if ((y_pos < 0) || (y_pos >= (320 - 16 - 24 - 16)))
if ((y_pos < 0) || (y_pos > (Coord)(screen_rect().size.h - item_height)))
child->hidden(true);
else
child->hidden(false);
@ -142,20 +153,24 @@ MenuItemView* MenuView::item_view(size_t index) const {
/* TODO: Terrible cast! Take it as a sign I must be doing something
* shamefully wrong here, right?
*/
return static_cast<MenuItemView*>(children_[index + 1]); // Skip arrow widget
return static_cast<MenuItemView*>(children_[index + 1]);
}
size_t MenuView::highlighted() const {
return highlighted_;
}
bool MenuView::set_highlighted(const size_t new_value) {
if( new_value >= (children_.size() - 1) ) // Skip arrow widget
bool MenuView::set_highlighted(int32_t new_value) {
int32_t item_count = (int32_t)children_.size() - 1;
if (new_value < 0)
return false;
if ((new_value > offset_) && ((new_value - offset_ + 1) >= MENU_MAX)) {
if (new_value >= item_count)
new_value = item_count - 1;
if ((new_value > offset_) && ((new_value - offset_ + 1) >= displayed_max_)) {
// Shift MenuView up
offset_ = new_value - MENU_MAX + 1;
offset_ = new_value - displayed_max_ + 1;
update_items();
} else if (new_value < offset_) {
// Shift MenuView down
@ -175,7 +190,7 @@ void MenuView::on_focus() {
}
void MenuView::on_blur() {
item_view(highlighted())->unhighlight();
if (!keep_highlight_) item_view(highlighted())->unhighlight();
}
bool MenuView::on_key(const KeyEvent key) {