Skip to content

Commit

Permalink
Display dialog with daily conditions details
Browse files Browse the repository at this point in the history
Refs: #16
  • Loading branch information
orontee committed Aug 4, 2024
1 parent a3dd2c3 commit 389c32f
Show file tree
Hide file tree
Showing 12 changed files with 527 additions and 17 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Add icons to sunrise and sunset lines
[#95](https://github.com/orontee/taranis/issues/95)

- Display dialog with daily conditions details
[#16](https://github.com/orontee/taranis/issues/16)

### Changed

### Removed
Expand Down
5 changes: 3 additions & 2 deletions src/alerts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ void AlertViewer::open() {
}
this->visible = true;

const auto &alert = this->model->alerts.at(this->alert_index);
this->update_title_text();

const auto &alert = this->model->alerts.at(this->alert_index);
this->update_alert_title_text(alert);
this->update_description_text(alert);

Expand Down Expand Up @@ -69,7 +70,7 @@ void AlertViewer::do_paint() {

const auto alert_title_height = TextRectHeight(
this->content_width, this->alert_title_text.c_str(), ALIGN_LEFT);
DrawTextRect(AlertViewer::horizontal_padding, alert_title_start_y,
DrawTextRect(AlertViewer::horizontal_padding, this->alert_title_start_y,
this->content_width, alert_title_height,
this->alert_title_text.c_str(), ALIGN_LEFT);

Expand Down
32 changes: 27 additions & 5 deletions src/dailyforecastbox.cc
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#include "dailyforecastbox.h"

#include <algorithm>

#include "dailyforecastviewer.h"
#include "units.h"
#include "util.h"

namespace taranis {
DailyForecastBox::DailyForecastBox(int pos_x, int pos_y, int width, int height,
std::shared_ptr<Model> model,
std::shared_ptr<Icons> icons,
std::shared_ptr<Fonts> fonts)
DailyForecastBox::DailyForecastBox(
int pos_x, int pos_y, int width, int height, std::shared_ptr<Model> model,
std::shared_ptr<Icons> icons, std::shared_ptr<Fonts> fonts,
std::shared_ptr<DailyForecastViewer> daily_forecast_viewer)
: Widget{pos_x, pos_y, width, height}, model{model}, icons{icons},
fonts{fonts} {
fonts{fonts}, viewer{daily_forecast_viewer} {
this->row_height = this->bounding_box.h / DailyForecastBox::row_count;
}

Expand All @@ -18,6 +21,16 @@ void DailyForecastBox::do_paint() {
this->draw_frame();
}

int DailyForecastBox::handle_pointer_event(int event_type, int pointer_pos_x,
int pointer_pos_y) {
// check pos on frame, identify forecast index, set viewer forecast index
if (event_type == EVT_POINTERUP) {
this->on_clicked_at(pointer_pos_x, pointer_pos_y);
return 1;
}
return 0;
}

std::pair<std::string, std::string>
DailyForecastBox::generate_precipitation_column_content(
const DailyCondition &forecast) const {
Expand Down Expand Up @@ -284,4 +297,13 @@ void DailyForecastBox::draw_values() {
}
}
}

void DailyForecastBox::on_clicked_at(int pointer_pos_x, int pointer_pos_y) {
if (this->viewer) {
const auto row_index = static_cast<size_t>(
std::max(0, pointer_pos_y - this->bounding_box.y) / this->row_height);
this->viewer->set_forecast_index(row_index);
this->viewer->open();
}
}
} // namespace taranis
13 changes: 11 additions & 2 deletions src/dailyforecastbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@ using namespace std::string_literals;

namespace taranis {

class DailyForecastViewer;

class DailyForecastBox : public Widget {
public:
DailyForecastBox(int pos_x, int pos_y, int width, int height,
std::shared_ptr<Model> model, std::shared_ptr<Icons> icons,
std::shared_ptr<Fonts> fonts);
std::shared_ptr<Fonts> fonts,
std::shared_ptr<DailyForecastViewer> daily_forecast_viewer);

void do_paint() override;

int handle_pointer_event(int event_type, int pointer_pos_x,
int pointer_pos_y) override;

private:
static constexpr size_t row_count{8};
static constexpr size_t column_count{9};
Expand All @@ -44,6 +50,8 @@ class DailyForecastBox : public Widget {
std::shared_ptr<Icons> icons;
std::shared_ptr<Fonts> fonts;

std::shared_ptr<DailyForecastViewer> viewer;

TableContent table_content;

int row_height;
Expand Down Expand Up @@ -80,6 +88,7 @@ class DailyForecastBox : public Widget {
void draw_frame() const;

void draw_values();
};

void on_clicked_at(int pointer_pos_x, int pointer_pos_y);
};
} // namespace taranis
Loading

0 comments on commit 389c32f

Please sign in to comment.