From 3f6024ddf213b83cf0c815b68f8ad8de3f3afa44 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sat, 16 Jan 2021 23:49:27 -0500 Subject: improve image loading a bit (close #6) --- components/lazyimage.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 components/lazyimage.hpp (limited to 'components/lazyimage.hpp') diff --git a/components/lazyimage.hpp b/components/lazyimage.hpp new file mode 100644 index 0000000..54282b5 --- /dev/null +++ b/components/lazyimage.hpp @@ -0,0 +1,20 @@ +#pragma once +#include + +// loads an image only when the widget is drawn for the first time +class LazyImage : public Gtk::Image { +public: + LazyImage(int w, int h, bool use_placeholder = true); + LazyImage(const std::string &url, int w, int h, bool use_placeholder = true); + + void SetURL(const std::string &url); + +private: + bool OnDraw(const Cairo::RefPtr &context); + + bool m_needs_request = true; + int m_idx; + std::string m_url; + int m_width; + int m_height; +}; -- cgit v1.2.3