improv(segmented-button): Add more From implementations for ButtonContent
This commit is contained in:
parent
bbac6b9bbf
commit
b13ad0b453
2 changed files with 26 additions and 19 deletions
|
|
@ -274,28 +274,16 @@ impl Application for Window {
|
|||
window.spin_button.max = 10;
|
||||
|
||||
// Configures the demo view switcher.
|
||||
let key = window
|
||||
.demo_view_switcher
|
||||
.insert(String::from("Tab A"), DemoView::TabA);
|
||||
|
||||
let key = window.demo_view_switcher.insert("Tab A", DemoView::TabA);
|
||||
window.demo_view_switcher.activate(key);
|
||||
|
||||
window
|
||||
.demo_view_switcher
|
||||
.insert(String::from("Tab B"), DemoView::TabB);
|
||||
|
||||
window
|
||||
.demo_view_switcher
|
||||
.insert(String::from("Tab C"), DemoView::TabC);
|
||||
window.demo_view_switcher.insert("Tab B", DemoView::TabB);
|
||||
window.demo_view_switcher.insert("Tab C", DemoView::TabC);
|
||||
|
||||
// Configures the demo selection button.
|
||||
let key = window.
|
||||
demo_selection
|
||||
.insert(String::from("Choice A"), ());
|
||||
|
||||
let key = window.demo_selection.insert("Choice A", ());
|
||||
window.demo_selection.activate(key);
|
||||
window.demo_selection.insert(String::from("Choice B"), ());
|
||||
window.demo_selection.insert(String::from("Choice C"), ());
|
||||
window.demo_selection.insert("Choice B", ());
|
||||
window.demo_selection.insert("Choice C", ());
|
||||
|
||||
(window, Command::none())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
/// Copyright 2022 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
use slotmap::{SecondaryMap, SlotMap};
|
||||
use std::borrow::Cow;
|
||||
|
||||
use crate::theme::Button;
|
||||
|
||||
slotmap::new_key_type! {
|
||||
pub struct Key;
|
||||
|
|
@ -71,11 +74,27 @@ impl<Data> State<Data> {
|
|||
|
||||
/// Data to be drawn in a [`SegmentedButton`] button.
|
||||
pub struct ButtonContent {
|
||||
pub text: String,
|
||||
pub text: Cow<'static, str>,
|
||||
}
|
||||
|
||||
impl From<String> for ButtonContent {
|
||||
fn from(text: String) -> Self {
|
||||
ButtonContent {
|
||||
text: Cow::Owned(text),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&'static str> for ButtonContent {
|
||||
fn from(text: &'static str) -> Self {
|
||||
ButtonContent {
|
||||
text: Cow::Borrowed(text),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Cow<'static, str>> for ButtonContent {
|
||||
fn from(text: Cow<'static, str>) -> Self {
|
||||
ButtonContent { text }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue