#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace psemek::ui { namespace { struct frame_style_fix : ui::single_container { struct shape const & shape() const override { return child()->shape(); } void reshape(math::box const & bbox) override { child()->reshape(bbox); } math::box size_constraints() const override { return child()->size_constraints(); } math::interval width_constraints(float height) const override { return child()->width_constraints(height); } math::interval height_constraints(float width) const override { return child()->height_constraints(width); } void style_updated() const override { ui::single_container::style_updated(); auto style = merged_style(); auto new_style = std::make_shared(); new_style->bg_color = style->action_color; child()->set_own_style(new_style); } void draw(painter &) const override {} }; struct file_dialog_image_provider : image_provider { file_dialog_image_provider() { back_.load(gfx::read_image(io::memory_istream(resources::back_png.data))); back_.linear_filter(); folder_.load(gfx::read_image(io::memory_istream(resources::folder_png.data))); folder_.linear_filter(); file_.load(gfx::read_image(io::memory_istream(resources::file_png.data))); file_.linear_filter(); } gfx::texture_view_2d get(std::string_view const & id) const override { if (id == "back") return gfx::texture_view_2d{&back_}; if (id == "folder") return gfx::texture_view_2d{&folder_}; if (id == "file") return gfx::texture_view_2d{&file_}; return {}; } private: gfx::texture_2d back_; gfx::texture_2d folder_; gfx::texture_2d file_; }; std::string replace(std::string str, std::string const & match, std::string const & replacement) { for (std::size_t i = 0; (i = str.find(match, i)) != std::string::npos;) { str.replace(i, match.size(), replacement); i += replacement.size(); } return str; } std::string escape(std::string str) { str = replace(std::move(str), "\\", "\\\\"); str = replace(std::move(str), "[", "\\["); str = replace(std::move(str), "]", "\\]"); return str; } } std::shared_ptr make_file_dialog(file_dialog_options const & options) { auto window = options.element_factory.make_window(options.caption); auto main_layout = options.element_factory.make_grid_layout(); main_layout->set_size(4, options.extra_widget ? 3 : 2); main_layout->set_column_weight(0, 0.f); if (options.extra_widget) main_layout->set_column_weight(2, 0.f); main_layout->set_row_weight(0, 0.f); main_layout->set_row_weight(2, 0.f); main_layout->set_row_weight(3, 0.f); auto image_provider = std::make_shared(); auto current_path = std::make_shared(); auto selected_path = std::make_shared(); auto back_button = options.element_factory.make_button(image_provider->get("back")); back_button->icon()->set_downscale(false); auto back_button_style = std::make_shared