diff --git a/include/toolbar.hpp b/include/toolbar.hpp index e2ecd54..8cd260a 100644 --- a/include/toolbar.hpp +++ b/include/toolbar.hpp @@ -49,6 +49,11 @@ public: * Récupère la fenêtre de la barre d'outils */ sfg::Window::Ptr getWindow(); + + /** + * Récupère la taille désirée par la barre d'outils + */ + float getWidth(); }; #endif diff --git a/src/editor.cpp b/src/editor.cpp index 170d88b..32a4aa1 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -330,10 +330,9 @@ void Editor::draw() { widget_timer.draw(sf::Vector2f(window_size.x / 2 - 50, 0)); // on redimensionne la toolbar pour qu'elle occupe l'espace droite - const sfg::Window::Ptr& toolbar_window = toolbar.getWindow(); - toolbar_window->SetAllocation(sf::FloatRect( - window_size.x - 200, 0, - 200, window_size.y + toolbar.getWindow()->SetAllocation(sf::FloatRect( + window_size.x - toolbar.getWidth(), 0, + toolbar.getWidth(), window_size.y )); } diff --git a/src/toolbar.cpp b/src/toolbar.cpp index 41752de..0c5827a 100644 --- a/src/toolbar.cpp +++ b/src/toolbar.cpp @@ -29,6 +29,9 @@ Toolbar::Toolbar(Editor& editor) : editor(editor) { toolbar_box->PackEnd(save_button); // ajout des créateurs de blocs + toolbar_box->PackEnd(sfg::Separator::Create()); + toolbar_box->PackEnd(sfg::Label::Create(L"Type d'objet à placer")); + addCreator(L"Bloc normal", std::bind(&Toolbar::createBlock, this)); addCreator(L"Caisse", std::bind(&Toolbar::createMovableBlock, this)); addCreator(L"Joueur", std::bind(&Toolbar::createPlayer, this)); @@ -54,16 +57,15 @@ Toolbar::Toolbar(Editor& editor) : editor(editor) { // création de la fenêtre de la barre d'outils scrolled_zone = sfg::ScrolledWindow::Create(); + toolbar_window = sfg::Window::Create(sfg::Window::Style::BACKGROUND); + scrolled_zone->SetScrollbarPolicy( sfg::ScrolledWindow::ScrollbarPolicy::VERTICAL_AUTOMATIC | sfg::ScrolledWindow::ScrollbarPolicy::HORIZONTAL_NEVER ); scrolled_zone->AddWithViewport(toolbar_box); - - toolbar_window = sfg::Window::Create(sfg::Window::Style::BACKGROUND); toolbar_window->Add(scrolled_zone); - toolbar_window->SetPosition(sf::Vector2f(0, 0)); } void Toolbar::addCreator(sf::String label, std::function creator) { @@ -122,3 +124,7 @@ Object::Ptr Toolbar::createObject() { sfg::Window::Ptr Toolbar::getWindow() { return toolbar_window; } + +float Toolbar::getWidth() { + return scrolled_zone->GetRequisition().x; +}