MCPcopy
hub / github.com/Textualize/textual / render

Method render

src/textual/_styles_cache.py:163–255  ·  view source on GitHub ↗

Render a widget content plus CSS styles. Args: styles: CSS Styles object. size: Size of widget. base_background: Background color beneath widget. background: Background color of widget. render_content_line: Callback to render conte

(
        self,
        styles: StylesBase,
        size: Size,
        base_background: Color,
        background: Color,
        render_content_line: RenderLineCallback,
        filters: Sequence[LineFilter],
        border_title: tuple[Content, Color, Color, Style] | None,
        border_subtitle: tuple[Content, Color, Color, Style] | None,
        content_size: Size | None = None,
        padding: Spacing | None = None,
        crop: Region | None = None,
        opacity: float = 1.0,
        ansi_theme: TerminalTheme = DEFAULT_TERMINAL_THEME,
        native_ansi: bool = False,
    )

Source from the content-addressed store, hash-verified

161 return strips
162
163 def render(
164 self,
165 styles: StylesBase,
166 size: Size,
167 base_background: Color,
168 background: Color,
169 render_content_line: RenderLineCallback,
170 filters: Sequence[LineFilter],
171 border_title: tuple[Content, Color, Color, Style] | None,
172 border_subtitle: tuple[Content, Color, Color, Style] | None,
173 content_size: Size | None = None,
174 padding: Spacing | None = None,
175 crop: Region | None = None,
176 opacity: float = 1.0,
177 ansi_theme: TerminalTheme = DEFAULT_TERMINAL_THEME,
178 native_ansi: bool = False,
179 ) -> list[Strip]:
180 """Render a widget content plus CSS styles.
181
182 Args:
183 styles: CSS Styles object.
184 size: Size of widget.
185 base_background: Background color beneath widget.
186 background: Background color of widget.
187 render_content_line: Callback to render content line.
188 console: The console in use by the app.
189 border_title: Optional tuple of (title, color, background, style).
190 border_subtitle: Optional tuple of (subtitle, color, background, style).
191 content_size: Size of content or None to assume full size.
192 padding: Override padding from Styles, or None to use styles.padding.
193 crop: Region to crop to.
194 filters: Additional post-processing for the segments.
195 opacity: Widget opacity.
196 ansi_theme: Theme for ANSI colors.
197 native_ansi: Use native ANSI colors?
198
199 Returns:
200 Rendered lines.
201 """
202 if content_size is None:
203 content_size = size
204 if padding is None:
205 padding = styles.padding
206 if crop is None:
207 crop = size.region
208
209 width, _height = size
210 if width != self._width:
211 self.clear()
212 self._width = width
213 strips: list[Strip] = []
214 add_strip = strips.append
215
216 is_dirty = self._dirty_lines.__contains__
217 render_line = self.render_line
218
219 for y in crop.line_range:
220 if is_dirty(y) or y not in self._cache:

Callers 7

render_widgetMethod · 0.95
test_borderFunction · 0.95
test_paddingFunction · 0.95
test_padding_borderFunction · 0.95
test_outlineFunction · 0.95
test_cropFunction · 0.95
test_dirty_cacheFunction · 0.95

Calls 4

clearMethod · 0.95
apply_filterMethod · 0.80
cropMethod · 0.80
warningMethod · 0.45

Tested by 6

test_borderFunction · 0.76
test_paddingFunction · 0.76
test_padding_borderFunction · 0.76
test_outlineFunction · 0.76
test_cropFunction · 0.76
test_dirty_cacheFunction · 0.76