UI library wip: implement frame, extend & move
This commit is contained in:
parent
8cc3356eb1
commit
3856fdd827
10 changed files with 319 additions and 0 deletions
19
libs/ui/include/psemek/ui/extend.hpp
Normal file
19
libs/ui/include/psemek/ui/extend.hpp
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include <psemek/react/value.hpp>
|
||||
|
||||
#include <any>
|
||||
|
||||
namespace psemek::ui
|
||||
{
|
||||
|
||||
struct extend
|
||||
{
|
||||
react::value<std::any> child = {};
|
||||
react::value<float> left = 0.f;
|
||||
react::value<float> right = 0.f;
|
||||
react::value<float> top = 0.f;
|
||||
react::value<float> bottom = 0.f;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ namespace psemek::ui
|
|||
struct frame
|
||||
{
|
||||
react::value<std::any> child = {};
|
||||
react::value<float> margin = 0.f;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
32
libs/ui/include/psemek/ui/impl/extend_base.hpp
Normal file
32
libs/ui/include/psemek/ui/impl/extend_base.hpp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#pragma once
|
||||
|
||||
#include <psemek/ui/extend.hpp>
|
||||
#include <psemek/ui/impl/single_container.hpp>
|
||||
#include <psemek/react/source.hpp>
|
||||
|
||||
namespace psemek::ui::impl
|
||||
{
|
||||
|
||||
struct extend_base
|
||||
: single_container
|
||||
{
|
||||
extend_base();
|
||||
|
||||
void reshape(geom::box<float, 2> const & new_shape) override;
|
||||
react::value<struct size_constraints> size_constraints() const override;
|
||||
|
||||
void set_child(std::unique_ptr<component> child) override;
|
||||
std::unique_ptr<component> release_child() override;
|
||||
|
||||
void update(extend const & value);
|
||||
|
||||
private:
|
||||
react::source<react::value<float>> left_;
|
||||
react::source<react::value<float>> right_;
|
||||
react::source<react::value<float>> top_;
|
||||
react::source<react::value<float>> bottom_;
|
||||
react::source<react::value<struct size_constraints>> child_size_constraints_;
|
||||
react::value<struct size_constraints> size_constraints_;
|
||||
};
|
||||
|
||||
}
|
||||
29
libs/ui/include/psemek/ui/impl/frame_base.hpp
Normal file
29
libs/ui/include/psemek/ui/impl/frame_base.hpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
|
||||
#include <psemek/ui/frame.hpp>
|
||||
#include <psemek/ui/impl/single_container.hpp>
|
||||
#include <psemek/react/source.hpp>
|
||||
|
||||
namespace psemek::ui::impl
|
||||
{
|
||||
|
||||
struct frame_base
|
||||
: single_container
|
||||
{
|
||||
frame_base();
|
||||
|
||||
void reshape(geom::box<float, 2> const & new_shape) override;
|
||||
react::value<struct size_constraints> size_constraints() const override;
|
||||
|
||||
void set_child(std::unique_ptr<component> child) override;
|
||||
std::unique_ptr<component> release_child() override;
|
||||
|
||||
void update(frame const & value);
|
||||
|
||||
private:
|
||||
react::source<react::value<float>> margin_;
|
||||
react::source<react::value<struct size_constraints>> child_size_constraints_;
|
||||
react::value<struct size_constraints> size_constraints_;
|
||||
};
|
||||
|
||||
}
|
||||
29
libs/ui/include/psemek/ui/impl/move_base.hpp
Normal file
29
libs/ui/include/psemek/ui/impl/move_base.hpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
|
||||
#include <psemek/ui/move.hpp>
|
||||
#include <psemek/ui/impl/single_container.hpp>
|
||||
#include <psemek/react/source.hpp>
|
||||
|
||||
namespace psemek::ui::impl
|
||||
{
|
||||
|
||||
struct move_base
|
||||
: single_container
|
||||
{
|
||||
move_base();
|
||||
|
||||
void reshape(geom::box<float, 2> const & new_shape) override;
|
||||
react::value<struct size_constraints> size_constraints() const override;
|
||||
|
||||
void set_child(std::unique_ptr<component> child) override;
|
||||
std::unique_ptr<component> release_child() override;
|
||||
|
||||
void update(move const & value);
|
||||
|
||||
private:
|
||||
react::source<react::value<geom::vector<float, 2>>> offset_;
|
||||
react::source<react::value<struct size_constraints>> child_size_constraints_;
|
||||
react::value<struct size_constraints> size_constraints_;
|
||||
};
|
||||
|
||||
}
|
||||
17
libs/ui/include/psemek/ui/move.hpp
Normal file
17
libs/ui/include/psemek/ui/move.hpp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include <psemek/react/value.hpp>
|
||||
#include <psemek/geom/vector.hpp>
|
||||
|
||||
#include <any>
|
||||
|
||||
namespace psemek::ui
|
||||
{
|
||||
|
||||
struct move
|
||||
{
|
||||
react::value<std::any> child = {};
|
||||
react::value<geom::vector<float, 2>> offset = geom::vector{0.f, 0.f};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -8,6 +8,9 @@
|
|||
#include <psemek/ui/impl/box_layout_base.hpp>
|
||||
#include <psemek/ui/impl/aligned_base.hpp>
|
||||
#include <psemek/ui/impl/fixed_size_base.hpp>
|
||||
#include <psemek/ui/impl/frame_base.hpp>
|
||||
#include <psemek/ui/impl/extend_base.hpp>
|
||||
#include <psemek/ui/impl/move_base.hpp>
|
||||
#include <psemek/ui/impl/button_base.hpp>
|
||||
|
||||
namespace psemek::ui::impl
|
||||
|
|
@ -22,6 +25,9 @@ namespace psemek::ui::impl
|
|||
register_type<fixed_size, impl::fixed_size_base>();
|
||||
register_type<fixed_width, impl::fixed_size_base>();
|
||||
register_type<fixed_height, impl::fixed_size_base>();
|
||||
register_type<frame, impl::frame_base>();
|
||||
register_type<extend, impl::extend_base>();
|
||||
register_type<move, impl::move_base>();
|
||||
register_type<button, impl::button_base>();
|
||||
}
|
||||
|
||||
|
|
|
|||
67
libs/ui/source/impl/extend_base.cpp
Normal file
67
libs/ui/source/impl/extend_base.cpp
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#include <psemek/ui/impl/extend_base.hpp>
|
||||
#include <psemek/react/join.hpp>
|
||||
#include <psemek/react/map.hpp>
|
||||
|
||||
namespace psemek::ui::impl
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
geom::box<float, 2> compute_child_shape(geom::box<float, 2> shape, float left, float right, float top, float bottom)
|
||||
{
|
||||
shape[0].min -= left;
|
||||
shape[0].max += right;
|
||||
shape[1].min -= top;
|
||||
shape[1].max += bottom;
|
||||
return shape;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extend_base::extend_base()
|
||||
: left_(0.f)
|
||||
, right_(0.f)
|
||||
, top_(0.f)
|
||||
, bottom_(0.f)
|
||||
, child_size_constraints_(size_constraints::max())
|
||||
, size_constraints_(react::join(child_size_constraints_))
|
||||
{}
|
||||
|
||||
void extend_base::reshape(geom::box<float, 2> const & new_shape)
|
||||
{
|
||||
single_container::reshape(new_shape);
|
||||
|
||||
if (auto child = this->child())
|
||||
child->reshape(compute_child_shape(new_shape, **left_, **right_, **top_, **bottom_));
|
||||
}
|
||||
|
||||
react::value<struct size_constraints> extend_base::size_constraints() const
|
||||
{
|
||||
return size_constraints_;
|
||||
}
|
||||
|
||||
void extend_base::set_child(std::unique_ptr<component> child)
|
||||
{
|
||||
if (child)
|
||||
child_size_constraints_.set(child->size_constraints());
|
||||
else
|
||||
child_size_constraints_.set(size_constraints::max());
|
||||
single_container::set_child(std::move(child));
|
||||
}
|
||||
|
||||
std::unique_ptr<component> extend_base::release_child()
|
||||
{
|
||||
child_size_constraints_.set(size_constraints::max());
|
||||
return single_container::release_child();
|
||||
}
|
||||
|
||||
void extend_base::update(extend const & value)
|
||||
{
|
||||
left_.set(value.left);
|
||||
right_.set(value.right);
|
||||
top_.set(value.top);
|
||||
bottom_.set(value.bottom);
|
||||
}
|
||||
|
||||
}
|
||||
62
libs/ui/source/impl/frame_base.cpp
Normal file
62
libs/ui/source/impl/frame_base.cpp
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
#include <psemek/ui/impl/frame_base.hpp>
|
||||
#include <psemek/react/join.hpp>
|
||||
#include <psemek/react/map.hpp>
|
||||
|
||||
namespace psemek::ui::impl
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
size_constraints compute_size_constraints(size_constraints const & child_size_constraints, float margin)
|
||||
{
|
||||
return { child_size_constraints.box + geom::vector{2.f * margin, 2.f * margin} };
|
||||
}
|
||||
|
||||
geom::box<float, 2> compute_child_shape(geom::box<float, 2> const & shape, float margin)
|
||||
{
|
||||
return geom::expand(shape, -margin);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
frame_base::frame_base()
|
||||
: margin_(0.f)
|
||||
, child_size_constraints_(size_constraints::max())
|
||||
, size_constraints_(react::map(compute_size_constraints, react::join(child_size_constraints_), react::join(margin_)))
|
||||
{}
|
||||
|
||||
void frame_base::reshape(geom::box<float, 2> const & new_shape)
|
||||
{
|
||||
single_container::reshape(new_shape);
|
||||
|
||||
if (auto child = this->child())
|
||||
child->reshape(compute_child_shape(new_shape, **margin_));
|
||||
}
|
||||
|
||||
react::value<struct size_constraints> frame_base::size_constraints() const
|
||||
{
|
||||
return size_constraints_;
|
||||
}
|
||||
|
||||
void frame_base::set_child(std::unique_ptr<component> child)
|
||||
{
|
||||
if (child)
|
||||
child_size_constraints_.set(child->size_constraints());
|
||||
else
|
||||
child_size_constraints_.set(size_constraints::max());
|
||||
single_container::set_child(std::move(child));
|
||||
}
|
||||
|
||||
std::unique_ptr<component> frame_base::release_child()
|
||||
{
|
||||
child_size_constraints_.set(size_constraints::max());
|
||||
return single_container::release_child();
|
||||
}
|
||||
|
||||
void frame_base::update(frame const & value)
|
||||
{
|
||||
margin_.set(value.margin);
|
||||
}
|
||||
|
||||
}
|
||||
57
libs/ui/source/impl/move_base.cpp
Normal file
57
libs/ui/source/impl/move_base.cpp
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#include <psemek/ui/impl/move_base.hpp>
|
||||
#include <psemek/react/join.hpp>
|
||||
#include <psemek/react/map.hpp>
|
||||
|
||||
namespace psemek::ui::impl
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
geom::box<float, 2> compute_child_shape(geom::box<float, 2> const & shape, geom::vector<float, 2> const & offset)
|
||||
{
|
||||
return shape + offset;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
move_base::move_base()
|
||||
: offset_({0.f, 0.f})
|
||||
, child_size_constraints_(size_constraints::max())
|
||||
, size_constraints_(react::join(child_size_constraints_))
|
||||
{}
|
||||
|
||||
void move_base::reshape(geom::box<float, 2> const & new_shape)
|
||||
{
|
||||
single_container::reshape(new_shape);
|
||||
|
||||
if (auto child = this->child())
|
||||
child->reshape(compute_child_shape(new_shape, **offset_));
|
||||
}
|
||||
|
||||
react::value<struct size_constraints> move_base::size_constraints() const
|
||||
{
|
||||
return size_constraints_;
|
||||
}
|
||||
|
||||
void move_base::set_child(std::unique_ptr<component> child)
|
||||
{
|
||||
if (child)
|
||||
child_size_constraints_.set(child->size_constraints());
|
||||
else
|
||||
child_size_constraints_.set(size_constraints::max());
|
||||
single_container::set_child(std::move(child));
|
||||
}
|
||||
|
||||
std::unique_ptr<component> move_base::release_child()
|
||||
{
|
||||
child_size_constraints_.set(size_constraints::max());
|
||||
return single_container::release_child();
|
||||
}
|
||||
|
||||
void move_base::update(move const & value)
|
||||
{
|
||||
offset_.set(value.offset);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue