Skip to content

Commit

Permalink
Add close button to daily forecast dialog
Browse files Browse the repository at this point in the history
Refs: #16
  • Loading branch information
orontee committed Nov 3, 2024
1 parent 20a9dcd commit fbd5a1d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 0 deletions.
Binary file added icons/icon_close.bmp
Binary file not shown.
1 change: 1 addition & 0 deletions icons/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ icons = files(
'icon_11n_2x.bmp',
'icon_13n_2x.bmp',
'icon_50n_2x.bmp',
'icon_close.bmp',
'icon_direction.bmp',
'icon_display_settings.bmp',
'icon_favorite.bmp',
Expand Down
32 changes: 32 additions & 0 deletions src/closebutton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once

#include <memory>

#include "button.h"
#include "icons.h"

namespace taranis {

class CloseButton : public Button {
public:
CloseButton(int icon_size, std::shared_ptr<Icons> icons)
: Button{icon_size, icons->get("close")} {}

typedef std::function<void()> ClickHandler;

void set_click_handler(ClickHandler handler) {
this->click_handler = handler;
}

protected:
void on_clicked() override {
if (!this->click_handler) {
return;
}
this->click_handler();
}

private:
ClickHandler click_handler;
};
} // namespace taranis
20 changes: 20 additions & 0 deletions src/dailyforecastviewer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ void DailyForecastViewer::do_paint() {
this->get_width() - 2 * DailyForecastViewer::horizontal_padding,
HORIZONTAL_SEPARATOR_SOLID);

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

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

// forecast
SetFont(default_font.get(), BLACK);

Expand Down Expand Up @@ -372,6 +386,12 @@ int DailyForecastViewer::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
6 changes: 6 additions & 0 deletions src/dailyforecastviewer.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#pragma once

#include <boost/variant.hpp>
#include <functional>
#include <inkview.h>
#include <memory>
#include <tuple>
#include <vector>

#include "button.h"
#include "closebutton.h"
#include "fonts.h"
#include "icons.h"
#include "model.h"
#include "widget.h"

namespace taranis {

class DailyForecastViewer : public ModalWidget {
public:
DailyForecastViewer(std::shared_ptr<Model> model,
Expand Down Expand Up @@ -39,6 +43,8 @@ class DailyForecastViewer : public ModalWidget {
std::shared_ptr<Icons> icons;
std::shared_ptr<Fonts> fonts;

std::shared_ptr<CloseButton> close_button;

size_t forecast_index{0};

const ibitmap *const direction_icon;
Expand Down
4 changes: 4 additions & 0 deletions src/icons.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extern const ibitmap icon_10n_2x;
extern const ibitmap icon_11n_2x;
extern const ibitmap icon_13n_2x;
extern const ibitmap icon_50n_2x;
extern const ibitmap icon_close;
extern const ibitmap icon_direction;
extern const ibitmap icon_display_settings;
extern const ibitmap icon_favorite;
Expand Down Expand Up @@ -64,6 +65,9 @@ class Icons {
if (name == "50d" or name == "50n") {
return const_cast<ibitmap *>(&icon_50n_2x);
}
if (name == "close") {
return const_cast<ibitmap *>(&icon_close);
}
if (name == "direction") {
return const_cast<ibitmap *>(&icon_direction);
}
Expand Down

0 comments on commit fbd5a1d

Please sign in to comment.