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, \
|
"The [long long label](https://github.com) text used markdown, \
|
||||||
it should wrap when the text is too long.",
|
it should wrap when the text is too long.",
|
||||||
)
|
)
|
||||||
.inline(),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -386,6 +386,7 @@ impl Node {
|
||||||
ordered: state.ordered,
|
ordered: state.ordered,
|
||||||
todo: checked.is_some(),
|
todo: checked.is_some(),
|
||||||
}),
|
}),
|
||||||
|
true,
|
||||||
text_view_style,
|
text_view_style,
|
||||||
window,
|
window,
|
||||||
cx,
|
cx,
|
||||||
|
|
@ -399,6 +400,7 @@ impl Node {
|
||||||
ordered: state.ordered,
|
ordered: state.ordered,
|
||||||
todo: checked.is_some(),
|
todo: checked.is_some(),
|
||||||
}),
|
}),
|
||||||
|
true,
|
||||||
text_view_style,
|
text_view_style,
|
||||||
window,
|
window,
|
||||||
cx,
|
cx,
|
||||||
|
|
@ -489,12 +491,13 @@ impl Node {
|
||||||
pub(crate) fn render(
|
pub(crate) fn render(
|
||||||
self,
|
self,
|
||||||
list_state: Option<ListState>,
|
list_state: Option<ListState>,
|
||||||
|
is_last_child: bool,
|
||||||
text_view_style: &TextViewStyle,
|
text_view_style: &TextViewStyle,
|
||||||
window: &mut Window,
|
window: &mut Window,
|
||||||
cx: &mut App,
|
cx: &mut App,
|
||||||
) -> impl IntoElement {
|
) -> impl IntoElement {
|
||||||
let in_list = list_state.is_some();
|
let in_list = list_state.is_some();
|
||||||
let mb = if in_list {
|
let mb = if in_list || is_last_child {
|
||||||
rems(0.)
|
rems(0.)
|
||||||
} else {
|
} else {
|
||||||
text_view_style.paragraph_gap
|
text_view_style.paragraph_gap
|
||||||
|
|
@ -502,11 +505,14 @@ impl Node {
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
Node::Root { children } => div()
|
Node::Root { children } => div()
|
||||||
.children(
|
.children({
|
||||||
children
|
let children_len = children.len();
|
||||||
.into_iter()
|
|
||||||
.map(|c| c.render(None, text_view_style, window, cx)),
|
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(),
|
.into_any_element(),
|
||||||
Node::Paragraph(paragraph) => div().mb(mb).child(paragraph).into_any_element(),
|
Node::Paragraph(paragraph) => div().mb(mb).child(paragraph).into_any_element(),
|
||||||
Node::Heading { level, children } => {
|
Node::Heading { level, children } => {
|
||||||
|
|
|
||||||
|
|
@ -160,7 +160,7 @@ impl Element for HtmlElement {
|
||||||
|
|
||||||
let mut el = div()
|
let mut el = div()
|
||||||
.map(|this| match root {
|
.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(
|
Err(err) => this.child(
|
||||||
v_flex()
|
v_flex()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ impl Element for MarkdownElement {
|
||||||
|
|
||||||
let mut el = div()
|
let mut el = div()
|
||||||
.map(|this| match root {
|
.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(
|
Err(err) => this.child(
|
||||||
v_flex()
|
v_flex()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
|
|
|
||||||
|
|
@ -64,15 +64,6 @@ impl Default for TextViewStyle {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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.
|
/// Set paragraph gap, default is 1 rem.
|
||||||
pub fn paragraph_gap(mut self, gap: Rems) -> Self {
|
pub fn paragraph_gap(mut self, gap: Rems) -> Self {
|
||||||
self.paragraph_gap = gap;
|
self.paragraph_gap = gap;
|
||||||
|
|
@ -106,11 +97,6 @@ impl TextView {
|
||||||
Self::Html(el) => Self::Html(el.style(style)),
|
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 {
|
impl RenderOnce for TextView {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue