From 8173b70c85df74da810ac2789253ab5cb06a03f5 Mon Sep 17 00:00:00 2001 From: PaulSquires Date: Wed, 11 Sep 2024 14:57:46 -0230 Subject: [PATCH] Add missing vmax_size functionalities --- lib/include/elements/element/size.hpp | 50 +++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/lib/include/elements/element/size.hpp b/lib/include/elements/element/size.hpp index a1b0b3e6..a03af0b7 100644 --- a/lib/include/elements/element/size.hpp +++ b/lib/include/elements/element/size.hpp @@ -483,6 +483,56 @@ namespace cycfi::elements ctx.bounds.width(_size); } + //////////////////////////////////////////////////////////////////////////// + template + class vmax_size_element : public proxy + { + public: + + using base_type = proxy; + + vmax_size_element(float size, Subject subject); + + view_limits limits(basic_context const& ctx) const override; + void prepare_subject(context& ctx) override; + + void vmax_size(float size) { _size = size; } + float vmax_size() const { return _size; } + + private: + + float _size; + }; + + template + inline vmax_size_element::vmax_size_element(float size, Subject subject) + : base_type(std::move(subject)) + , _size(size) + {} + + template + inline vmax_size_element> + vmax_size(float size, Subject&& subject) + { + return {size, std::forward(subject)}; + } + + template + inline view_limits vmax_size_element::limits(basic_context const& ctx) const + { + auto e_limits = this->subject().limits(ctx); + float size_y = _size; + clamp(size_y, e_limits.min.y, e_limits.max.y); + return {{e_limits.min.x, e_limits.min.y}, {size_y, e_limits.max.y}}; + } + + template + inline void vmax_size_element::prepare_subject(context& ctx) + { + if (ctx.bounds.height() > _size) + ctx.bounds.height(_size); + } + //////////////////////////////////////////////////////////////////////////// // Stretch elements ////////////////////////////////////////////////////////////////////////////