Skip to content

Commit 309db8a

Browse files
committed
Allow str-like objects as labels
1 parent e11ca64 commit 309db8a

5 files changed

Lines changed: 48 additions & 38 deletions

File tree

backend-embedded-graphics/src/themes/basic/button/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,12 @@ where
220220
}
221221

222222
// Type alias to decouple button definition from theme
223-
pub type StyledButton<'a, C> =
224-
StyledButtonDecorator<C, Spacing<Label<&'static str, LabelStyle<MonoTextStyle<'a, C>>>>>;
223+
pub type StyledButton<S, C> =
224+
StyledButtonDecorator<C, Spacing<Label<S, LabelStyle<MonoTextStyle<'static, C>>>>>;
225225

226-
pub fn styled_button<C, S>(label: &'static str) -> StyledButton<C::PixelColor>
226+
pub fn styled_button<ST, C, S>(label: ST) -> StyledButton<ST, C::PixelColor>
227227
where
228+
ST: AsRef<str>,
228229
C: BasicTheme,
229230
S: ButtonStyle<C::PixelColor>,
230231
{
@@ -239,18 +240,19 @@ where
239240
)
240241
}
241242

242-
pub type StyledButtonStretched<'a, C> = StyledButtonDecorator<
243+
pub type StyledButtonStretched<S, C> = StyledButtonDecorator<
243244
C,
244245
FillParent<
245-
Label<&'static str, LabelStyle<MonoTextStyle<'a, C>>>,
246+
Label<S, LabelStyle<MonoTextStyle<'static, C>>>,
246247
HorizontalAndVertical,
247248
Center,
248249
Center,
249250
>,
250251
>;
251252

