Add ui::single_container for wrapper elements
This commit is contained in:
parent
4a6d3a9d88
commit
e630316a05
8 changed files with 45 additions and 63 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <psemek/ui/element.hpp>
|
#include <psemek/ui/single_container.hpp>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
|
@ -8,12 +8,8 @@ namespace psemek::ui
|
||||||
{
|
{
|
||||||
|
|
||||||
struct event_interceptor
|
struct event_interceptor
|
||||||
: element
|
: single_container
|
||||||
{
|
{
|
||||||
children_range children() const override { return children_; }
|
|
||||||
|
|
||||||
virtual std::shared_ptr<element> set_child(std::shared_ptr<element> c);
|
|
||||||
|
|
||||||
geom::box<float, 2> size_constraints() const override;
|
geom::box<float, 2> size_constraints() const override;
|
||||||
|
|
||||||
struct shape const & shape() const override;
|
struct shape const & shape() const override;
|
||||||
|
|
@ -32,9 +28,6 @@ namespace psemek::ui
|
||||||
void draw(painter &) const override {}
|
void draw(painter &) const override {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<element> child_;
|
|
||||||
element * children_[1]{nullptr};
|
|
||||||
|
|
||||||
bool mouseover_ = false;
|
bool mouseover_ = false;
|
||||||
|
|
||||||
std::function<bool(mouse_move const &)> mouse_move_callback_;
|
std::function<bool(mouse_move const &)> mouse_move_callback_;
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <psemek/ui/element.hpp>
|
#include <psemek/ui/single_container.hpp>
|
||||||
|
|
||||||
namespace psemek::ui
|
namespace psemek::ui
|
||||||
{
|
{
|
||||||
|
|
||||||
struct frame
|
struct frame
|
||||||
: element
|
: single_container
|
||||||
{
|
{
|
||||||
children_range children() const override { return children_; }
|
|
||||||
|
|
||||||
virtual std::shared_ptr<element> set_child(std::shared_ptr<element> c);
|
|
||||||
|
|
||||||
virtual void set_min_size(std::optional<geom::vector<float, 2>> const & size);
|
virtual void set_min_size(std::optional<geom::vector<float, 2>> const & size);
|
||||||
virtual void set_max_size(std::optional<geom::vector<float, 2>> const & size);
|
virtual void set_max_size(std::optional<geom::vector<float, 2>> const & size);
|
||||||
virtual void set_fixed_size(geom::vector<float, 2> const & size);
|
virtual void set_fixed_size(geom::vector<float, 2> const & size);
|
||||||
|
|
@ -24,9 +20,6 @@ namespace psemek::ui
|
||||||
private:
|
private:
|
||||||
std::optional<geom::vector<float, 2>> min_size_;
|
std::optional<geom::vector<float, 2>> min_size_;
|
||||||
std::optional<geom::vector<float, 2>> max_size_;
|
std::optional<geom::vector<float, 2>> max_size_;
|
||||||
|
|
||||||
std::shared_ptr<element> child_;
|
|
||||||
element * children_[1]{nullptr};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,14 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <psemek/ui/element.hpp>
|
#include <psemek/ui/single_container.hpp>
|
||||||
#include <psemek/ui/box_shape.hpp>
|
#include <psemek/ui/box_shape.hpp>
|
||||||
|
|
||||||
namespace psemek::ui
|
namespace psemek::ui
|
||||||
{
|
{
|
||||||
|
|
||||||
struct scroller
|
struct scroller
|
||||||
: element
|
: single_container
|
||||||
{
|
{
|
||||||
children_range children() const override { return children_; }
|
|
||||||
|
|
||||||
virtual std::shared_ptr<element> set_child(std::shared_ptr<element> c);
|
|
||||||
|
|
||||||
enum class direction
|
enum class direction
|
||||||
{
|
{
|
||||||
horizontal,
|
horizontal,
|
||||||
|
|
@ -77,9 +73,6 @@ namespace psemek::ui
|
||||||
geom::vector<float, 2> shift_{0.f, 0.f};
|
geom::vector<float, 2> shift_{0.f, 0.f};
|
||||||
geom::vector<float, 2> shift_tgt_{0.f, 0.f};
|
geom::vector<float, 2> shift_tgt_{0.f, 0.f};
|
||||||
|
|
||||||
std::shared_ptr<element> child_;
|
|
||||||
element * children_[1]{nullptr};
|
|
||||||
|
|
||||||
void clamp_shift();
|
void clamp_shift();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
21
libs/ui/include/psemek/ui/single_container.hpp
Normal file
21
libs/ui/include/psemek/ui/single_container.hpp
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <psemek/ui/element.hpp>
|
||||||
|
|
||||||
|
namespace psemek::ui
|
||||||
|
{
|
||||||
|
|
||||||
|
struct single_container
|
||||||
|
: element
|
||||||
|
{
|
||||||
|
children_range children() const override { return children_; }
|
||||||
|
|
||||||
|
virtual std::shared_ptr<element> set_child(std::shared_ptr<element> c);
|
||||||
|
virtual std::shared_ptr<element> child() { return child_; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::shared_ptr<element> child_;
|
||||||
|
element * children_[1]{nullptr};
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -4,18 +4,6 @@
|
||||||
namespace psemek::ui
|
namespace psemek::ui
|
||||||
{
|
{
|
||||||
|
|
||||||
std::shared_ptr<element> event_interceptor::set_child(std::shared_ptr<element> c)
|
|
||||||
{
|
|
||||||
auto old = std::move(child_);
|
|
||||||
if (old) old->set_parent(nullptr);
|
|
||||||
|
|
||||||
child_ = std::move(c);
|
|
||||||
if (child_) child_->set_parent(this);
|
|
||||||
children_[0] = child_.get();
|
|
||||||
|
|
||||||
return old;
|
|
||||||
}
|
|
||||||
|
|
||||||
geom::box<float, 2> event_interceptor::size_constraints() const
|
geom::box<float, 2> event_interceptor::size_constraints() const
|
||||||
{
|
{
|
||||||
if (child_)
|
if (child_)
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,6 @@
|
||||||
namespace psemek::ui
|
namespace psemek::ui
|
||||||
{
|
{
|
||||||
|
|
||||||
std::shared_ptr<element> frame::set_child(std::shared_ptr<element> c)
|
|
||||||
{
|
|
||||||
auto old = std::move(child_);
|
|
||||||
if (old) old->set_parent(nullptr);
|
|
||||||
|
|
||||||
child_ = std::move(c);
|
|
||||||
if (child_) child_->set_parent(this);
|
|
||||||
children_[0] = child_.get();
|
|
||||||
|
|
||||||
return old;
|
|
||||||
}
|
|
||||||
|
|
||||||
void frame::set_min_size(std::optional<geom::vector<float, 2>> const & size)
|
void frame::set_min_size(std::optional<geom::vector<float, 2>> const & size)
|
||||||
{
|
{
|
||||||
min_size_ = size;
|
min_size_ = size;
|
||||||
|
|
|
||||||
|
|
@ -5,18 +5,6 @@
|
||||||
namespace psemek::ui
|
namespace psemek::ui
|
||||||
{
|
{
|
||||||
|
|
||||||
std::shared_ptr<element> scroller::set_child(std::shared_ptr<element> c)
|
|
||||||
{
|
|
||||||
auto old = std::move(child_);
|
|
||||||
if (old) old->set_parent(nullptr);
|
|
||||||
|
|
||||||
child_ = std::move(c);
|
|
||||||
if (child_) child_->set_parent(this);
|
|
||||||
children_[0] = child_.get();
|
|
||||||
|
|
||||||
return old;
|
|
||||||
}
|
|
||||||
|
|
||||||
void scroller::set_preferred_direction(direction d)
|
void scroller::set_preferred_direction(direction d)
|
||||||
{
|
{
|
||||||
preferred_direction_ = d;
|
preferred_direction_ = d;
|
||||||
|
|
|
||||||
18
libs/ui/source/single_container.cpp
Normal file
18
libs/ui/source/single_container.cpp
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
#include <psemek/ui/single_container.hpp>
|
||||||
|
|
||||||
|
namespace psemek::ui
|
||||||
|
{
|
||||||
|
|
||||||
|
std::shared_ptr<element> single_container::set_child(std::shared_ptr<element> c)
|
||||||
|
{
|
||||||
|
auto old = std::move(child_);
|
||||||
|
if (old) old->set_parent(nullptr);
|
||||||
|
|
||||||
|
child_ = std::move(c);
|
||||||
|
if (child_) child_->set_parent(this);
|
||||||
|
children_[0] = child_.get();
|
||||||
|
|
||||||
|
return old;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue