Skip to content

Commit 66f392c

Browse files
author
pythcoiner
committed
fixed size for badges
1 parent 3fcbb0b commit 66f392c

File tree

2 files changed

+75
-52
lines changed

2 files changed

+75
-52
lines changed

gui/src/app/view/psbts.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,17 @@ fn spend_tx_list_view(i: usize, tx: &SpendTx) -> Element<'_, Message> {
133133
.align_items(Alignment::Center)
134134
.width(Length::Fill),
135135
)
136-
.push_maybe(match tx.status {
137-
SpendStatus::Deprecated => Some(badge::deprecated()),
138-
SpendStatus::Broadcast => Some(badge::unconfirmed()),
139-
SpendStatus::Spent => Some(badge::spent()),
140-
_ => None,
141-
})
142136
.push_maybe(if tx.is_batch() {
143137
Some(badge::batch())
144138
} else {
145139
None
146140
})
141+
.push_maybe(match tx.status {
142+
SpendStatus::Deprecated => Some(badge::deprecated_sized(120.0)),
143+
SpendStatus::Broadcast => Some(badge::unconfirmed_sized(120.0)),
144+
SpendStatus::Spent => Some(badge::spent_sized(120.0)),
145+
_ => None,
146+
})
147147
.push(
148148
Column::new()
149149
.align_items(Alignment::End)
@@ -153,7 +153,7 @@ fn spend_tx_list_view(i: usize, tx: &SpendTx) -> Element<'_, Message> {
153153
Container::new(p1_regular("Self-transfer"))
154154
})
155155
.push_maybe(tx.fee_amount.map(|fee| amount_with_size(&fee, P2_SIZE)))
156-
.width(Length::Shrink),
156+
.width(Length::Fixed(140.0)),
157157
)
158158
.align_items(Alignment::Center)
159159
.spacing(20),

gui/ui/src/component/badge.rs

+68-45
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use iced::{widget::tooltip, Length};
22

3+
use crate::util::Collection;
34
use crate::{component::text, icon, image, theme, widget::*};
45

56
pub struct Badge {
@@ -75,66 +76,88 @@ pub fn coin<T>() -> Container<'static, T> {
7576
}
7677

7778
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,
8783
)
8884
}
8985

9086
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),
10099
)
101100
}
102101

103102
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,
113107
)
114108
}
115109

116110
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),
126123
)
127124
}
128125

129126
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),
139139
)
140140
}
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

Comments
 (0)