mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-09-18 16:53:42 +08:00
cabana: make the Signals pane a native dock panel, fix pad (#38889)
* cabana: align center tabs and keep signal panel docked * cabana: prevent panels from docking into the tabless center * cabana: use native docking for the Signals panel * cabana: migrate dock tabs when loading the layout
This commit is contained in:
@@ -107,6 +107,15 @@ std::string migrateQtState() {
|
||||
return std::string(buf.c_str());
|
||||
}
|
||||
|
||||
void migrateDockLayout() {
|
||||
// Show dock tabs hidden by older layouts.
|
||||
if (const auto *center = ImGui::FindWindowSettingsByID(ImHashStr("###CenterWidget"))) {
|
||||
if (auto *node = ImGui::DockBuilderGetNode(center->DockId)) {
|
||||
node->LocalFlags &= ~ImGuiDockNodeFlags_NoTabBar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void addSettingsHandler() {
|
||||
@@ -123,6 +132,8 @@ void load() {
|
||||
if (settings.ui_state.empty()) settings.ui_state = migrateQtState();
|
||||
if (!settings.ui_state.empty())
|
||||
ImGui::LoadIniSettingsFromMemory(settings.ui_state.data(), settings.ui_state.size());
|
||||
|
||||
migrateDockLayout();
|
||||
}
|
||||
|
||||
void applyWindowGeometry(GLFWwindow *window) {
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
namespace {
|
||||
// dock window ids (the visible titles change, the part after ### is the identity)
|
||||
constexpr const char *VIDEO_PANEL = "###VideoPanel";
|
||||
constexpr const char *CENTER_PANEL = "###CenterWidget";
|
||||
constexpr const char *CENTER_PANEL = "Signals###CenterWidget";
|
||||
constexpr const char *CHARTS_WINDOW = "Charts###ChartsWindow";
|
||||
} // namespace
|
||||
|
||||
@@ -777,8 +777,6 @@ void MainWindow::drawDockspace() {
|
||||
// the status bar sits below the dockspace: reserve its height plus the item spacing between the two,
|
||||
// otherwise the host window is a few pixels taller than the viewport and scrolls
|
||||
const float status_height = full_screen_ ? 0.0f : ImGui::GetFrameHeight() + ImGui::GetStyle().ItemSpacing.y;
|
||||
const float top_gap = full_screen_ ? 0.0f : ImGui::GetStyle().ItemSpacing.y;
|
||||
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + top_gap);
|
||||
const ImVec2 dock_size(ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y - status_height);
|
||||
const ImGuiID dock_id = ImGui::GetID("cabana_dockspace");
|
||||
if (reset_layout_ || ImGui::DockBuilderGetNode(dock_id) == nullptr ||
|
||||
@@ -796,7 +794,6 @@ void MainWindow::drawDockspace() {
|
||||
ImGui::DockBuilderDockWindow(MESSAGES_PANEL_ID, left);
|
||||
ImGui::DockBuilderDockWindow(VIDEO_PANEL, right);
|
||||
ImGui::DockBuilderDockWindow(CENTER_PANEL, center);
|
||||
ImGui::DockBuilderGetNode(center)->LocalFlags |= ImGuiDockNodeFlags_NoTabBar;
|
||||
ImGui::DockBuilderFinish(dock_id);
|
||||
reset_layout_ = false;
|
||||
}
|
||||
@@ -879,13 +876,12 @@ void MainWindow::draw() {
|
||||
drawDockspace();
|
||||
|
||||
// the central widget has no scrollbars of its own (the views inside scroll)
|
||||
setNextPanelClass();
|
||||
if (beginPanel(CENTER_PANEL, nullptr, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) {
|
||||
ImGui::BeginChild("center", ImVec2(0, 0), ImGuiChildFlags_Borders, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
|
||||
center_widget_.draw();
|
||||
if (auto *detail = center_widget_.getDetailWidget(); detail && help_overlay_.visible()) {
|
||||
for (const auto &[text, rect] : detail->helpRects()) help_overlay_.add(text, rect);
|
||||
}
|
||||
ImGui::EndChild();
|
||||
}
|
||||
ImGui::End();
|
||||
// Submit the same dock windows while loading, so ImGui doesn't collapse their
|
||||
|
||||
@@ -280,6 +280,8 @@ void DetailWidget::drawTabWidget() {
|
||||
|
||||
void DetailWidget::draw() {
|
||||
tabbar_.draw();
|
||||
ImGui::BeginChild("message_content", ImVec2(0, 0), ImGuiChildFlags_Borders,
|
||||
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
|
||||
drawToolBar();
|
||||
|
||||
if (warning_widget_visible_) {
|
||||
@@ -289,6 +291,7 @@ void DetailWidget::draw() {
|
||||
}
|
||||
|
||||
drawTabWidget();
|
||||
ImGui::EndChild();
|
||||
|
||||
if (edit_dlg_ && !edit_dlg_->draw()) {
|
||||
if (edit_dlg_->accepted()) {
|
||||
|
||||
Reference in New Issue
Block a user