Skip to content

Tabbed Widgets

Morquin edited this page Jul 1, 2026 · 3 revisions

Tabbed Widgets

Tabbed widgets provide multiple switchable content areas within a single widget, ideal for communication channels, logs, or categorized information.

A tabbed widget is one object with built-in channels you write to with echoTo(). This is different from a grouped widget, which combines several independent widgets into a shared tab bar by dragging. A tabbed widget can itself be dropped into a group as one member.

Creating a Tabbed Widget

local comm = mdw.TabbedWidget:new({
  name = "Comm",
  title = "Communications",
  tabs = {"All", "Room", "Global", "Tells", "Party"},
  allTab = "All",        -- Optional: receives copies of all messages
  activeTab = "All",     -- Optional: initially active tab
  dock = "right",
  height = 300,
})

Constructor Options

Option Type Default Description
name string required Unique identifier for the widget
title string name Display title shown in title bar
tabs table required Array of tab names
allTab string nil Tab that receives copies of all messages
activeTab string first tab Initially active tab
dock string nil "left", "right", or nil for floating
x number 100 Initial X position (floating only)
y number 100 Initial Y position (floating only)
height number 200 Widget height in pixels
visible boolean true Whether widget starts visible
row number auto Row index in dock (auto-assigned if nil)
rowPosition number 0 Position within a row for side-by-side placement
subRow number 0 Sub-row within a column for vertical sub-stacking
overflow string "wrap" Text overflow mode: "wrap", "ellipsis", or "hidden" (applies to all tabs)
fill boolean false Whether widget fills remaining dock column height (normally automatic)
fontAdjust number 0 Font size offset from the global content font size
onClose function nil Callback when widget is hidden
onTabChange function nil Callback when tab is switched

Callbacks

local comm = mdw.TabbedWidget:new({
  name = "Comm",
  tabs = {"All", "Room", "Chat"},
  allTab = "All",
  dock = "right",
  onTabChange = function(self, tabName)
    echo("Switched to tab: " .. tabName .. "\n")
  end,
  onClose = function(self)
    echo("Comm widget was hidden\n")
  end,
})

Display Methods

-- Echo to the currently active tab
comm:echo("Plain text\n")
comm:cecho("<red>Colored text\n")
comm:decho("<255,128,0>RGB text\n")
comm:hecho("#FF8000Hex text\n")
comm:clear()

-- Echo to a specific tab (also copies to "all" tab if configured)
comm:echoTo("Room", "Someone says: Hello!\n")
comm:cechoTo("Global", "<cyan>[Global] Message\n")
comm:dechoTo("Tells", "<255,200,100>Tell from Bob\n")
comm:hechoTo("Party", "#00FF00Party chat\n")

-- Clear specific or all tabs
comm:clearTab("Room")
comm:clearAll()

Tab Management

-- Switch tabs
comm:selectTab("Tells")

-- Get current tab info
local currentTab = comm:getActiveTab()     -- Returns tab name
local tabIndex = comm:getTabIndex("Room")  -- Returns numeric index

-- Get direct access to a tab's MiniConsole
local console = comm:getTab("Global")
console:echo("Direct console access\n")

-- Reorder tabs programmatically (1-based indices)
comm:reorderTab(3, 1)                      -- Move tab 3 to position 1
local order = comm:getTabOrder()           -- Returns {"All", "Room", ...}

Tabs can also be reordered by dragging them horizontally in the tab bar.

Other Methods

Tabbed widgets support all the same docking, visibility, appearance, and size methods as regular widgets:

comm:dock("left")
comm:undock()
comm:show()
comm:hide()
comm:setTitle("New Title")
comm:setFont("Consolas", 12)  -- Sets font for all tabs
comm:setFontAdjust(2)         -- Per-widget font size offset
comm:setContentStyleSheet([[background-color: rgb(20,20,30);]])
comm:resize(nil, 400)
comm:reflow()                 -- Replay buffered text at current width
comm:destroy()

See Widget Methods for full details on these shared methods.

Tabbed Widget Class Methods

-- Get a tabbed widget by name (returns nil for regular widgets)
local comm = mdw.TabbedWidget.get("Comm")

-- Get list of tabbed widget names only
local names = mdw.TabbedWidget.list()

The "All" Tab Feature

When you specify an allTab, any message sent via echoTo(), cechoTo(), etc. is automatically duplicated to the "all" tab (unless you're already echoing to the all tab):

local comm = mdw.TabbedWidget:new({
  name = "Chat",
  tabs = {"All", "Say", "Tell", "OOC"},
  allTab = "All",
  dock = "right",
})

-- This message appears in both "Say" and "All" tabs
comm:cechoTo("Say", "<white>You say: Hello!\n")

-- This message only appears in "All" tab (no duplication)
comm:cechoTo("All", "<gray>--- Session started ---\n")

Clone this wiki locally