|
1 | 1 | use iced::{widget::tooltip, Length};
|
2 | 2 |
|
| 3 | +use crate::util::Collection; |
3 | 4 | use crate::{component::text, icon, image, theme, widget::*};
|
4 | 5 |
|
5 | 6 | pub struct Badge {
|
@@ -75,66 +76,88 @@ pub fn coin<T>() -> Container<'static, T> {
|
75 | 76 | }
|
76 | 77 |
|
77 | 78 | pub fn recovery<'a, T: 'a>() -> Container<'a, T> {
|
78 |
| - Container::new( |
79 |
| - tooltip::Tooltip::new( |
80 |
| - Container::new(text::p2_regular(" Recovery ")) |
81 |
| - .padding(10) |
82 |
| - .style(theme::Container::Pill(theme::Pill::Simple)), |
83 |
| - "This transaction is using a recovery path", |
84 |
| - tooltip::Position::Top, |
85 |
| - ) |
86 |
| - .style(theme::Container::Card(theme::Card::Simple)), |
| 79 | + badge_pill( |
| 80 | + " Recovery ", |
| 81 | + "This transaction is using a recovery path", |
| 82 | + None, |
87 | 83 | )
|
88 | 84 | }
|
89 | 85 |
|
90 | 86 | pub fn unconfirmed<'a, T: 'a>() -> Container<'a, T> {
|
91 |
| - Container::new( |
92 |
| - tooltip::Tooltip::new( |
93 |
| - Container::new(text::p2_regular(" Unconfirmed ")) |
94 |
| - .padding(10) |
95 |
| - .style(theme::Container::Pill(theme::Pill::Simple)), |
96 |
| - "Do not treat this as a payment until it is confirmed", |
97 |
| - tooltip::Position::Top, |
98 |
| - ) |
99 |
| - .style(theme::Container::Card(theme::Card::Simple)), |
| 87 | + badge_pill( |
| 88 | + " Unconfirmed ", |
| 89 | + "Do not treat this as a payment until it is confirmed", |
| 90 | + None, |
| 91 | + ) |
| 92 | +} |
| 93 | + |
| 94 | +pub fn unconfirmed_sized<'a, T: 'a>(width: f32) -> Container<'a, T> { |
| 95 | + badge_pill( |
| 96 | + " Unconfirmed ", |
| 97 | + "Do not treat this as a payment until it is confirmed", |
| 98 | + Some(width), |
100 | 99 | )
|
101 | 100 | }
|
102 | 101 |
|
103 | 102 | pub fn batch<'a, T: 'a>() -> Container<'a, T> {
|
104 |
| - Container::new( |
105 |
| - tooltip::Tooltip::new( |
106 |
| - Container::new(text::p2_regular(" Batch ")) |
107 |
| - .padding(10) |
108 |
| - .style(theme::Container::Pill(theme::Pill::Simple)), |
109 |
| - "This transaction contains multiple payments", |
110 |
| - tooltip::Position::Top, |
111 |
| - ) |
112 |
| - .style(theme::Container::Card(theme::Card::Simple)), |
| 103 | + badge_pill( |
| 104 | + " Batch ", |
| 105 | + "This transaction contains multiple payments", |
| 106 | + None, |
113 | 107 | )
|
114 | 108 | }
|
115 | 109 |
|
116 | 110 | pub fn deprecated<'a, T: 'a>() -> Container<'a, T> {
|
117 |
| - Container::new( |
118 |
| - tooltip::Tooltip::new( |
119 |
| - Container::new(text::p2_regular(" Deprecated ")) |
120 |
| - .padding(10) |
121 |
| - .style(theme::Container::Pill(theme::Pill::Simple)), |
122 |
| - "This transaction cannot be included in the blockchain anymore.", |
123 |
| - tooltip::Position::Top, |
124 |
| - ) |
125 |
| - .style(theme::Container::Card(theme::Card::Simple)), |
| 111 | + badge_pill( |
| 112 | + " Deprecated ", |
| 113 | + "This transaction cannot be included in the blockchain anymore.", |
| 114 | + None, |
| 115 | + ) |
| 116 | +} |
| 117 | + |
| 118 | +pub fn deprecated_sized<'a, T: 'a>(width: f32) -> Container<'a, T> { |
| 119 | + badge_pill( |
| 120 | + " Deprecated ", |
| 121 | + "This transaction cannot be included in the blockchain anymore.", |
| 122 | + Some(width), |
126 | 123 | )
|
127 | 124 | }
|
128 | 125 |
|
129 | 126 | pub fn spent<'a, T: 'a>() -> Container<'a, T> {
|
130 |
| - Container::new( |
131 |
| - tooltip::Tooltip::new( |
132 |
| - Container::new(text::p2_regular(" Spent ")) |
133 |
| - .padding(10) |
134 |
| - .style(theme::Container::Pill(theme::Pill::Simple)), |
135 |
| - "The transaction was included in the blockchain.", |
136 |
| - tooltip::Position::Top, |
137 |
| - ) |
138 |
| - .style(theme::Container::Card(theme::Card::Simple)), |
| 127 | + badge_pill( |
| 128 | + " Spent ", |
| 129 | + "The transaction was included in the blockchain.", |
| 130 | + None, |
| 131 | + ) |
| 132 | +} |
| 133 | + |
| 134 | +pub fn spent_sized<'a, T: 'a>(width: f32) -> Container<'a, T> { |
| 135 | + badge_pill( |
| 136 | + " Spent ", |
| 137 | + "The transaction was included in the blockchain.", |
| 138 | + Some(width), |
139 | 139 | )
|
140 | 140 | }
|
| 141 | + |
| 142 | +pub fn badge_pill<'a, T: 'a>( |
| 143 | + label: &'a str, |
| 144 | + tooltip: &'a str, |
| 145 | + width: Option<f32>, |
| 146 | +) -> Container<'a, T> { |
| 147 | + Container::new({ |
| 148 | + let mut pill: Container<'a, T> = Container::new( |
| 149 | + Row::new() |
| 150 | + .push_maybe(width.map(|_| iced::widget::Space::with_width(Length::Fill))) |
| 151 | + .push(text::p2_regular(label)) |
| 152 | + .push_maybe(width.map(|_| iced::widget::Space::with_width(Length::Fill))), |
| 153 | + ) |
| 154 | + .padding(10) |
| 155 | + .style(theme::Container::Pill(theme::Pill::Simple)); |
| 156 | + if let Some(w) = width { |
| 157 | + pill = pill.width(Length::Fixed(w)); |
| 158 | + } |
| 159 | + |
| 160 | + tooltip::Tooltip::new(pill, tooltip, tooltip::Position::Top) |
| 161 | + .style(theme::Container::Card(theme::Card::Simple)) |
| 162 | + }) |
| 163 | +} |
0 commit comments