252-
pub fn styled_button_stretched<C, S>(label: &'static str) -> StyledButtonStretched<C::PixelColor>
253+
pub fn styled_button_stretched<ST, C, S>(label: ST) -> StyledButtonStretched<ST, C::PixelColor>
253254
where
255+
ST: AsRef<str>,
254256
C: BasicTheme,
255257
S: ButtonStyle<C::PixelColor>,
256258
{

backend-embedded-graphics/src/themes/basic/check_box/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,12 @@ where
206206
}
207207

208208
// Type alias to decouple toggle button definition from theme
209-
pub type StyledCheckBox<'a, C> =
210-
StyledCheckBoxDecorator<C, Label<&'static str, LabelStyle<MonoTextStyle<'a, C>>>>;
209+
pub type StyledCheckBox<S, C> =
210+
StyledCheckBoxDecorator<C, Label<S, LabelStyle<MonoTextStyle<'static, C>>>>;
211211

212-
pub fn styled_check_box<C, S>(label: &'static str) -> StyledCheckBox<C::PixelColor>
212+
pub fn styled_check_box<ST, C, S>(label: ST) -> StyledCheckBox<ST, C::PixelColor>
213213
where
214+
ST: AsRef<str>,
214215
C: BasicTheme,
215216
S: CheckBoxVisualStyle<C::PixelColor>,
216217
{

backend-embedded-graphics/src/themes/basic/mod.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,38 +46,42 @@ pub trait BasicTheme: Sized {
4646
styled_label::<Self, Self::LabelStyle, _>(label)
4747
}
4848

49-
fn primary_button(label: &'static str) -> StyledButton<Self::PixelColor> {
50-
styled_button::<Self, Self::PrimaryButton>(label)
49+
fn primary_button<S: AsRef<str>>(label: S) -> StyledButton<S, Self::PixelColor> {
50+
styled_button::<_, Self, Self::PrimaryButton>(label)
5151
}
5252

53-
fn secondary_button(label: &'static str) -> StyledButton<Self::PixelColor> {
54-
styled_button::<Self, Self::SecondaryButton>(label)
53+
fn secondary_button<S: AsRef<str>>(label: S) -> StyledButton<S, Self::PixelColor> {
54+
styled_button::<_, Self, Self::SecondaryButton>(label)
5555
}
5656

57-
fn primary_button_stretched(label: &'static str) -> StyledButtonStretched<Self::PixelColor> {
58-
styled_button_stretched::<Self, Self::PrimaryButton>(label)
57+
fn primary_button_stretched<S: AsRef<str>>(
58+
label: S,
59+
) -> StyledButtonStretched<S, Self::PixelColor> {
60+
styled_button_stretched::<_, Self, Self::PrimaryButton>(label)
5961
}
6062

61-
fn secondary_button_stretched(label: &'static str) -> StyledButtonStretched<Self::PixelColor> {
62-
styled_button_stretched::<Self, Self::SecondaryButton>(label)
63+
fn secondary_button_stretched<S: AsRef<str>>(
64+
label: S,
65+
) -> StyledButtonStretched<S, Self::PixelColor> {
66+
styled_button_stretched::<_, Self, Self::SecondaryButton>(label)
6367
}
6468

65-
fn toggle_button(label: &'static str) -> StyledToggleButton<Self::PixelColor> {
66-
styled_toggle_button::<Self, Self::ToggleButton>(label)
69+
fn toggle_button<S: AsRef<str>>(label: S) -> StyledToggleButton<S, Self::PixelColor> {
70+
styled_toggle_button::<_, Self, Self::ToggleButton>(label)
6771
}
6872

69-
fn toggle_button_stretched(
70-
label: &'static str,
71-
) -> StyledToggleButtonStretched<Self::PixelColor> {
72-
styled_toggle_button_stretched::<Self, Self::ToggleButton>(label)
73+
fn toggle_button_stretched<S: AsRef<str>>(
74+
label: S,
75+
) -> StyledToggleButtonStretched<S, Self::PixelColor> {
76+
styled_toggle_button_stretched::<_, Self, Self::ToggleButton>(label)
7377
}
7478

75-
fn check_box(label: &'static str) -> StyledCheckBox<Self::PixelColor> {
76-
styled_check_box::<Self, Self::CheckBox>(label)
79+
fn check_box<S: AsRef<str>>(label: S) -> StyledCheckBox<S, Self::PixelColor> {
80+
styled_check_box::<_, Self, Self::CheckBox>(label)
7781
}
7882

79-
fn radio_button(label: &'static str) -> StyledRadioButton<Self::PixelColor> {
80-
styled_radio_button::<Self, Self::RadioButton>(label)
83+
fn radio_button<S: AsRef<str>>(label: S) -> StyledRadioButton<S, Self::PixelColor> {
84+
styled_radio_button::<_, Self, Self::RadioButton>(label)
8185
}
8286

8387
fn horizontal_scrollbar(

backend-embedded-graphics/src/themes/basic/radio_button/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,12 @@ where
206206
}
207207

208208
// Type alias to decouple toggle button definition from theme
209-
pub type StyledRadioButton<'a, C> =
210-
StyledRadioButtonDecorator<C, Label<&'static str, LabelStyle<MonoTextStyle<'a, C>>>>;
209+
pub type StyledRadioButton<S, C> =
210+
StyledRadioButtonDecorator<C, Label<S, LabelStyle<MonoTextStyle<'static, C>>>>;
211211

212-
pub fn styled_radio_button<C, S>(label: &'static str) -> StyledRadioButton<C::PixelColor>
212+
pub fn styled_radio_button<ST, C, S>(label: ST) -> StyledRadioButton<ST, C::PixelColor>
213213
where
214+
ST: AsRef<str>,
214215
C: BasicTheme,
215216
S: RadioButtonVisualStyle<C::PixelColor>,
216217
{

backend-embedded-graphics/src/themes/basic/toggle_button/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,12 @@ where
255255
}
256256

257257
// Type alias to decouple toggle button definition from theme
258-
pub type StyledToggleButton<'a, C> =
259-
StyledToggleButtonDecorator<C, Spacing<Label<&'static str, LabelStyle<MonoTextStyle<'a, C>>>>>;
258+
pub type StyledToggleButton<S, C> =
259+
StyledToggleButtonDecorator<C, Spacing<Label<S, LabelStyle<MonoTextStyle<'static, C>>>>>;
260260

261-
pub fn styled_toggle_button<C, S>(label: &'static str) -> StyledToggleButton<C::PixelColor>
261+
pub fn styled_toggle_button<ST, C, S>(label: ST) -> StyledToggleButton<ST, C::PixelColor>
262262
where
263+
ST: AsRef<str>,
263264
C: BasicTheme,
264265
S: ToggleButtonStyle<C::PixelColor>,
265266
{
@@ -277,20 +278,21 @@ where
277278
)
278279
}
279280

280-
pub type StyledToggleButtonStretched<'a, C> = StyledToggleButtonDecorator<
281+
pub type StyledToggleButtonStretched<S, C> = StyledToggleButtonDecorator<
281282
C,
282283
FillParent<
283-
Label<&'static str, LabelStyle<MonoTextStyle<'a, C>>>,
284+
Label<S, LabelStyle<MonoTextStyle<'static, C>>>,
284285
HorizontalAndVertical,
285286
Center,
286287
Center,
287288
>,
288289
>;
289290

290-
pub fn styled_toggle_button_stretched<C, S>(
291-
label: &'static str,
292-
) -> StyledToggleButtonStretched<C::PixelColor>
291+
pub fn styled_toggle_button_stretched<ST, C, S>(
292+
label: ST,
293+
) -> StyledToggleButtonStretched<ST, C::PixelColor>
293294
where
295+
ST: AsRef<str>,
294296
C: BasicTheme,
295297
S: ToggleButtonStyle<C::PixelColor>,
296298
{

0 commit comments

Comments
 (0)