Skip to content

Commit

Permalink
Add close button to alert dialogs
Browse files Browse the repository at this point in the history
Refs: #99
  • Loading branch information
orontee committed Nov 13, 2024
1 parent 5738423 commit acabdbf
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Added

- Add close button to alert dialogs
[#99](https://github.com/orontee/taranis/issues/99)

- Add icons to sunrise and sunset lines
[#95](https://github.com/orontee/taranis/issues/95)

Expand Down
23 changes: 22 additions & 1 deletion src/alerts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ namespace taranis {
void AlertsButton::on_clicked() { this->viewer->open(); }

AlertViewer::AlertViewer(std::shared_ptr<Model> model,
std::shared_ptr<Icons> icons,
std::shared_ptr<Fonts> fonts)
: ModalWidget{}, model{model}, fonts{fonts},
: ModalWidget{}, model{model}, icons{icons}, fonts{fonts},
content_width{this->bounding_box.w - 2 * AlertViewer::horizontal_padding},
title_height{2 * this->fonts->get_small_font()->height},
alert_title_start_y{this->title_height + AlertViewer::vertical_padding} {}
Expand Down Expand Up @@ -61,6 +62,20 @@ void AlertViewer::do_paint() {
this->content_width, this->title_height,
this->title_text.c_str(), ALIGN_CENTER);

if (!this->close_button) {
const auto close_button_icon_size =
default_font->height + AlertViewer::vertical_padding;

this->close_button =
std::make_shared<CloseButton>(close_button_icon_size, this->icons);
this->close_button->set_click_handler(std::bind(&AlertViewer::hide, this));
this->close_button->set_pos_x(this->get_width() - close_button_icon_size -
AlertViewer::horizontal_padding);
this->close_button->set_pos_y(this->get_pos_y() +
AlertViewer::vertical_padding / 4);
}
this->close_button->do_paint();

DrawHorizontalSeparator(0, this->title_height, ScreenWidth(),
HORIZONTAL_SEPARATOR_SOLID);

Expand Down Expand Up @@ -210,6 +225,12 @@ int AlertViewer::handle_pointer_event(int event_type, int pointer_pos_x,
return 1;
}
}
if (this->close_button and
this->close_button->is_in_bouding_box(pointer_pos_x, pointer_pos_y) and
this->close_button->is_enabled()) {
return this->close_button->handle_pointer_event(event_type, pointer_pos_x,
pointer_pos_y);
}
return 0;
}

Expand Down
7 changes: 6 additions & 1 deletion src/alerts.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <vector>

#include "button.h"
#include "closebutton.h"
#include "fonts.h"
#include "icons.h"
#include "model.h"
Expand Down Expand Up @@ -35,7 +36,8 @@ class AlertsButton : public Button {

class AlertViewer : public ModalWidget {
public:
AlertViewer(std::shared_ptr<Model> model, std::shared_ptr<Fonts> fonts);
AlertViewer(std::shared_ptr<Model> model, std::shared_ptr<Icons> icons,
std::shared_ptr<Fonts> fonts);

void open();

Expand All @@ -53,8 +55,11 @@ class AlertViewer : public ModalWidget {
static constexpr int vertical_padding{25};

std::shared_ptr<Model> model;
std::shared_ptr<Icons> icons;
std::shared_ptr<Fonts> fonts;

std::shared_ptr<CloseButton> close_button;

size_t alert_index{0};

const int content_width;
Expand Down
3 changes: 2 additions & 1 deletion src/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ Ui::Ui(std::shared_ptr<Config> config, std::shared_ptr<Model> model)
menu_button->set_pos_y(Ui::button_margin);
menu_button->set_menu_handler(&handle_menu_item_selected);

this->alert_viewer = std::make_shared<AlertViewer>(model, this->fonts);
this->alert_viewer =
std::make_shared<AlertViewer>(model, this->icons, this->fonts);
this->daily_forecast_viewer =
std::make_shared<DailyForecastViewer>(model, this->icons, this->fonts);

Expand Down

0 comments on commit acabdbf

Please sign in to comment.