Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
resizable_shell.hpp
Go to the documentation of this file.
1#pragma once
2
3// ResizableShell — plugin-window size constraints, aspect-ratio lock,
4// and saved-size persistence.
5//
6// Plugin shells (VST3 IPlugViewContentScaleSupport, AU fit-in-window,
7// CLAP clap_plugin_gui.adjust_size) all need the same three behaviors:
8// 1. Clamp requested sizes to a min/max.
9// 2. Optionally lock to an aspect ratio so resize handles move in step.
10// 3. Round-trip the last accepted size across session reloads.
11//
12// This component owns the arithmetic. Format adapters delegate to it
13// from their native resize callbacks and persist the last size blob
14// alongside parameter state.
15
16#include <cstdint>
17#include <optional>
18#include <span>
19#include <vector>
20
21namespace pulp::view {
22
23struct Size {
24 uint32_t width = 0;
25 uint32_t height = 0;
26 bool operator==(const Size& o) const {
27 return width == o.width && height == o.height;
28 }
29};
30
32 Size min_size{200, 150};
33 Size max_size{4096, 4096};
34 Size initial_size{640, 480};
37 double aspect_ratio = 0.0;
38};
39
41public:
48 : cfg_(cfg), current_(negotiate_static_(cfg, cfg.initial_size)) {}
49
52 Size negotiate(Size requested) const;
53
55 Size apply(Size requested) {
56 current_ = negotiate(requested);
57 return current_;
58 }
59
60 Size current() const { return current_; }
61 const ResizableShellConfig& config() const { return cfg_; }
62
66 std::vector<uint8_t> serialize() const;
67
72 bool deserialize(std::span<const uint8_t> blob);
73
74private:
75 // Free-function version of negotiate used by the ctor (negotiate()
76 // depends on cfg_ which isn't initialized yet at member-init time).
77 static Size negotiate_static_(const ResizableShellConfig& cfg, Size requested);
78
80 Size current_;
81};
82
83} // namespace pulp::view
std::vector< uint8_t > serialize() const
Serialize the saved size to 8 bytes (little-endian u32 w, h).
const ResizableShellConfig & config() const
Definition resizable_shell.hpp:61
Size apply(Size requested)
Commit the new size. Returns the clamped size actually applied.
Definition resizable_shell.hpp:55
Size negotiate(Size requested) const
Intended size → clamped to [min, max] and (when aspect is locked) snapped to the nearest aspect-corre...
bool deserialize(std::span< const uint8_t > blob)
Restore from a blob produced by serialize().
Size current() const
Definition resizable_shell.hpp:60
ResizableShell(ResizableShellConfig cfg={})
Construct with a config.
Definition resizable_shell.hpp:47
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
@ o
Definition input_events.hpp:40
Definition resizable_shell.hpp:31
Size max_size
Definition resizable_shell.hpp:33
double aspect_ratio
When > 0, aspect ratio = width / height is held during resize.
Definition resizable_shell.hpp:37
Size initial_size
Definition resizable_shell.hpp:34
Size min_size
Definition resizable_shell.hpp:32
Definition geometry.hpp:28
bool operator==(const Size &o) const
Definition resizable_shell.hpp:26
float height
Definition geometry.hpp:29
float width
Definition geometry.hpp:29