Skip to content
This repository has been archived by the owner on Aug 6, 2023. It is now read-only.

Feature: Block padding #551

Closed

Conversation

Igormandello
Copy link

Description

If we want to render a widget inside a block with a certain distance from its borders, we need to create another Layout element based on the outer Block, add a margin and render the Widget into it. Adding a padding property on the block element skips the creation of this second Layout.

This property works especially when rendering texts, as we can just create a block with padding and use it as the text wrapper:

let block = Block::default().borders(Borders::ALL).padding(4);
let paragraph = Paragraph::new("example paragraph").block(block);
f.render_widget(paragraph, area);

Rendering another widget should be easy too, using the .inner method:

let block = Block::default().borders(Borders::ALL).padding(4);
let inner_block = Block::default().borders(Borders::ALL);
let inner_area = block.inner(area);

f.render_widget(block, area);
f.render_widget(inner_block, inner_area);

Testing guidelines

The block.rs example contains two cases of use: one with an inner text and another with an inner block:
image

I've also changed the paragraph tests to include a padding of value 1 to the rendering tests.

Checklist

@alpha-tango-kilo
Copy link
Contributor

This would be awesome! I hope this gets merged 🙌

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants