Make convenient function in ui::element_factory to create a progress bar with a label

This commit is contained in:
Nikita Lisitsa 2022-05-17 20:24:58 +03:00
parent c706032df5
commit 16036268f5
2 changed files with 20 additions and 0 deletions

View file

@ -53,6 +53,7 @@ namespace psemek::ui
virtual std::shared_ptr<button> make_arrow_button(int direction);
virtual std::shared_ptr<scroller> make_scroller();
virtual std::shared_ptr<progress_bar> make_progress_bar();
virtual std::shared_ptr<progress_bar> make_progress_bar(std::string text);
virtual std::shared_ptr<selector> make_selector();
virtual std::shared_ptr<table> make_table();
virtual std::shared_ptr<edit> make_edit();

View file

@ -7,6 +7,7 @@
#include <psemek/ui/rich_image_view.hpp>
#include <psemek/ui/grid_layout.hpp>
#include <psemek/ui/screen.hpp>
#include <psemek/ui/progress_bar.hpp>
namespace psemek::ui
{
@ -129,6 +130,24 @@ namespace psemek::ui
std::shared_ptr<progress_bar> element_factory::make_progress_bar() { return nullptr; }
std::shared_ptr<progress_bar> element_factory::make_progress_bar(std::string text)
{
auto result = make_progress_bar();
if (result)
{
auto label = make_label(std::move(text));
if (label)
{
label->set_halign(ui::label::halignment::center);
label->set_valign(ui::label::valignment::center);
result->set_child(label);
}
}
return result;
}
std::shared_ptr<selector> element_factory::make_selector() { return nullptr; }
std::shared_ptr<table> element_factory::make_table() { return nullptr; }