From b8fb2d47e3db50881e40eca105c799f1d5e3a040 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Wed, 3 Mar 2021 10:59:50 +0300 Subject: [PATCH] UI window wip --- examples/ui.cpp | 25 ++- .../psemek/ui/default_element_factory.hpp | 2 + libs/ui/include/psemek/ui/window.hpp | 15 ++ libs/ui/source/default_element_factory.cpp | 171 +++++++++++++++++- 4 files changed, 199 insertions(+), 14 deletions(-) create mode 100644 libs/ui/include/psemek/ui/window.hpp diff --git a/examples/ui.cpp b/examples/ui.cpp index 43cb37db..ec82b4da 100644 --- a/examples/ui.cpp +++ b/examples/ui.cpp @@ -46,21 +46,20 @@ struct ui_example auto screen = element_factory.make_screen(); screen->set_style(style); - std::shared_ptr button; + auto window = element_factory.make_window("Settings"); + auto frame = element_factory.make_frame(); { - gfx::pixmap_rgba pm({32, 32}); - for (int x = 0; x < pm.width(); ++x) - { - for (int y = 0; y < pm.height(); ++y) - { - pm(x, y) = {(x * 255) / pm.width(), (y * 255) / pm.height(), 0, 255}; - } - } - auto tex = std::make_shared(gfx::texture_2d::from_pixmap(pm)); - tex->nearest_filter(); - button = element_factory.make_button(tex); + auto style = std::make_shared(); + style->border_width = 0; + style->shadow_offset = {0, 0}; + frame->set_style(style); } - screen->add_child(button, ui::screen::x_policy::center, ui::screen::y_policy::center); + auto label = element_factory.make_label(to_be); + label->set_overflow(ui::label::overflow_mode::ellipsis); + label->set_multiline(ui::label::multiline_mode::minimize_lines); + frame->set_child(label); + window->set_child(frame); + screen->add_child(window, ui::screen::x_policy::center, ui::screen::y_policy::center); ui_controller.set_root(std::move(screen)); } diff --git a/libs/ui/include/psemek/ui/default_element_factory.hpp b/libs/ui/include/psemek/ui/default_element_factory.hpp index fdeeff37..81952ffc 100644 --- a/libs/ui/include/psemek/ui/default_element_factory.hpp +++ b/libs/ui/include/psemek/ui/default_element_factory.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -23,6 +24,7 @@ namespace psemek::ui std::shared_ptr