Skip to content

Commit

Permalink
Add missing vmax_size functionalities (#424)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulSquires authored and djowel committed Oct 27, 2024
1 parent dd03b64 commit 88eee1a
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions lib/include/elements/element/size.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,56 @@ namespace cycfi::elements
ctx.bounds.width(_size);
}

////////////////////////////////////////////////////////////////////////////
template <concepts::Element Subject>
class vmax_size_element : public proxy<Subject>
{
public:

using base_type = proxy<Subject>;

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 <concepts::Element Subject>
inline vmax_size_element<Subject>::vmax_size_element(float size, Subject subject)
: base_type(std::move(subject))
, _size(size)
{}

template <concepts::Element Subject>
inline vmax_size_element<remove_cvref_t<Subject>>
vmax_size(float size, Subject&& subject)
{
return {size, std::forward<Subject>(subject)};
}

template <concepts::Element Subject>
inline view_limits vmax_size_element<Subject>::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 <concepts::Element Subject>
inline void vmax_size_element<Subject>::prepare_subject(context& ctx)
{
if (ctx.bounds.height() > _size)
ctx.bounds.height(_size);
}

////////////////////////////////////////////////////////////////////////////
// Stretch elements
////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 88eee1a

Please # to comment.