Skip to main content

ZonePlugin

Trait ZonePlugin 

Source
pub trait ZonePlugin: Send + Sync {
    // Required methods
    fn id(&self) -> &str;
    fn render(
        &self,
        zone_id: ZoneId,
        ctx: &RenderContext,
        area: Rect,
        buf: &mut Buffer,
    ) -> bool;

    // Provided methods
    fn zones(&self) -> Vec<ZoneRequest> { ... }
    fn on_register(&self, _zone_id: ZoneId) { ... }
    fn on_event(&self, _zone_id: ZoneId, _event: &ZoneEvent) -> bool { ... }
}
Expand description

A plugin that owns one or more zones in the TUI.

Implement this trait to contribute UI to a ratatui application. The host calls methods in this order:

  1. id() + zones() — once at registration
  2. on_register(zone_id) — once per granted zone
  3. render(zone_id, ctx, area, buf) — every frame per visible zone
  4. on_event(zone_id, event) — when a relevant event occurs

§Theme Agnosticism

The RenderContext.base_style carries the host’s theme as a plain ratatui::style::Style. This works with any styling system:

  • ratatui-themekit: host sets base_style = theme.style_base()
  • Raw styles: host sets base_style = Style::default().bg(Color::Rgb(...))
  • Custom: any Style value

Plugins that want to use themekit directly can depend on it themselves — zonekit does not require or prevent this.

Required Methods§

Source

fn id(&self) -> &str

Unique plugin identifier (e.g., "official.bmad").

Source

fn render( &self, zone_id: ZoneId, ctx: &RenderContext, area: Rect, buf: &mut Buffer, ) -> bool

Renders the plugin’s content into the granted zone.

area is the allocated Rect — plugin MUST NOT write outside it. buf is the buffer slice for this area. ctx carries theme style, focus state, and terminal dimensions.

Return false if the zone has nothing to show (host may hide it).

Provided Methods§

Source

fn zones(&self) -> Vec<ZoneRequest>

Zone requests — what zones this plugin wants to own.

Called once during registration. Each request is evaluated by the host, which may grant or deny based on available space.

Source

fn on_register(&self, _zone_id: ZoneId)

Called when the host grants a zone to this plugin.

Uses &self — plugins that need to store the zone ID should use interior mutability (e.g., Cell, Mutex).

Source

fn on_event(&self, _zone_id: ZoneId, _event: &ZoneEvent) -> bool

Called when a keyboard or mouse event occurs in this zone.

Return true if the event was handled (prevents propagation).

Implementors§