Sparkle 0.0.1
Loading...
Searching...
No Matches
spk_resizable_element.hpp
1#pragma once
2
3#include "structure/design_pattern/spk_cached_data.hpp"
4#include "structure/graphics/spk_extend_2d.hpp"
5#include "structure/math/spk_vector2.hpp"
6#include "utils/spk_math_utils.hpp"
7#include <limits>
8#include <vector>
9
10namespace spk
11{
16 class ResizableElement
17 {
18 public:
23 class SizeHint
24 {
25 public:
30
31 private:
32 mutable CachedData<Vector2UInt> _minimal{[]() {
33 return Vector2UInt::Zero;
34 }};
35 mutable CachedData<Vector2UInt> _desired{[]() {
36 return Vector2UInt::Zero;
37 }};
38 mutable CachedData<Vector2UInt> _maximal{[]() {
39 return std::numeric_limits<Vector2UInt>::max();
40 }};
41
42 public:
43 SizeHint() = default;
44
51 SizeHint(Generator p_minimalGenerator, Generator p_desiredGenerator, Generator p_maximalGenerator);
52
59 void configure(Generator p_minimalGenerator, Generator p_desiredGenerator, Generator p_maximalGenerator);
60
65 void configureMinimalGenerator(Generator p_generator);
70 void configureDesiredGenerator(Generator p_generator);
75 void configureMaximalGenerator(Generator p_generator);
76
80 void release();
81
85 void releaseMinimal();
89 void releaseDesired();
93 void releaseMaximal();
94
99 void setMinimal(const Vector2UInt &p_minimalValue);
104 void setDesired(const Vector2UInt &p_desiredValue);
109 void setMaximal(const Vector2UInt &p_maximalValue);
110
115 const Vector2UInt &minimal() const;
120 const Vector2UInt &desired() const;
125 const Vector2UInt &maximal() const;
126 };
127
128 private:
129 SizeHint _sizeHint;
130
131 public:
132 ResizableElement() = default;
133
134 virtual ~ResizableElement() = default;
135
140 virtual void setGeometry(const Extend2D &p_extend) = 0;
141
151 const SizeHint &sizeHint() const;
152 };
153}
Lazily generates and caches a value with optional custom destructor.
Definition spk_cached_data.hpp:26
std::function< TType()> Generator
Callable used to lazily produce the cached value.
Definition spk_cached_data.hpp:33
Holds minimal, desired, and maximal size generators.
Definition spk_resizable_element.hpp:24
const Vector2UInt & minimal() const
Returns the minimal size.
Definition spk_resizable_element.cpp:73
void releaseMinimal()
Releases cached minimal size.
Definition spk_resizable_element.cpp:43
void configureMaximalGenerator(Generator p_generator)
Configures the maximal size generator.
Definition spk_resizable_element.cpp:31
void setDesired(const Vector2UInt &p_desiredValue)
Sets the desired size override.
Definition spk_resizable_element.cpp:63
const Vector2UInt & maximal() const
Returns the maximal size.
Definition spk_resizable_element.cpp:81
CachedData< Vector2UInt >::Generator Generator
Generator type used to compute size hints.
Definition spk_resizable_element.hpp:29
const Vector2UInt & desired() const
Returns the desired size.
Definition spk_resizable_element.cpp:77
void configureDesiredGenerator(Generator p_generator)
Configures the desired size generator.
Definition spk_resizable_element.cpp:26
void setMaximal(const Vector2UInt &p_maximalValue)
Sets the maximal size override.
Definition spk_resizable_element.cpp:68
void release()
Releases all cached size hint values.
Definition spk_resizable_element.cpp:36
void setMinimal(const Vector2UInt &p_minimalValue)
Sets the minimal size override.
Definition spk_resizable_element.cpp:58
void releaseDesired()
Releases cached desired size.
Definition spk_resizable_element.cpp:48
void configure(Generator p_minimalGenerator, Generator p_desiredGenerator, Generator p_maximalGenerator)
Configures all size hint generators.
Definition spk_resizable_element.cpp:14
void releaseMaximal()
Releases cached maximal size.
Definition spk_resizable_element.cpp:53
void configureMinimalGenerator(Generator p_generator)
Configures the minimal size generator.
Definition spk_resizable_element.cpp:21
virtual void setGeometry(const Extend2D &p_extend)=0
Sets the element geometry.
SizeHint & sizeHint()
Returns mutable size hint data.
Definition spk_resizable_element.cpp:86
Axis-aligned rectangle defined by an anchor point and size.
Definition spk_extend_2d.hpp:24
static const IVector2 Zero
Definition spk_vector2.hpp:96