Repos
C++
1.4 KB41 lines Opens in site
Directory
Raw
Download
#pragma once
// Spec: INV-social 17.3, 17.4 (FullscreenImageViewer, ZoomableImage). Full screen image: spinner until the bitmap is
// loaded, then a zoomable image: zoom 1x to 5x with ctrl+wheel and the + / - buttons, drag to pan while zoomed, reset to
// the center at 1x. Toolbar: Done (leading), Share (trailing, after load): save dialog or copy the link.
// DIFF: no pinch gesture (desktop), no double tap zoom (none in Swift either), no animated reset.
#include <memory>
#include <string>
#include "ui/Navigation.hpp"
namespace dp {
// Zoom and pan state (unit tested).
struct ZoomState {
float scale = 1;
float offsetX = 0;
float offsetY = 0;
void zoomBy(float factor); // clamps to [1, 5]; at 1 the offset resets
void setScale(float value);
void pan(float dx, float dy); // only while scale > 1
};
class FullscreenImageViewerScreen : public ui::Screen {
public:
explicit FullscreenImageViewerScreen(std::string url);
~FullscreenImageViewerScreen() override { *alive_ = false; }
ui::ViewPtr body() override;
TitleMode titleMode() const override { return TitleMode::Inline; }
ui::ViewPtr toolbarLeading() override;
ui::ViewPtr toolbarTrailing() override;
const ZoomState& zoom() const { return *zoom_; }
private:
void share(ui::Rect anchor);
void save();
std::string url_;
std::shared_ptr<ZoomState> zoom_;
std::shared_ptr<bool> alive_;
};
} // namespace dp