Skip to content

Commit de137eb

Browse files
committed
chore: Optional for style in Text
1 parent 8d24c16 commit de137eb

File tree

8 files changed

+29
-23
lines changed

8 files changed

+29
-23
lines changed

promkit-widgets/src/text.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct State {
1313
pub text: Text,
1414

1515
/// Style for the text string.
16-
pub style: ContentStyle,
16+
pub style: Option<ContentStyle>,
1717

1818
/// Maximum number of lines to display.
1919
pub lines: Option<usize>,
@@ -42,7 +42,13 @@ impl PaneFactory for State {
4242
.iter()
4343
.enumerate()
4444
.filter(|(i, _)| *i >= self.text.position() && *i < self.text.position() + height)
45-
.map(|(_, item)| item.clone().apply_style(self.style))
45+
.map(|(_, item)| {
46+
if let Some(style) = &self.style {
47+
item.clone().apply_style(style.clone())
48+
} else {
49+
item.clone()
50+
}
51+
})
4652
.fold((vec![], 0), |(mut acc, pos), item| {
4753
let rows = item.matrixify(width as usize, height, 0).0;
4854
if pos < self.text.position() + height {

promkit/src/preset/checkbox.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ impl Checkbox {
8585
renderer: None,
8686
evaluator: |event, ctx| Box::pin(evaluate::default(event, ctx)),
8787
title: text::State {
88-
style: ContentStyle {
88+
style: Some(ContentStyle {
8989
attributes: Attributes::from(Attribute::Bold),
9090
..Default::default()
91-
},
91+
}),
9292
..Default::default()
9393
},
9494
checkbox: checkbox::State {
@@ -124,7 +124,7 @@ impl Checkbox {
124124

125125
/// Sets the style for the title text.
126126
pub fn title_style(mut self, style: ContentStyle) -> Self {
127-
self.title.style = style;
127+
self.title.style = Some(style);
128128
self
129129
}
130130

promkit/src/preset/json.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ impl Json {
7777
renderer: None,
7878
evaluator: |event, ctx| Box::pin(evaluate::default(event, ctx)),
7979
title: text::State {
80-
style: ContentStyle {
80+
style: Some(ContentStyle {
8181
attributes: Attributes::from(Attribute::Bold),
8282
..Default::default()
83-
},
83+
}),
8484
..Default::default()
8585
},
8686
json: jsonstream::State {
@@ -125,7 +125,7 @@ impl Json {
125125

126126
/// Sets the style for the title text.
127127
pub fn title_style(mut self, style: ContentStyle) -> Self {
128-
self.title.style = style;
128+
self.title.style = Some(style);
129129
self
130130
}
131131

promkit/src/preset/listbox.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ impl Listbox {
8585
renderer: None,
8686
evaluator: |event, ctx| Box::pin(evaluate::default(event, ctx)),
8787
title: text::State {
88-
style: ContentStyle {
88+
style: Some(ContentStyle {
8989
attributes: Attributes::from(Attribute::Bold),
9090
..Default::default()
91-
},
91+
}),
9292
..Default::default()
9393
},
9494
listbox: listbox::State {
@@ -112,7 +112,7 @@ impl Listbox {
112112

113113
/// Sets the style for the title text.
114114
pub fn title_style(mut self, style: ContentStyle) -> Self {
115-
self.title.style = style;
115+
self.title.style = Some(style);
116116
self
117117
}
118118

promkit/src/preset/query_selector.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ impl QuerySelector {
131131
renderer: None,
132132
evaluator: |event, ctx| Box::pin(evaluate::default(event, ctx)),
133133
title: text::State {
134-
style: ContentStyle {
134+
style: Some(ContentStyle {
135135
attributes: Attributes::from(Attribute::Bold),
136136
..Default::default()
137-
},
137+
}),
138138
..Default::default()
139139
},
140140
readline: text_editor::State {
@@ -178,7 +178,7 @@ impl QuerySelector {
178178

179179
/// Sets the style for the title text.
180180
pub fn title_style(mut self, style: ContentStyle) -> Self {
181-
self.title.style = style;
181+
self.title.style = Some(style);
182182
self
183183
}
184184

promkit/src/preset/readline.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ impl Default for Readline {
7373
evaluator: |event, ctx| Box::pin(evaluate::default(event, ctx)),
7474
focus: Focus::Readline,
7575
title: text::State {
76-
style: ContentStyle {
76+
style: Some(ContentStyle {
7777
attributes: Attributes::from(Attribute::Bold),
7878
..Default::default()
79-
},
79+
}),
8080
..Default::default()
8181
},
8282
readline: text_editor::State {
@@ -115,11 +115,11 @@ impl Default for Readline {
115115
validator: Default::default(),
116116
error_message: text::State {
117117
text: Default::default(),
118-
style: ContentStyle {
118+
style: Some(ContentStyle {
119119
foreground_color: Some(Color::DarkRed),
120120
attributes: Attributes::from(Attribute::Bold),
121121
..Default::default()
122-
},
122+
}),
123123
lines: None,
124124
},
125125
}
@@ -179,7 +179,7 @@ impl Readline {
179179

180180
/// Sets the style for the title text.
181181
pub fn title_style(mut self, style: ContentStyle) -> Self {
182-
self.title.style = style;
182+
self.title.style = Some(style);
183183
self
184184
}
185185

promkit/src/preset/text.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Text {
7373

7474
/// Sets the style for the text component.
7575
pub fn style(mut self, style: ContentStyle) -> Self {
76-
self.text.style = style;
76+
self.text.style = Some(style);
7777
self
7878
}
7979

promkit/src/preset/tree.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ impl Tree {
7878
renderer: None,
7979
evaluator: |event, ctx| Box::pin(evaluate::default(event, ctx)),
8080
title: text::State {
81-
style: ContentStyle {
81+
style: Some(ContentStyle {
8282
attributes: Attributes::from(Attribute::Bold),
8383
..Default::default()
84-
},
84+
}),
8585
..Default::default()
8686
},
8787
tree: tree::State {
@@ -107,7 +107,7 @@ impl Tree {
107107

108108
/// Sets the style for the title text.
109109
pub fn title_style(mut self, style: ContentStyle) -> Self {
110-
self.title.style = style;
110+
self.title.style = Some(style);
111111
self
112112
}
113113

0 commit comments

Comments
 (0)