Highlight the option that owns the active submenu in ui::selector
This commit is contained in:
parent
d6f53ed76f
commit
e1d4608e3f
2 changed files with 23 additions and 12 deletions
|
|
@ -39,7 +39,7 @@ namespace psemek::ui
|
||||||
|
|
||||||
using callback_type = std::function<void(std::size_t)>;
|
using callback_type = std::function<void(std::size_t)>;
|
||||||
|
|
||||||
virtual std::optional<std::size_t> selected() const { return selected_; }
|
virtual std::optional<std::size_t> selected() const;
|
||||||
virtual void on_selected(callback_type callback);
|
virtual void on_selected(callback_type callback);
|
||||||
virtual void on_mouseover(std::function<void(std::optional<std::size_t>)> callback);
|
virtual void on_mouseover(std::function<void(std::optional<std::size_t>)> callback);
|
||||||
|
|
||||||
|
|
@ -65,7 +65,7 @@ namespace psemek::ui
|
||||||
|
|
||||||
box_shape shape_;
|
box_shape shape_;
|
||||||
std::vector<std::shared_ptr<selector>> submenu_;
|
std::vector<std::shared_ptr<selector>> submenu_;
|
||||||
selector * active_submenu_ = nullptr;
|
std::optional<std::size_t> active_submenu_;
|
||||||
float active_submenu_y_ = 0.f;
|
float active_submenu_y_ = 0.f;
|
||||||
|
|
||||||
std::vector<geom::box<float, 2>> child_boxes_;
|
std::vector<geom::box<float, 2>> child_boxes_;
|
||||||
|
|
|
||||||
|
|
@ -62,13 +62,14 @@ namespace psemek::ui
|
||||||
|
|
||||||
if (active_submenu_)
|
if (active_submenu_)
|
||||||
{
|
{
|
||||||
auto sc = active_submenu_->size_constraints();
|
auto submenu = submenu_[*active_submenu_];
|
||||||
|
auto sc = submenu->size_constraints();
|
||||||
|
|
||||||
geom::box<float, 2> box{{{0.f, sc[0].min}, {0.f, sc[1].min}}};
|
geom::box<float, 2> box{{{0.f, sc[0].min}, {0.f, sc[1].min}}};
|
||||||
box[0] += shape_.box[0].max;
|
box[0] += shape_.box[0].max;
|
||||||
box[1] += active_submenu_y_;
|
box[1] += active_submenu_y_;
|
||||||
|
|
||||||
active_submenu_->reshape(box);
|
submenu->reshape(box);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -199,6 +200,15 @@ namespace psemek::ui
|
||||||
return child_boxes_[index][1];
|
return child_boxes_[index][1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<std::size_t> selector::selected() const
|
||||||
|
{
|
||||||
|
if (active_submenu_)
|
||||||
|
return active_submenu_;
|
||||||
|
if (selected_)
|
||||||
|
return selected_;
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
void selector::on_selected(callback_type callback)
|
void selector::on_selected(callback_type callback)
|
||||||
{
|
{
|
||||||
callback_ = std::move(callback);
|
callback_ = std::move(callback);
|
||||||
|
|
@ -218,12 +228,12 @@ namespace psemek::ui
|
||||||
{
|
{
|
||||||
release_submenu();
|
release_submenu();
|
||||||
|
|
||||||
auto new_submenu = submenu_[index].get();
|
auto submenu = submenu_[index].get();
|
||||||
if (new_submenu)
|
if (submenu)
|
||||||
{
|
{
|
||||||
children_range_[0] = new_submenu;
|
children_range_[0] = submenu;
|
||||||
active_submenu_ = new_submenu;
|
active_submenu_ = index;
|
||||||
new_submenu->set_parent(this);
|
submenu->set_parent(this);
|
||||||
active_submenu_y_ = child_boxes_[index][1].min;
|
active_submenu_y_ = child_boxes_[index][1].min;
|
||||||
post_reshape();
|
post_reshape();
|
||||||
}
|
}
|
||||||
|
|
@ -233,9 +243,10 @@ namespace psemek::ui
|
||||||
{
|
{
|
||||||
if (active_submenu_)
|
if (active_submenu_)
|
||||||
{
|
{
|
||||||
active_submenu_->release_submenu();
|
auto submenu = submenu_[*active_submenu_].get();
|
||||||
active_submenu_->set_parent(nullptr);
|
submenu->release_submenu();
|
||||||
active_submenu_ = nullptr;
|
submenu->set_parent(nullptr);
|
||||||
|
active_submenu_ = std::nullopt;
|
||||||
children_range_[0] = nullptr;
|
children_range_[0] = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue