chrome: Refactor state fields to remove is_ prefix. (#627)
This commit is contained in:
parent
bf300a2880
commit
0ebedbe79f
13 changed files with 102 additions and 106 deletions
|
|
@ -147,7 +147,7 @@ struct CompanyListDelegate {
|
|||
confirmed_index: Option<usize>,
|
||||
query: String,
|
||||
loading: bool,
|
||||
is_eof: bool,
|
||||
eof: bool,
|
||||
}
|
||||
|
||||
impl ListDelegate for CompanyListDelegate {
|
||||
|
|
@ -208,7 +208,7 @@ impl ListDelegate for CompanyListDelegate {
|
|||
}
|
||||
|
||||
fn can_load_more(&self, _: &App) -> bool {
|
||||
return !self.loading && !self.is_eof;
|
||||
return !self.loading && !self.eof;
|
||||
}
|
||||
|
||||
fn load_more_threshold(&self) -> usize {
|
||||
|
|
@ -226,7 +226,7 @@ impl ListDelegate for CompanyListDelegate {
|
|||
.companies
|
||||
.extend((0..200).map(|_| random_company()));
|
||||
_ = view.delegate_mut().perform_search(&query, window, cx);
|
||||
view.delegate_mut().is_eof = view.delegate().companies.len() >= 6000;
|
||||
view.delegate_mut().eof = view.delegate().companies.len() >= 6000;
|
||||
});
|
||||
})
|
||||
.detach();
|
||||
|
|
@ -281,7 +281,7 @@ impl ListStory {
|
|||
confirmed_index: None,
|
||||
query: "".to_string(),
|
||||
loading: false,
|
||||
is_eof: false,
|
||||
eof: false,
|
||||
};
|
||||
|
||||
let company_list = cx.new(|cx| List::new(delegate, window, cx));
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ impl_internal_actions!(sidebar_story, [SelectCompany]);
|
|||
pub struct SidebarStory {
|
||||
active_item: Item,
|
||||
active_subitem: Option<SubItem>,
|
||||
is_collapsed: bool,
|
||||
collapsed: bool,
|
||||
side: Side,
|
||||
focus_handle: gpui::FocusHandle,
|
||||
}
|
||||
|
|
@ -39,7 +39,7 @@ impl SidebarStory {
|
|||
Self {
|
||||
active_item: Item::Playground,
|
||||
active_subitem: None,
|
||||
is_collapsed: false,
|
||||
collapsed: false,
|
||||
side: Side::Left,
|
||||
focus_handle: cx.focus_handle(),
|
||||
}
|
||||
|
|
@ -231,10 +231,10 @@ impl Render for SidebarStory {
|
|||
.when(self.side.is_right(), |this| this.flex_row_reverse())
|
||||
.child(
|
||||
sidebar
|
||||
.collapsed(self.is_collapsed)
|
||||
.collapsed(self.collapsed)
|
||||
.header(
|
||||
SidebarHeader::new()
|
||||
.collapsed(self.is_collapsed)
|
||||
.collapsed(self.collapsed)
|
||||
.w_full()
|
||||
.child(
|
||||
div()
|
||||
|
|
@ -246,17 +246,17 @@ impl Render for SidebarStory {
|
|||
.text_color(white())
|
||||
.size_8()
|
||||
.flex_shrink_0()
|
||||
.when(!self.is_collapsed, |this| {
|
||||
.when(!self.collapsed, |this| {
|
||||
this.child(Icon::new(IconName::GalleryVerticalEnd).size_4())
|
||||
})
|
||||
.when(self.is_collapsed, |this| {
|
||||
.when(self.collapsed, |this| {
|
||||
this.size_4()
|
||||
.bg(cx.theme().transparent)
|
||||
.text_color(cx.theme().foreground)
|
||||
.child(Icon::new(IconName::GalleryVerticalEnd).size_5())
|
||||
}),
|
||||
)
|
||||
.when(!self.is_collapsed, |this| {
|
||||
.when(!self.collapsed, |this| {
|
||||
this.child(
|
||||
v_flex()
|
||||
.gap_0()
|
||||
|
|
@ -269,7 +269,7 @@ impl Render for SidebarStory {
|
|||
.child(div().child("Enterprise").text_xs()),
|
||||
)
|
||||
})
|
||||
.when(!self.is_collapsed, |this| {
|
||||
.when(!self.collapsed, |this| {
|
||||
this.child(
|
||||
Icon::new(IconName::ChevronsUpDown).size_4().flex_shrink_0(),
|
||||
)
|
||||
|
|
@ -291,15 +291,15 @@ impl Render for SidebarStory {
|
|||
)
|
||||
.footer(
|
||||
SidebarFooter::new()
|
||||
.collapsed(self.is_collapsed)
|
||||
.collapsed(self.collapsed)
|
||||
.justify_between()
|
||||
.child(
|
||||
h_flex()
|
||||
.gap_2()
|
||||
.child(IconName::CircleUser)
|
||||
.when(!self.is_collapsed, |this| this.child("Jason Lee")),
|
||||
.when(!self.collapsed, |this| this.child("Jason Lee")),
|
||||
)
|
||||
.when(!self.is_collapsed, |this| {
|
||||
.when(!self.collapsed, |this| {
|
||||
this.child(
|
||||
Icon::new(IconName::ChevronsUpDown).size_4().flex_shrink_0(),
|
||||
)
|
||||
|
|
@ -362,9 +362,9 @@ impl Render for SidebarStory {
|
|||
.child(
|
||||
SidebarToggleButton::left()
|
||||
.side(self.side)
|
||||
.collapsed(self.is_collapsed)
|
||||
.collapsed(self.collapsed)
|
||||
.on_click(cx.listener(|this, _, _, cx| {
|
||||
this.is_collapsed = !this.is_collapsed;
|
||||
this.collapsed = !this.collapsed;
|
||||
cx.notify();
|
||||
})),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ struct StockTableDelegate {
|
|||
loading: bool,
|
||||
full_loading: bool,
|
||||
fixed_cols: bool,
|
||||
is_eof: bool,
|
||||
eof: bool,
|
||||
visible_rows: Range<usize>,
|
||||
visible_cols: Range<usize>,
|
||||
}
|
||||
|
|
@ -247,7 +247,7 @@ impl StockTableDelegate {
|
|||
fixed_cols: false,
|
||||
loading: false,
|
||||
full_loading: false,
|
||||
is_eof: false,
|
||||
eof: false,
|
||||
visible_cols: Range::default(),
|
||||
visible_rows: Range::default(),
|
||||
}
|
||||
|
|
@ -255,7 +255,7 @@ impl StockTableDelegate {
|
|||
|
||||
fn update_stocks(&mut self, size: usize) {
|
||||
self.stocks = random_stocks(size);
|
||||
self.is_eof = size <= 50;
|
||||
self.eof = size <= 50;
|
||||
self.loading = false;
|
||||
self.full_loading = false;
|
||||
}
|
||||
|
|
@ -514,7 +514,7 @@ impl TableDelegate for StockTableDelegate {
|
|||
}
|
||||
|
||||
fn can_load_more(&self, _: &App) -> bool {
|
||||
return !self.loading && !self.is_eof;
|
||||
return !self.loading && !self.eof;
|
||||
}
|
||||
|
||||
fn load_more_threshold(&self) -> usize {
|
||||
|
|
@ -532,7 +532,7 @@ impl TableDelegate for StockTableDelegate {
|
|||
let _ = view.update(cx, |view, _| {
|
||||
view.delegate_mut().stocks.extend(random_stocks(200));
|
||||
view.delegate_mut().loading = false;
|
||||
view.delegate_mut().is_eof = view.delegate().stocks.len() >= 6000;
|
||||
view.delegate_mut().eof = view.delegate().stocks.len() >= 6000;
|
||||
});
|
||||
})
|
||||
})
|
||||
|
|
@ -927,7 +927,7 @@ impl Render for TableStory {
|
|||
.child(format!("Total Rows: {}", rows_count))
|
||||
.child(format!("Visible Rows: {:?}", delegate.visible_rows))
|
||||
.child(format!("Visible Cols: {:?}", delegate.visible_cols))
|
||||
.when(delegate.is_eof, |this| this.child("All data loaded.")),
|
||||
.when(delegate.eof, |this| this.child("All data loaded.")),
|
||||
),
|
||||
)
|
||||
.child(self.table.clone())
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ pub struct Dock {
|
|||
|
||||
// Runtime state
|
||||
/// Whether the Dock is resizing
|
||||
is_resizing: bool,
|
||||
resizing: bool,
|
||||
}
|
||||
|
||||
impl Dock {
|
||||
|
|
@ -105,7 +105,7 @@ impl Dock {
|
|||
open: true,
|
||||
collapsible: true,
|
||||
size: px(200.0),
|
||||
is_resizing: false,
|
||||
resizing: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -178,7 +178,7 @@ impl Dock {
|
|||
open,
|
||||
size,
|
||||
collapsible: true,
|
||||
is_resizing: false,
|
||||
resizing: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -284,13 +284,13 @@ impl Dock {
|
|||
.on_drag(ResizePanel {}, move |info, _, _, cx| {
|
||||
cx.stop_propagation();
|
||||
view.update(cx, |view, _| {
|
||||
view.is_resizing = true;
|
||||
view.resizing = true;
|
||||
});
|
||||
cx.new(|_| info.deref().clone())
|
||||
})
|
||||
}
|
||||
fn resize(&mut self, mouse_position: Point<Pixels>, _: &mut Window, cx: &mut Context<Self>) {
|
||||
if !self.is_resizing {
|
||||
if !self.resizing {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -349,7 +349,7 @@ impl Dock {
|
|||
}
|
||||
|
||||
fn done_resizing(&mut self, _window: &mut Window, _cx: &mut Context<Self>) {
|
||||
self.is_resizing = false;
|
||||
self.resizing = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -438,9 +438,9 @@ impl Element for DockElement {
|
|||
) {
|
||||
window.on_mouse_event({
|
||||
let view = self.view.clone();
|
||||
let is_resizing = view.read(cx).is_resizing;
|
||||
let resizing = view.read(cx).resizing;
|
||||
move |e: &MouseMoveEvent, phase, window, cx| {
|
||||
if !is_resizing {
|
||||
if !resizing {
|
||||
return;
|
||||
}
|
||||
if !phase.bubble() {
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ pub struct DockArea {
|
|||
zoom_view: Option<AnyView>,
|
||||
|
||||
/// Lock panels layout, but allow to resize.
|
||||
is_locked: bool,
|
||||
locked: bool,
|
||||
|
||||
/// The panel style, default is [`PanelStyle::Default`](PanelStyle::Default).
|
||||
pub(crate) panel_style: PanelStyle,
|
||||
|
|
@ -408,7 +408,7 @@ impl DockArea {
|
|||
left_dock: None,
|
||||
right_dock: None,
|
||||
bottom_dock: None,
|
||||
is_locked: false,
|
||||
locked: false,
|
||||
panel_style: PanelStyle::Default,
|
||||
_subscriptions: vec![],
|
||||
};
|
||||
|
|
@ -514,12 +514,12 @@ impl DockArea {
|
|||
|
||||
/// Set locked state of the dock area, if locked, the dock area cannot be split or move, but allows to resize panels.
|
||||
pub fn set_locked(&mut self, locked: bool, _window: &mut Window, _cx: &mut App) {
|
||||
self.is_locked = locked;
|
||||
self.locked = locked;
|
||||
}
|
||||
|
||||
/// Determine if the dock area is locked.
|
||||
pub fn is_locked(&self) -> bool {
|
||||
self.is_locked
|
||||
self.locked
|
||||
}
|
||||
|
||||
/// Determine if the dock area has a dock at the given placement.
|
||||
|
|
|
|||
|
|
@ -75,8 +75,8 @@ pub struct TabPanel {
|
|||
pub(crate) closable: bool,
|
||||
|
||||
tab_bar_scroll_handle: ScrollHandle,
|
||||
is_zoomed: bool,
|
||||
is_collapsed: bool,
|
||||
zoomed: bool,
|
||||
collapsed: bool,
|
||||
/// When drag move, will get the placement of the panel to be split
|
||||
will_split_placement: Option<Placement>,
|
||||
}
|
||||
|
|
@ -153,8 +153,8 @@ impl TabPanel {
|
|||
active_ix: 0,
|
||||
tab_bar_scroll_handle: ScrollHandle::new(),
|
||||
will_split_placement: None,
|
||||
is_zoomed: false,
|
||||
is_collapsed: false,
|
||||
zoomed: false,
|
||||
collapsed: false,
|
||||
closable: true,
|
||||
}
|
||||
}
|
||||
|
|
@ -340,7 +340,7 @@ impl TabPanel {
|
|||
_: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.is_collapsed = collapsed;
|
||||
self.collapsed = collapsed;
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
|
|
@ -353,7 +353,7 @@ impl TabPanel {
|
|||
return true;
|
||||
}
|
||||
|
||||
if self.is_zoomed {
|
||||
if self.zoomed {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -404,7 +404,7 @@ impl TabPanel {
|
|||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> impl IntoElement {
|
||||
let is_zoomed = self.is_zoomed;
|
||||
let zoomed = self.zoomed;
|
||||
let view = cx.entity().clone();
|
||||
let zoomable_toolbar_visible = state.zoomable.map_or(false, |v| v.toolbar_visible());
|
||||
|
||||
|
|
@ -417,7 +417,7 @@ impl TabPanel {
|
|||
this.children(buttons.into_iter().map(|btn| btn.xsmall().ghost()))
|
||||
})
|
||||
.map(|this| {
|
||||
let value = if is_zoomed {
|
||||
let value = if zoomed {
|
||||
Some(("zoom-out", IconName::Minimize, t!("Dock.Zoom Out")))
|
||||
} else if zoomable_toolbar_visible {
|
||||
Some(("zoom-in", IconName::Maximize, t!("Dock.Zoom In")))
|
||||
|
|
@ -453,7 +453,7 @@ impl TabPanel {
|
|||
view.read(cx)
|
||||
.popup_menu(this, window, cx)
|
||||
.when(zoomable, |this| {
|
||||
let name = if is_zoomed {
|
||||
let name = if zoomed {
|
||||
t!("Dock.Zoom Out")
|
||||
} else {
|
||||
t!("Dock.Zoom In")
|
||||
|
|
@ -476,7 +476,7 @@ impl TabPanel {
|
|||
_: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Option<impl IntoElement> {
|
||||
if self.is_zoomed {
|
||||
if self.zoomed {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
|
@ -662,14 +662,14 @@ impl TabPanel {
|
|||
)
|
||||
.children(self.panels.iter().enumerate().filter_map(|(ix, panel)| {
|
||||
let mut active = state.active_panel.as_ref() == Some(panel);
|
||||
let disabled = self.is_collapsed;
|
||||
let disabled = self.collapsed;
|
||||
|
||||
if !panel.visible(cx) {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Always not show active tab style, if the panel is collapsed
|
||||
if self.is_collapsed {
|
||||
if self.collapsed {
|
||||
active = false;
|
||||
}
|
||||
|
||||
|
|
@ -758,7 +758,7 @@ impl TabPanel {
|
|||
_: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) -> impl IntoElement {
|
||||
if self.is_collapsed {
|
||||
if self.collapsed {
|
||||
return Empty {}.into_any_element();
|
||||
}
|
||||
|
||||
|
|
@ -1026,19 +1026,19 @@ impl TabPanel {
|
|||
return;
|
||||
}
|
||||
|
||||
if !self.is_zoomed {
|
||||
if !self.zoomed {
|
||||
cx.emit(PanelEvent::ZoomIn)
|
||||
} else {
|
||||
cx.emit(PanelEvent::ZoomOut)
|
||||
}
|
||||
self.is_zoomed = !self.is_zoomed;
|
||||
self.zoomed = !self.zoomed;
|
||||
|
||||
cx.spawn_in(window, |view, mut cx| {
|
||||
let is_zoomed = self.is_zoomed;
|
||||
let zoomed = self.zoomed;
|
||||
async move {
|
||||
_ = cx.update(|window, cx| {
|
||||
_ = view.update(cx, |view, cx| {
|
||||
view.set_zoomed(is_zoomed, window, cx);
|
||||
view.set_zoomed(zoomed, window, cx);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ pub struct TextInput {
|
|||
/// The text bounds
|
||||
pub(super) last_bounds: Option<Bounds<Pixels>>,
|
||||
pub(super) last_selected_range: Option<Range<usize>>,
|
||||
pub(super) is_selecting: bool,
|
||||
pub(super) selecting: bool,
|
||||
pub(super) disabled: bool,
|
||||
pub(super) masked: bool,
|
||||
pub(super) appearance: bool,
|
||||
|
|
@ -272,7 +272,7 @@ impl TextInput {
|
|||
selection_reversed: false,
|
||||
marked_range: None,
|
||||
input_bounds: Bounds::default(),
|
||||
is_selecting: false,
|
||||
selecting: false,
|
||||
disabled: false,
|
||||
masked: false,
|
||||
appearance: true,
|
||||
|
|
@ -936,7 +936,7 @@ impl TextInput {
|
|||
window: &mut Window,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
self.is_selecting = true;
|
||||
self.selecting = true;
|
||||
let offset = self.index_for_mouse_position(event.position, window, cx);
|
||||
// Double click to select word
|
||||
if event.button == MouseButton::Left && event.click_count == 2 {
|
||||
|
|
@ -952,7 +952,7 @@ impl TextInput {
|
|||
}
|
||||
|
||||
fn on_mouse_up(&mut self, _: &MouseUpEvent, _window: &mut Window, _cx: &mut Context<Self>) {
|
||||
self.is_selecting = false;
|
||||
self.selecting = false;
|
||||
self.selected_word_range = None;
|
||||
}
|
||||
|
||||
|
|
@ -1364,7 +1364,7 @@ impl TextInput {
|
|||
return;
|
||||
}
|
||||
|
||||
if !self.is_selecting {
|
||||
if !self.selecting {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -139,12 +139,12 @@ where
|
|||
self
|
||||
}
|
||||
|
||||
fn render_trigger(&mut self, is_open: bool, window: &mut Window, cx: &mut App) -> AnyElement {
|
||||
fn render_trigger(&mut self, open: bool, window: &mut Window, cx: &mut App) -> AnyElement {
|
||||
let Some(trigger) = self.trigger.take() else {
|
||||
return div().into_any_element();
|
||||
};
|
||||
|
||||
(trigger)(is_open, window, cx)
|
||||
(trigger)(open, window, cx)
|
||||
}
|
||||
|
||||
fn resolved_corner(&self, bounds: Bounds<Pixels>) -> Point<Pixels> {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ pub struct SidebarFooter {
|
|||
id: ElementId,
|
||||
base: Div,
|
||||
selected: bool,
|
||||
is_collapsed: bool,
|
||||
collapsed: bool,
|
||||
}
|
||||
|
||||
impl SidebarFooter {
|
||||
|
|
@ -19,7 +19,7 @@ impl SidebarFooter {
|
|||
id: SharedString::from("sidebar-footer").into(),
|
||||
base: h_flex().gap_2().w_full(),
|
||||
selected: false,
|
||||
is_collapsed: false,
|
||||
collapsed: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -35,11 +35,11 @@ impl Selectable for SidebarFooter {
|
|||
}
|
||||
impl Collapsible for SidebarFooter {
|
||||
fn is_collapsed(&self) -> bool {
|
||||
self.is_collapsed
|
||||
self.collapsed
|
||||
}
|
||||
|
||||
fn collapsed(mut self, collapsed: bool) -> Self {
|
||||
self.is_collapsed = collapsed;
|
||||
self.collapsed = collapsed;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use gpui::{
|
|||
pub struct SidebarGroup<E: Collapsible + IntoElement + 'static> {
|
||||
base: Div,
|
||||
label: SharedString,
|
||||
is_collapsed: bool,
|
||||
collapsed: bool,
|
||||
children: Vec<E>,
|
||||
}
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ impl<E: Collapsible + IntoElement> SidebarGroup<E> {
|
|||
Self {
|
||||
base: div().gap_2().flex_col(),
|
||||
label: label.into(),
|
||||
is_collapsed: false,
|
||||
collapsed: false,
|
||||
children: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
|
@ -35,11 +35,11 @@ impl<E: Collapsible + IntoElement> SidebarGroup<E> {
|
|||
}
|
||||
impl<E: Collapsible + IntoElement> Collapsible for SidebarGroup<E> {
|
||||
fn is_collapsed(&self) -> bool {
|
||||
self.is_collapsed
|
||||
self.collapsed
|
||||
}
|
||||
|
||||
fn collapsed(mut self, collapsed: bool) -> Self {
|
||||
self.is_collapsed = collapsed;
|
||||
self.collapsed = collapsed;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
@ -48,7 +48,7 @@ impl<E: Collapsible + IntoElement> RenderOnce for SidebarGroup<E> {
|
|||
v_flex()
|
||||
.relative()
|
||||
.p_2()
|
||||
.when(!self.is_collapsed, |this| {
|
||||
.when(!self.collapsed, |this| {
|
||||
this.child(
|
||||
div()
|
||||
.flex_shrink_0()
|
||||
|
|
@ -64,7 +64,7 @@ impl<E: Collapsible + IntoElement> RenderOnce for SidebarGroup<E> {
|
|||
self.base.children(
|
||||
self.children
|
||||
.into_iter()
|
||||
.map(|child| child.collapsed(self.is_collapsed)),
|
||||
.map(|child| child.collapsed(self.collapsed)),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ pub struct SidebarHeader {
|
|||
id: ElementId,
|
||||
base: Div,
|
||||
selected: bool,
|
||||
is_collapsed: bool,
|
||||
collapsed: bool,
|
||||
}
|
||||
|
||||
impl SidebarHeader {
|
||||
|
|
@ -19,7 +19,7 @@ impl SidebarHeader {
|
|||
id: SharedString::from("sidebar-header").into(),
|
||||
base: h_flex().gap_2().w_full(),
|
||||
selected: false,
|
||||
is_collapsed: false,
|
||||
collapsed: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -35,11 +35,11 @@ impl Selectable for SidebarHeader {
|
|||
}
|
||||
impl Collapsible for SidebarHeader {
|
||||
fn is_collapsed(&self) -> bool {
|
||||
self.is_collapsed
|
||||
self.collapsed
|
||||
}
|
||||
|
||||
fn collapsed(mut self, collapsed: bool) -> Self {
|
||||
self.is_collapsed = collapsed;
|
||||
self.collapsed = collapsed;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use std::rc::Rc;
|
|||
|
||||
#[derive(IntoElement)]
|
||||
pub struct SidebarMenu {
|
||||
is_collapsed: bool,
|
||||
collapsed: bool,
|
||||
items: Vec<SidebarMenuItem>,
|
||||
}
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ impl SidebarMenu {
|
|||
pub fn new() -> Self {
|
||||
Self {
|
||||
items: Vec::new(),
|
||||
is_collapsed: false,
|
||||
collapsed: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ impl SidebarMenu {
|
|||
label: label.into(),
|
||||
handler: Rc::new(handler),
|
||||
active,
|
||||
is_collapsed: self.is_collapsed,
|
||||
collapsed: self.collapsed,
|
||||
});
|
||||
self
|
||||
}
|
||||
|
|
@ -51,8 +51,8 @@ impl SidebarMenu {
|
|||
icon,
|
||||
label: label.into(),
|
||||
items: menu.items,
|
||||
is_open: open,
|
||||
is_collapsed: self.is_collapsed,
|
||||
open,
|
||||
collapsed: self.collapsed,
|
||||
handler: Rc::new(handler),
|
||||
});
|
||||
self
|
||||
|
|
@ -60,11 +60,11 @@ impl SidebarMenu {
|
|||
}
|
||||
impl Collapsible for SidebarMenu {
|
||||
fn is_collapsed(&self) -> bool {
|
||||
self.is_collapsed
|
||||
self.collapsed
|
||||
}
|
||||
|
||||
fn collapsed(mut self, collapsed: bool) -> Self {
|
||||
self.is_collapsed = collapsed;
|
||||
self.collapsed = collapsed;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
@ -74,10 +74,8 @@ impl RenderOnce for SidebarMenu {
|
|||
.gap_2()
|
||||
.children(self.items.into_iter().map(|mut item| {
|
||||
match &mut item {
|
||||
SidebarMenuItem::Item { is_collapsed, .. } => *is_collapsed = self.is_collapsed,
|
||||
SidebarMenuItem::Submenu { is_collapsed, .. } => {
|
||||
*is_collapsed = self.is_collapsed
|
||||
}
|
||||
SidebarMenuItem::Item { collapsed, .. } => *collapsed = self.collapsed,
|
||||
SidebarMenuItem::Submenu { collapsed, .. } => *collapsed = self.collapsed,
|
||||
}
|
||||
item
|
||||
}))
|
||||
|
|
@ -92,15 +90,15 @@ enum SidebarMenuItem {
|
|||
label: SharedString,
|
||||
handler: Rc<dyn Fn(&ClickEvent, &mut Window, &mut App)>,
|
||||
active: bool,
|
||||
is_collapsed: bool,
|
||||
collapsed: bool,
|
||||
},
|
||||
Submenu {
|
||||
icon: Option<Icon>,
|
||||
label: SharedString,
|
||||
handler: Rc<dyn Fn(&ClickEvent, &mut Window, &mut App)>,
|
||||
items: Vec<SidebarMenuItem>,
|
||||
is_open: bool,
|
||||
is_collapsed: bool,
|
||||
open: bool,
|
||||
collapsed: bool,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -133,16 +131,16 @@ impl SidebarMenuItem {
|
|||
fn is_open(&self) -> bool {
|
||||
match self {
|
||||
SidebarMenuItem::Item { .. } => false,
|
||||
SidebarMenuItem::Submenu { is_open, items, .. } => {
|
||||
*is_open || items.iter().any(|item| item.is_active())
|
||||
SidebarMenuItem::Submenu { open, items, .. } => {
|
||||
*open || items.iter().any(|item| item.is_active())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn is_collapsed(&self) -> bool {
|
||||
match self {
|
||||
SidebarMenuItem::Item { is_collapsed, .. } => *is_collapsed,
|
||||
SidebarMenuItem::Submenu { is_collapsed, .. } => *is_collapsed,
|
||||
SidebarMenuItem::Item { collapsed, .. } => *collapsed,
|
||||
SidebarMenuItem::Submenu { collapsed, .. } => *collapsed,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -212,11 +210,9 @@ impl RenderOnce for SidebarMenuItem {
|
|||
.when(is_open, |this| {
|
||||
this.map(|this| match self {
|
||||
SidebarMenuItem::Submenu {
|
||||
items,
|
||||
is_collapsed,
|
||||
..
|
||||
items, collapsed, ..
|
||||
} => {
|
||||
if is_collapsed {
|
||||
if collapsed {
|
||||
this
|
||||
} else {
|
||||
this.child(
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ pub struct Sidebar<E: Collapsible + IntoElement + 'static> {
|
|||
side: Side,
|
||||
collapsible: bool,
|
||||
width: Pixels,
|
||||
is_collapsed: bool,
|
||||
collapsed: bool,
|
||||
}
|
||||
|
||||
impl<E: Collapsible + IntoElement> Sidebar<E> {
|
||||
|
|
@ -50,7 +50,7 @@ impl<E: Collapsible + IntoElement> Sidebar<E> {
|
|||
side,
|
||||
collapsible: true,
|
||||
width: DEFAULT_WIDTH,
|
||||
is_collapsed: false,
|
||||
collapsed: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ impl<E: Collapsible + IntoElement> Sidebar<E> {
|
|||
|
||||
/// Set the sidebar to be collapsed
|
||||
pub fn collapsed(mut self, collapsed: bool) -> Self {
|
||||
self.is_collapsed = collapsed;
|
||||
self.collapsed = collapsed;
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -109,7 +109,7 @@ impl<E: Collapsible + IntoElement> Sidebar<E> {
|
|||
#[derive(IntoElement)]
|
||||
pub struct SidebarToggleButton {
|
||||
btn: Button,
|
||||
is_collapsed: bool,
|
||||
collapsed: bool,
|
||||
side: Side,
|
||||
on_click: Option<Rc<dyn Fn(&ClickEvent, &mut Window, &mut App)>>,
|
||||
}
|
||||
|
|
@ -118,7 +118,7 @@ impl SidebarToggleButton {
|
|||
fn new(side: Side) -> Self {
|
||||
Self {
|
||||
btn: Button::new("sidebar-collapse").ghost().small(),
|
||||
is_collapsed: false,
|
||||
collapsed: false,
|
||||
side,
|
||||
on_click: None,
|
||||
}
|
||||
|
|
@ -137,8 +137,8 @@ impl SidebarToggleButton {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn collapsed(mut self, is_collapsed: bool) -> Self {
|
||||
self.is_collapsed = is_collapsed;
|
||||
pub fn collapsed(mut self, collapsed: bool) -> Self {
|
||||
self.collapsed = collapsed;
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -153,10 +153,10 @@ impl SidebarToggleButton {
|
|||
|
||||
impl RenderOnce for SidebarToggleButton {
|
||||
fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
|
||||
let is_collapsed = self.is_collapsed;
|
||||
let collapsed = self.collapsed;
|
||||
let on_click = self.on_click.clone();
|
||||
|
||||
let icon = if is_collapsed {
|
||||
let icon = if collapsed {
|
||||
if self.side.is_left() {
|
||||
IconName::PanelLeftOpen
|
||||
} else {
|
||||
|
|
@ -182,11 +182,11 @@ impl RenderOnce for SidebarToggleButton {
|
|||
|
||||
impl<E: Collapsible + IntoElement> RenderOnce for Sidebar<E> {
|
||||
fn render(mut self, _: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let is_collapsed = self.is_collapsed;
|
||||
let is_collapsed = self.collapsed;
|
||||
v_flex()
|
||||
.id("sidebar")
|
||||
.w(self.width)
|
||||
.when(self.is_collapsed, |this| this.w(COLLAPSED_WIDTH))
|
||||
.when(self.collapsed, |this| this.w(COLLAPSED_WIDTH))
|
||||
.flex_shrink_0()
|
||||
.h_full()
|
||||
.overflow_hidden()
|
||||
|
|
|
|||
Loading…
Reference in a new issue