Commit a0e73151 authored by Martin Kröning's avatar Martin Kröning

Fix inconsistent window resizing

parent e22a8fbe
...@@ -48,6 +48,7 @@ private: ...@@ -48,6 +48,7 @@ private:
void onVehicleRowSelected(Gtk::ListBoxRow *row); void onVehicleRowSelected(Gtk::ListBoxRow *row);
void refreshVehicleLabels(const DrawableVehicle &vehicle); void refreshVehicleLabels(const DrawableVehicle &vehicle);
void refreshArea(int x, int y, int width, int height); void refreshArea(int x, int y, int width, int height);
void resizeWindow();
MapArea mapArea; MapArea mapArea;
Gtk::Window win; Gtk::Window win;
Gtk::ListBox *listBox; Gtk::ListBox *listBox;
......
...@@ -88,8 +88,8 @@ void MapApp::onZoomEntryActivate() { ...@@ -88,8 +88,8 @@ void MapApp::onZoomEntryActivate() {
std::istringstream zoomBuffer(input); std::istringstream zoomBuffer(input);
zoomBuffer >> zoom; zoomBuffer >> zoom;
mapArea.setScale(zoom / 100); mapArea.setScale(zoom / 100);
// The window is only resizing, when called from the main thread like this: Glib::signal_idle().connect_once([this]() { mapArea.adaptSizeRequest(); },
mapArea.adaptSizeRequest(); Glib::PRIORITY_HIGH_IDLE + 10);
std::ostringstream formatBuffer; std::ostringstream formatBuffer;
formatBuffer << zoom << '%'; formatBuffer << zoom << '%';
...@@ -105,8 +105,8 @@ void MapApp::onZoomSelectionChanged() { ...@@ -105,8 +105,8 @@ void MapApp::onZoomSelectionChanged() {
std::istringstream zoomBuffer(selection); std::istringstream zoomBuffer(selection);
zoomBuffer >> zoom; zoomBuffer >> zoom;
mapArea.setScale(zoom / 100); mapArea.setScale(zoom / 100);
// The window is only resizing, when called from the main thread like this: Glib::signal_idle().connect_once([this]() { mapArea.adaptSizeRequest(); },
mapArea.adaptSizeRequest(); Glib::PRIORITY_HIGH_IDLE + 10);
} }
} }
...@@ -160,6 +160,12 @@ void MapApp::setTimeLabel(const std::chrono::minutes minutes) { ...@@ -160,6 +160,12 @@ void MapApp::setTimeLabel(const std::chrono::minutes minutes) {
void MapApp::addJunction(const double x, const double y) { void MapApp::addJunction(const double x, const double y) {
auto &junction = junctions.emplace_back(x, y); auto &junction = junctions.emplace_back(x, y);
Glib::signal_idle().connect_once(
[this]() {
mapArea.adaptSizeRequest();
resizeWindow();
},
Glib::PRIORITY_HIGH_IDLE + 10);
int xRegion, yRegion, widthRegion, heightRegion; int xRegion, yRegion, widthRegion, heightRegion;
junction.getRegion(xRegion, yRegion, widthRegion, heightRegion); junction.getRegion(xRegion, yRegion, widthRegion, heightRegion);
Glib::signal_idle().connect_once( Glib::signal_idle().connect_once(
...@@ -172,8 +178,12 @@ void MapApp::addJunction(const double x, const double y) { ...@@ -172,8 +178,12 @@ void MapApp::addJunction(const double x, const double y) {
void MapApp::addRoad(std::string laneThereName, std::string laneBackName, void MapApp::addRoad(std::string laneThereName, std::string laneBackName,
std::vector<std::valarray<double>> coordinates) { std::vector<std::valarray<double>> coordinates) {
auto &road = roads.emplace_back(laneThereName, laneBackName, coordinates); auto &road = roads.emplace_back(laneThereName, laneBackName, coordinates);
// The window is only resizing, when called from the main thread like this: Glib::signal_idle().connect_once(
mapArea.adaptSizeRequest(); [this]() {
mapArea.adaptSizeRequest();
resizeWindow();
},
Glib::PRIORITY_HIGH_IDLE + 10);
int xRegion, yRegion, widthRegion, heightRegion; int xRegion, yRegion, widthRegion, heightRegion;
road.getRegion(xRegion, yRegion, widthRegion, heightRegion); road.getRegion(xRegion, yRegion, widthRegion, heightRegion);
Glib::signal_idle().connect_once( Glib::signal_idle().connect_once(
...@@ -264,3 +274,10 @@ void MapApp::addOrReplaceVehicle(const std::string &vehicleName, ...@@ -264,3 +274,10 @@ void MapApp::addOrReplaceVehicle(const std::string &vehicleName,
listBox->select_row(*listBoxRow); listBox->select_row(*listBoxRow);
} }
} }
void MapApp::resizeWindow() {
Gtk::Requisition minimumSize, naturalSize;
win.get_preferred_size(minimumSize, naturalSize);
win.resize(static_cast<int>(naturalSize.width),
static_cast<int>(naturalSize.height));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment