mirror of
https://seed.radicle.dev/rad:z39mP9rQAaGmERfUMPULfPUi473tY.git
synced 2026-11-21 02:20:48 +08:00
lib: Unify panes and container widget
This commit is contained in:
+2
-16
@@ -479,7 +479,7 @@ impl<M> Ui<M>
|
||||
where
|
||||
M: Clone,
|
||||
{
|
||||
pub fn panes<R>(
|
||||
pub fn container<R>(
|
||||
&mut self,
|
||||
layout: impl Into<Layout>,
|
||||
focus: &mut Option<usize>,
|
||||
@@ -497,21 +497,7 @@ where
|
||||
..self.child_ui(area, layout)
|
||||
};
|
||||
|
||||
widget::Panes::new(len, focus).show(&mut child_ui, add_contents)
|
||||
}
|
||||
|
||||
pub fn container<R>(
|
||||
&mut self,
|
||||
layout: impl Into<Layout>,
|
||||
focus: usize,
|
||||
add_contents: impl FnOnce(&mut Ui<M>) -> R,
|
||||
) -> InnerResponse<R> {
|
||||
let (area, area_focus) = self.next_area().unwrap_or_default();
|
||||
|
||||
let mut child_ui = self.child_ui(area, layout);
|
||||
child_ui.has_focus = area_focus;
|
||||
|
||||
widget::Container::new(focus).show(&mut child_ui, add_contents)
|
||||
widget::Container::new(len, focus).show(&mut child_ui, add_contents)
|
||||
}
|
||||
|
||||
pub fn popup<R>(
|
||||
|
||||
+5
-44
@@ -62,12 +62,12 @@ impl Window {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct PanesState {
|
||||
pub struct ContainerState {
|
||||
len: usize,
|
||||
focus: Option<usize>,
|
||||
}
|
||||
|
||||
impl PanesState {
|
||||
impl ContainerState {
|
||||
pub fn new(len: usize, focus: Option<usize>) -> Self {
|
||||
Self { len, focus }
|
||||
}
|
||||
@@ -95,12 +95,12 @@ impl PanesState {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Panes<'a> {
|
||||
pub struct Container<'a> {
|
||||
focus: &'a mut Option<usize>,
|
||||
len: usize,
|
||||
}
|
||||
|
||||
impl<'a> Panes<'a> {
|
||||
impl<'a> Container<'a> {
|
||||
pub fn new(len: usize, focus: &'a mut Option<usize>) -> Self {
|
||||
Self { len, focus }
|
||||
}
|
||||
@@ -126,7 +126,7 @@ impl<'a> Panes<'a> {
|
||||
{
|
||||
let mut response = Response::default();
|
||||
|
||||
let mut state = PanesState {
|
||||
let mut state = ContainerState {
|
||||
focus: *self.focus,
|
||||
len: self.len,
|
||||
};
|
||||
@@ -176,45 +176,6 @@ impl CompositeState {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Container {
|
||||
focus: usize,
|
||||
}
|
||||
|
||||
impl Container {
|
||||
pub fn new(focus: usize) -> Self {
|
||||
Self { focus }
|
||||
}
|
||||
|
||||
pub fn show<M, R>(
|
||||
self,
|
||||
ui: &mut Ui<M>,
|
||||
add_contents: impl FnOnce(&mut Ui<M>) -> R,
|
||||
) -> InnerResponse<R>
|
||||
where
|
||||
M: Clone,
|
||||
{
|
||||
self.show_dyn(ui, Box::new(add_contents))
|
||||
}
|
||||
|
||||
pub fn show_dyn<M, R>(
|
||||
self,
|
||||
ui: &mut Ui<M>,
|
||||
add_contents: Box<AddContentFn<M, R>>,
|
||||
) -> InnerResponse<R>
|
||||
where
|
||||
M: Clone,
|
||||
{
|
||||
let mut ui = Ui {
|
||||
focus_area: Some(self.focus),
|
||||
..ui.clone()
|
||||
};
|
||||
|
||||
let inner = add_contents(&mut ui);
|
||||
|
||||
InnerResponse::new(inner, Response::default())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Popup {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user