text_view: Remove last paragraph bottom margin. (#660)
Now, we can be easy to use TextView for 1 line text. ## Break Changes - Removed `inline` method by previous #649 added, this is not needed.
This commit is contained in:
parent
f75f96f135
commit
9f429592ce
5 changed files with 14 additions and 23 deletions
|
|
@ -218,7 +218,6 @@ impl Render for SwitchStory {
|
|||
"The [long long label](https://github.com) text used markdown, \
|
||||
it should wrap when the text is too long.",
|
||||
)
|
||||
.inline(),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -386,6 +386,7 @@ impl Node {
|
|||
ordered: state.ordered,
|
||||
todo: checked.is_some(),
|
||||
}),
|
||||
true,
|
||||
text_view_style,
|
||||
window,
|
||||
cx,
|
||||
|
|
@ -399,6 +400,7 @@ impl Node {
|
|||
ordered: state.ordered,
|
||||
todo: checked.is_some(),
|
||||
}),
|
||||
true,
|
||||
text_view_style,
|
||||
window,
|
||||
cx,
|
||||
|
|
@ -489,12 +491,13 @@ impl Node {
|
|||
pub(crate) fn render(
|
||||
self,
|
||||
list_state: Option<ListState>,
|
||||
is_last_child: bool,
|
||||
text_view_style: &TextViewStyle,
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) -> impl IntoElement {
|
||||
let in_list = list_state.is_some();
|
||||
let mb = if in_list {
|
||||
let mb = if in_list || is_last_child {
|
||||
rems(0.)
|
||||
} else {
|
||||
text_view_style.paragraph_gap
|
||||
|
|
@ -502,11 +505,14 @@ impl Node {
|
|||
|
||||
match self {
|
||||
Node::Root { children } => div()
|
||||
.children(
|
||||
children
|
||||
.into_iter()
|
||||
.map(|c| c.render(None, text_view_style, window, cx)),
|
||||
)
|
||||
.children({
|
||||
let children_len = children.len();
|
||||
|
||||
children.into_iter().enumerate().map(move |(ix, c)| {
|
||||
let is_last_child = ix == children_len - 1;
|
||||
c.render(None, is_last_child, text_view_style, window, cx)
|
||||
})
|
||||
})
|
||||
.into_any_element(),
|
||||
Node::Paragraph(paragraph) => div().mb(mb).child(paragraph).into_any_element(),
|
||||
Node::Heading { level, children } => {
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ impl Element for HtmlElement {
|
|||
|
||||
let mut el = div()
|
||||
.map(|this| match root {
|
||||
Ok(node) => this.child(node.render(None, &self.style, window, cx)),
|
||||
Ok(node) => this.child(node.render(None, true, &self.style, window, cx)),
|
||||
Err(err) => this.child(
|
||||
v_flex()
|
||||
.gap_1()
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ impl Element for MarkdownElement {
|
|||
|
||||
let mut el = div()
|
||||
.map(|this| match root {
|
||||
Ok(node) => this.child(node.render(None, &self.style, window, cx)),
|
||||
Ok(node) => this.child(node.render(None, true, &self.style, window, cx)),
|
||||
Err(err) => this.child(
|
||||
v_flex()
|
||||
.gap_1()
|
||||
|
|
|
|||
|
|
@ -64,15 +64,6 @@ impl Default for TextViewStyle {
|
|||
}
|
||||
|
||||
impl TextViewStyle {
|
||||
/// Default style for inline text.
|
||||
///
|
||||
/// This style has no paragraph gap.
|
||||
pub fn inline() -> Self {
|
||||
Self {
|
||||
paragraph_gap: rems(0.),
|
||||
}
|
||||
}
|
||||
|
||||
/// Set paragraph gap, default is 1 rem.
|
||||
pub fn paragraph_gap(mut self, gap: Rems) -> Self {
|
||||
self.paragraph_gap = gap;
|
||||
|
|
@ -106,11 +97,6 @@ impl TextView {
|
|||
Self::Html(el) => Self::Html(el.style(style)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Set to use [`TextViewStyle::inline`].
|
||||
pub fn inline(self) -> Self {
|
||||
self.style(TextViewStyle::inline())
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for TextView {
|
||||
|
|
|
|||
Loading…
Reference in a new issue