Skip to main content

Overview

The ZepTabWindow class represents a tab container that manages one or more ZepWindow instances. It handles window splitting, window navigation, layout management, and active window tracking. Tab windows allow users to view multiple buffers simultaneously with split layouts.

Constructor

ZepTabWindow

ZepTabWindow(ZepEditor& editor);
editor
ZepEditor&
required
Reference to the parent editor
Create a new tab window container.

Window Management

AddWindow

ZepWindow* AddWindow(ZepBuffer* pBuffer, ZepWindow* pParent = nullptr, 
                     RegionLayoutType layoutType = RegionLayoutType::HBox);
pBuffer
ZepBuffer*
required
Buffer to display in the new window
pParent
ZepWindow*
Parent window for split layouts (nullptr for first window)
layoutType
RegionLayoutType
Layout direction:
  • HBox: Horizontal split (side by side)
  • VBox: Vertical split (top and bottom)
Add a new window to the tab, optionally splitting from an existing window. Returns pointer to the created window.

RemoveWindow

void RemoveWindow(ZepWindow* pWindow);
pWindow
ZepWindow*
required
Window to remove
Remove a window from the tab.

CloseActiveWindow

void CloseActiveWindow();
Close the currently active window.

GetWindows

const tWindows& GetWindows() const;
Get all windows in this tab as a std::vector<ZepWindow*>.

Active Window Management

SetActiveWindow

void SetActiveWindow(ZepWindow* pBuffer);
pBuffer
ZepWindow*
required
Window to make active
Set the active window in this tab.

GetActiveWindow

ZepWindow* GetActiveWindow() const;
Get the currently active window, or nullptr if none.

Window Navigation

DoMotion

ZepWindow* DoMotion(WindowMotion motion);
motion
WindowMotion
required
Direction to move:
  • Left: Navigate to window on the left
  • Right: Navigate to window on the right
  • Up: Navigate to window above
  • Down: Navigate to window below
Navigate to an adjacent window in the specified direction. Returns the new active window, or nullptr if no window exists in that direction.

Display Management

Display

void Display();
Render all windows in the tab.

SetDisplayRegion

void SetDisplayRegion(const NRectf& region, bool force = false);
region
const NRectf&
required
Rectangle defining the tab’s display area
force
bool
Force layout recalculation even if region hasn’t changed (default: false)
Set the display region for the tab and recalculate window layouts.

Tab Properties

GetName

std::string GetName() const;
Get the display name for this tab (typically the name of the active buffer).

Layout System

The tab window uses a region-based layout system:

Window Regions Mapping

Internal mapping between windows and their display regions:
using tWindowRegions = std::map<ZepWindow*, std::shared_ptr<Region>>;
Each ZepWindow is mapped to its corresponding Region for layout management.

Usage Examples

Basic Tab with Single Window

#include <zep/tab_window.h>
#include <zep/window.h>
#include <zep/editor.h>

// Create tab window
ZepTabWindow* pTab = editor.AddTabWindow();

// Get or create a buffer
ZepBuffer* pBuffer = editor.GetFileBuffer("main.cpp");

// Add first window to the tab
ZepWindow* pWindow = pTab->AddWindow(pBuffer);

// Set as active
pTab->SetActiveWindow(pWindow);

// Display
pTab->Display();

Horizontal Split

// Create first window
ZepBuffer* pBuffer1 = editor.GetFileBuffer("main.cpp");
ZepWindow* pWindow1 = pTab->AddWindow(pBuffer1);

// Split horizontally (side by side)
ZepBuffer* pBuffer2 = editor.GetFileBuffer("header.h");
ZepWindow* pWindow2 = pTab->AddWindow(pBuffer2, pWindow1, 
                                      RegionLayoutType::HBox);

// Now pWindow1 and pWindow2 are side by side

Vertical Split

// Create first window
ZepBuffer* pBuffer1 = editor.GetFileBuffer("main.cpp");
ZepWindow* pWindow1 = pTab->AddWindow(pBuffer1);

// Split vertically (top and bottom)
ZepBuffer* pBuffer2 = editor.GetFileBuffer("output.txt");
ZepWindow* pWindow2 = pTab->AddWindow(pBuffer2, pWindow1, 
                                      RegionLayoutType::VBox);

// Now pWindow1 is on top, pWindow2 is on bottom

Complex Multi-Split Layout

// Create initial window
ZepWindow* pMain = pTab->AddWindow(editor.GetFileBuffer("main.cpp"));

// Split horizontally
ZepWindow* pHeader = pTab->AddWindow(editor.GetFileBuffer("main.h"), 
                                     pMain, RegionLayoutType::HBox);

// Split the right pane vertically
ZepWindow* pOutput = pTab->AddWindow(editor.GetFileBuffer("output.txt"), 
                                     pHeader, RegionLayoutType::VBox);

// Result:
// +----------+----------+
// |          |  main.h  |
// |  main.cpp+----------+
// |          | output   |
// +----------+----------+

Window Navigation

// Navigate between windows
ZepWindow* pLeft = pTab->DoMotion(WindowMotion::Left);
if (pLeft)
{
    // Successfully moved to left window
    std::cout << "Now viewing: " << pLeft->GetBuffer().GetDisplayName();
}

ZepWindow* pDown = pTab->DoMotion(WindowMotion::Down);
if (!pDown)
{
    // No window below current position
    std::cout << "No window below";
}

Closing Windows

// Close specific window
ZepWindow* pWindow = pTab->GetActiveWindow();
if (pWindow)
{
    pTab->RemoveWindow(pWindow);
}

// Or close the active window directly
pTab->CloseActiveWindow();

Getting Tab Information

// Get tab name (from active buffer)
std::string tabName = pTab->GetName();

// Get all windows
const auto& windows = pTab->GetWindows();
std::cout << "Tab has " << windows.size() << " windows\n";

// Iterate through windows
for (ZepWindow* pWindow : windows)
{
    std::cout << "  - " << pWindow->GetBuffer().GetDisplayName() << "\n";
}

Setting Display Region

// Define tab area (x, y, width, height)
NRectf tabRect(0, 0, 1024, 768);
pTab->SetDisplayRegion(tabRect);

// Force recalculation of layout
pTab->SetDisplayRegion(tabRect, true);

Integration with ZepEditor

The editor manages multiple tab windows:
// Editor maintains a list of tabs
const auto& tabs = editor.GetTabWindows();

// Navigate between tabs
editor.NextTabWindow();
editor.PreviousTabWindow();

// Set active tab
editor.SetCurrentTabWindow(pTab);

// Get active tab
ZepTabWindow* pActiveTab = editor.GetActiveTabWindow();

Event Handling

virtual void Notify(std::shared_ptr<ZepMessage> message) override;
The tab window receives notifications about:
  • Buffer changes
  • Mouse events
  • Window state changes
  • Configuration updates

Best Practices

Performance Notes

Build docs developers (and LLMs) love