Skip to content

Commit 76f617e

Browse files
committed
feat(dashboard): adding wipe to tabs
1 parent 01c5ae8 commit 76f617e

File tree

7 files changed

+207
-128
lines changed

7 files changed

+207
-128
lines changed

src/fx.rs

+35-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use bon::Builder;
1+
use bon::{builder, Builder};
22
use eyre::Result;
33
use ndarray::{s, ArrayViewMut2};
44
use ratatui::{buffer::Buffer, layout::Rect, Frame};
@@ -46,29 +46,44 @@ impl Widget for Animated {
4646
}
4747
}
4848

49-
/// Wipes content in from right to left, uses `previous` as the source and then
49+
#[derive(Clone, Default)]
50+
pub enum Start {
51+
Left,
52+
#[default]
53+
Right,
54+
}
55+
56+
/// Wipes content in from the start edge, uses `previous` as the source and then
5057
/// the current buffer as the destination.
5158
#[derive(Builder, Clone)]
52-
pub struct Slider {
59+
pub struct Wipe {
5360
#[builder(into)]
5461
timer: EffectTimer,
62+
#[builder(default)]
63+
start: Start,
5564
previous: Buffer,
5665
#[builder(default)]
5766
done: bool,
5867
}
5968

60-
pub fn right_to_left<T: Into<EffectTimer>>(timer: T, previous: Buffer) -> Effect {
69+
#[builder]
70+
pub fn horizontal_wipe<T: Into<EffectTimer>>(
71+
timer: T,
72+
buffer: Buffer,
73+
#[builder(default)] start: Start,
74+
) -> Effect {
6175
Effect::new(
62-
Slider::builder()
76+
Wipe::builder()
6377
.timer(timer.into())
64-
.previous(previous)
78+
.previous(buffer)
79+
.start(start)
6580
.build(),
6681
)
6782
}
6883

6984
// This assumes that the area from the original buffer to the new one doesn't
7085
// change. If it is unable to create a slice correctly, it'll just give up.
71-
impl Shader for Slider {
86+
impl Shader for Wipe {
7287
fn name(&self) -> &'static str {
7388
"slider"
7489
}
@@ -87,36 +102,40 @@ impl Shader for Slider {
87102
let y = area.y as usize;
88103
let width = area.width as usize;
89104
let height = area.height as usize;
105+
let buffer_width = self.previous.area.width as usize;
106+
let buffer_height = self.previous.area.height as usize;
90107

91108
let window = ((width as f32 * alpha).round() as usize).clamp(0, width);
92109

93110
if window == width {
94111
self.done = true;
95112
}
96113

97-
let Ok(previous) = ArrayViewMut2::from_shape(
98-
(area.height as usize, area.width as usize),
99-
&mut self.previous.content,
100-
) else {
114+
let Ok(previous) =
115+
ArrayViewMut2::from_shape((buffer_height, buffer_width), &mut self.previous.content)
116+
else {
101117
tracing::debug!(area = ?area, "unable to create view from previous buffer");
102118

103119
self.done = true;
104120
return overflow;
105121
};
106122

107-
let Ok(mut next) = ArrayViewMut2::from_shape(
108-
(area.height as usize, area.width as usize),
109-
&mut buf.content,
110-
) else {
123+
let Ok(mut next) =
124+
ArrayViewMut2::from_shape((buffer_height, buffer_width), &mut buf.content)
125+
else {
111126
tracing::debug!(area = ?area, "unable to create view from next buffer");
112127

113128
self.done = true;
114129
return overflow;
115130
};
116131

117-
let slice = s![y..y + height, x..x + width - window];
132+
let slice = match self.start {
133+
Start::Left => s![y..height, x + window..x + width],
134+
Start::Right => s![y..y + height, x..x + width - window],
135+
};
118136

119137
let previous_section = previous.slice(slice);
138+
120139
next.slice_mut(slice).assign(&previous_section);
121140

122141
overflow

src/widget/log.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,12 @@ impl Log {
8585
// TODO: This should be a macro. Ideally, it'd be a trait with a default impl
8686
// but I don't think it is possible to do generically.
8787
pub fn tab(name: String, client: kube::Client, pod: Arc<Pod>) -> Tab {
88-
Tab::new(
89-
name,
90-
Box::new(move || Box::new(Log::new(client.clone(), pod.clone()))),
91-
)
88+
Tab::builder()
89+
.name(name)
90+
.constructor(Box::new(move || {
91+
Log::new(client.clone(), pod.clone()).boxed()
92+
}))
93+
.build()
9294
}
9395

9496
fn update(&mut self) -> u16 {

src/widget/pod.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,13 @@ impl Detail {
107107
fn new(client: &kube::Client, pod: Arc<Pod>) -> Self {
108108
WIDGET_VIEWS.pod.detail.inc();
109109

110-
let view = TabbedView::new(vec![
111-
Yaml::tab("Overview".to_string(), pod.clone()),
112-
Log::tab("Logs".to_string(), client.clone(), pod.clone()),
113-
Shell::tab("Shell".to_string(), client.clone(), pod.clone()).no_margin(),
114-
])
115-
.unwrap();
110+
let view = TabbedView::builder()
111+
.tabs(vec![
112+
Yaml::tab("Overview".to_string(), pod.clone()),
113+
Log::tab("Logs".to_string(), client.clone(), pod.clone()),
114+
Shell::tab("Shell".to_string(), client.clone(), pod.clone()),
115+
])
116+
.build();
116117

117118
Self { pod, view }
118119
}

src/widget/pod/shell.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,16 @@ impl Shell {
7171
}
7272

7373
pub fn tab(name: String, client: kube::Client, pod: Arc<Pod>) -> Tab {
74-
Tab::new(
75-
name,
76-
Box::new(move || {
77-
Box::new(
78-
Self::builder()
79-
.client(client.clone())
80-
.pod(pod.clone())
81-
.build(),
82-
)
83-
}),
84-
)
74+
Tab::builder()
75+
.name(name)
76+
.constructor(Box::new(move || {
77+
Self::builder()
78+
.client(client.clone())
79+
.pod(pod.clone())
80+
.build()
81+
.boxed()
82+
}))
83+
.build()
8584
}
8685
}
8786

src/widget/table.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use super::{
2222
};
2323
use crate::{
2424
events::{Broadcast, Event, Keypress},
25-
fx::{right_to_left, Animated},
25+
fx::Animated,
2626
};
2727

2828
lazy_static! {
@@ -238,14 +238,11 @@ impl Filtered {
238238
let widget = (self.constructor)(idx, self.filter.borrow().clone())?;
239239

240240
let detail = Animated::builder()
241-
.maybe_effect(frame.map(|buffer| {
242-
fx::parallel(&[
243-
fx::coalesce(EffectTimer::from_ms(500, Interpolation::SineInOut)),
244-
right_to_left(
245-
EffectTimer::from_ms(500, Interpolation::SineInOut),
246-
buffer.clone(),
247-
),
248-
])
241+
.maybe_effect(frame.map(|_| {
242+
fx::parallel(&[fx::coalesce(EffectTimer::from_ms(
243+
500,
244+
Interpolation::SineInOut,
245+
))])
249246
}))
250247
.widget(widget)
251248
.build();

0 commit comments

Comments
 (0)