1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: 2026 FernTech
//! Tier-3 style protocol for `RichTextEditor`. See `docs/styling-system.md`.
//!
//! Themes only the *frame* — border, padding, focus ring, background —
//! the same surface a `TextInput` has. The body's `paint` renders
//! glyph runs, caret, and selection itself; that is the editor's
//! domain output and stays widget-owned (principle 6).
//!
//! The `RichTextEditor` widget is wired through `make_body` — the
//! composing outer widget owns state, handlers, focus, while the
//! inner leaf body owns layout, paint, and accessibility. Apps
//! install a chrome override via
//! `RichTextEditor::style(impl RichTextEditorStyle)` or the
//! theme-wide `style_slots.rich_text_editor` slot.
use std::rc::Rc;
use crate::build_context::BuildContext;
use crate::signal::Signal;
use crate::widget_id::WidgetId;
pub struct RichTextEditorStyleConfig {
/// Pre-built editor viewport (the leaf widget that paints text).
pub viewport: WidgetId,
/// Reactive focus signal — drives the focus-ring colour.
pub is_focused: Signal<bool>,
/// `true` when the editor is in read-only / viewer mode.
pub is_read_only: bool,
/// Per-edge `(top, right, bottom, left)` padding between the text
/// content and the chrome border. `None` means the style picks its
/// own default (TextInput-style insets for editable, no padding for
/// read-only). Set via `RichTextEditor::content_padding`.
pub content_padding: Option<(f32, f32, f32, f32)>,
/// App-supplied background fill (`RichTextEditor::background`). When `Some`,
/// the style should paint this instead of its default surface — so the
/// common "give the editor a surface" case needs no custom style. `None`
/// keeps the style's own default.
pub background: Option<crate::color_prop::ColorProp>,
}
pub trait RichTextEditorStyle: 'static {
fn make_body(&self, cfg: &RichTextEditorStyleConfig, ctx: &mut BuildContext) -> WidgetId;
}
pub type SharedRichTextEditorStyle = Rc<dyn RichTextEditorStyle>;