Skip to content

Commit

Permalink
remove extra containers
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmoulton committed Jun 9, 2024
1 parent 5691c81 commit 8ac1976
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 160 deletions.
86 changes: 55 additions & 31 deletions lapce-app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ use floem::{
AlignItems, CursorStyle, Display, FlexDirection, JustifyContent, Position,
Style,
},
taffy::{
style_helpers::{self, auto, fr},
Line,
},
unit::PxPctAuto,
views::{
clip, container, drag_resize_window_area, drag_window_area, dyn_stack,
Expand Down Expand Up @@ -584,6 +588,7 @@ impl AppData {
}
}

/// The top bar of an Editor tab. Includes the tab forward/back buttons, the tab scroll bar and the new split and tab close all button.
fn editor_tab_header(
window_tab_data: Rc<WindowTabData>,
active_editor_tab: ReadSignal<Option<EditorTabId>>,
Expand Down Expand Up @@ -634,12 +639,11 @@ fn editor_tab_header(
let child_for_mouse_close = child.clone();
let main_split = main_split.clone();
let plugin = plugin.clone();
let child_view = move || {
let child_view = {
let info = child.view_info(editors, diff_editors, plugin, config);
let hovered = create_rw_signal(false);

use crate::config::ui::TabCloseButton;
let tab_close_button_style = config.get().ui.tab_close_button;

let tab_icon = container({
svg(move || info.with(|info| info.icon.clone())).style(move |s| {
Expand All @@ -648,7 +652,7 @@ fn editor_tab_header(
.apply_opt(info.with(|info| info.color), |s, c| s.color(c))
})
})
.style(|s| s.padding_horiz(10.0));
.style(|s| s.padding(4.));

let tab_content = label(move || info.with(|info| info.path.clone()))
.style(move |s| {
Expand All @@ -659,9 +663,6 @@ fn editor_tab_header(
.unwrap_or(true),
|s| s.font_style(FontStyle::Italic),
)
.apply_if(tab_close_button_style == TabCloseButton::Off, |s| {
s.margin_right(15.0)
})
});

let tab_close_button = clickable_icon(
Expand Down Expand Up @@ -691,31 +692,53 @@ fn editor_tab_header(
})
.on_event_stop(EventListener::PointerLeave, move |_| {
hovered.set(false);
})
.style(|s| s.margin_horiz(6.0));
});

let tab_style = move |s: Style| {
stack((
tab_icon.style(move |s| {
let tab_close_button = config.get().ui.tab_close_button;
s.apply_if(tab_close_button == TabCloseButton::Left, |s| {
s.grid_column(Line {
start: style_helpers::line(3),
end: style_helpers::span(1),
})
})
}),
tab_content.style(move |s| {
let tab_close_button = config.get().ui.tab_close_button;
s.apply_if(tab_close_button == TabCloseButton::Left, |s| {
s.grid_column(Line {
start: style_helpers::line(2),
end: style_helpers::span(1),
})
})
.apply_if(tab_close_button == TabCloseButton::Off, |s| {
s.padding_right(4.)
})
}),
tab_close_button.style(move |s| {
let tab_close_button = config.get().ui.tab_close_button;
s.apply_if(tab_close_button == TabCloseButton::Left, |s| {
s.grid_column(Line {
start: style_helpers::line(1),
end: style_helpers::span(1),
})
})
.apply_if(tab_close_button == TabCloseButton::Off, |s| s.hide())
}),
))
.style(move |s| {
s.items_center()
.justify_center()
.height_full()
.border_left(if i.get() == 0 { 1.0 } else { 0.0 })
.border_right(1.0)
.border_color(config.get().color(LapceColor::LAPCE_BORDER))
};

match tab_close_button_style {
TabCloseButton::Left => container(
stack((tab_close_button, tab_content, tab_icon))
.style(tab_style),
),
TabCloseButton::Right => container(
stack((tab_icon, tab_content, tab_close_button))
.style(tab_style),
),
TabCloseButton::Off => {
container(stack((tab_icon, tab_content)).style(tab_style))
}
}
.padding_horiz(6.)
.gap(6.)
.grid()
.grid_template_columns(vec![auto(), fr(1.), auto()])
})
};

let confirmed = match local_child {
Expand All @@ -734,7 +757,7 @@ fn editor_tab_header(
let header_content_size = create_rw_signal(Size::ZERO);
let drag_over_left: RwSignal<Option<bool>> = create_rw_signal(None);
stack((
child_view()
child_view
.on_double_click_stop(move |_| {
if let Some(confirmed) = confirmed {
confirmed.set(true);
Expand Down Expand Up @@ -1741,15 +1764,16 @@ fn split_list(
let editor_tab_data = editor_tabs
.with_untracked(|tabs| tabs.get(editor_tab_id).cloned());
if let Some(editor_tab_data) = editor_tab_data {
container(editor_tab(
editor_tab(
window_tab_data.clone(),
plugin.clone(),
active_editor_tab,
editor_tab_data,
dragging,
))
)
.into_any()
} else {
container(text("empty editor tab"))
text("empty editor tab").into_any()
}
}
SplitContent::Split(split_id) => {
Expand All @@ -1762,8 +1786,9 @@ fn split_list(
plugin.clone(),
dragging,
)
.into_any()
} else {
container(text("empty split"))
text("empty split").into_any()
}
}
};
Expand Down Expand Up @@ -1995,8 +2020,7 @@ fn workbench(window_tab_data: Rc<WindowTabData>) -> impl View {
let workbench_size = window_tab_data.common.workbench_size;
let main_split_width = window_tab_data.main_split.width;
stack((
panel_container_view(window_tab_data.clone(), PanelContainerPosition::Left)
.style(|s| s.border_right(0.)),
panel_container_view(window_tab_data.clone(), PanelContainerPosition::Left),
{
let window_tab_data = window_tab_data.clone();
stack((
Expand Down
78 changes: 32 additions & 46 deletions lapce-app/src/editor/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,18 +695,6 @@ impl EditorView {
return;
}

cx.fill(
&Rect::ZERO
.with_size(Size::new(1.0, viewport.height()))
.with_origin(Point::new(
viewport.x0 + viewport.width() - BAR_WIDTH,
viewport.y0,
))
.inflate(0.0, 10.0),
config.color(LapceColor::LAPCE_SCROLL_BAR),
0.0,
);

if !self.editor.kind.get_untracked().is_normal() {
return;
}
Expand Down Expand Up @@ -1114,8 +1102,8 @@ impl View for EditorView {
let screen_lines = ed.screen_lines.get_untracked();
FloemEditorView::paint_text(cx, ed, viewport, is_active, &screen_lines);
let screen_lines = ed.screen_lines.get_untracked();
self.paint_sticky_headers(cx, viewport, &screen_lines);
self.paint_scroll_bar(cx, viewport, is_local, config);
self.paint_sticky_headers(cx, viewport, &screen_lines);
}
}

Expand Down Expand Up @@ -1260,39 +1248,36 @@ pub fn editor_container_view(

stack((
editor_breadcrumbs(workspace, editor.get_untracked(), config),
container(
stack((
editor_gutter(window_tab_data.clone(), editor, is_active),
editor_content(editor, debug_breakline, is_active),
empty().style(move |s| {
let config = config.get();
s.absolute()
.width_pct(100.0)
.height(sticky_header_height.get() as f32)
// .box_shadow_blur(5.0)
// .border_bottom(1.0)
// .border_color(
// config.get_color(LapceColor::LAPCE_BORDER),
// )
.apply_if(
!config.editor.sticky_header
|| sticky_header_height.get() == 0.0
|| !editor_view.get().is_normal(),
|s| s.hide(),
)
}),
find_view(
editor,
find_editor,
find_focus,
replace_editor,
replace_active,
replace_focus,
is_active,
),
))
.style(|s| s.absolute().size_full()),
)
stack((
editor_gutter(window_tab_data.clone(), editor, is_active),
editor_content(editor, debug_breakline, is_active),
empty().style(move |s| {
let config = config.get();
s.absolute()
.width_pct(100.0)
.height(sticky_header_height.get() as f32)
// .box_shadow_blur(5.0)
// .border_bottom(1.0)
// .border_color(
// config.get_color(LapceColor::LAPCE_BORDER),
// )
.apply_if(
!config.editor.sticky_header
|| sticky_header_height.get() == 0.0
|| !editor_view.get().is_normal(),
|s| s.hide(),
)
}),
find_view(
editor,
find_editor,
find_focus,
replace_editor,
replace_active,
replace_focus,
is_active,
),
))
.style(|s| s.width_full().flex_basis(0).flex_grow(1.0)),
))
.on_cleanup(move || {
Expand Down Expand Up @@ -1736,6 +1721,7 @@ fn editor_breadcrumbs(
.width_pct(100.0)
.height(line_height as f32)
.apply_if(doc_path.get().is_none(), |s| s.hide())
.apply_if(!config.editor.show_bread_crumbs, |s| s.hide())
})
.debug_name("Editor BreadCrumbs")
}
Expand Down
23 changes: 14 additions & 9 deletions lapce-app/src/file_explorer/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,20 @@ pub fn file_explorer_panel(
.add_height_style(
"Open Editors",
150.0,
container(open_editors_view(window_tab_data.clone()))
.style(|s| s.size_full()),
open_editors_view(window_tab_data.clone()).style(|s| s.size_full()),
window_tab_data.panel.section_open(PanelSection::OpenEditor),
move |s| s.apply_if(!config.get().ui.open_editors_visible, Style::hide),
move |s| s.apply_if(!config.get().ui.open_editors_visible, |s| s.hide()),
)
.add(
"File Explorer",
container(
new_file_node_view(data, source_control).style(|s| s.absolute()),
)
.style(|s| s.size_full().line_height(1.6)),
new_file_node_view(data, source_control)
.style(|s| s.size_full().line_height(1.6)),
window_tab_data
.panel
.section_open(PanelSection::FileExplorer),
)
.build()
.debug_name("File Explorer Panel")
}

/// Initialize the file explorer's naming (renaming, creating, etc.) editor with the given path.
Expand Down Expand Up @@ -419,7 +417,7 @@ fn new_file_node_view(
)
.style(|s| s.flex_col().align_items(AlignItems::Stretch).width_full()),
)
.style(|s| s.size_full())
.style(|s| s.min_height(0).flex_grow(1.).flex_basis(0.).size_full())
.on_secondary_click_stop(move |_| {
if let Naming::None = naming.get_untracked() {
if let Some(path) = &secondary_click_data.common.workspace.path {
Expand Down Expand Up @@ -550,5 +548,12 @@ fn open_editors_view(window_tab_data: Rc<WindowTabData>) -> impl View {
)
.style(|s| s.flex_col().width_pct(100.0)),
)
.style(|s| s.absolute().size_pct(100.0, 100.0).line_height(1.6))
.style(|s| {
s.min_height(0)
.flex_grow(1.)
.flex_basis(0.)
.size_full()
.line_height(1.6)
})
.debug_name("Open Editors")
}
1 change: 1 addition & 0 deletions lapce-app/src/panel/debug_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub fn debug_panel(
window_tab_data.panel.section_open(PanelSection::Breakpoint),
)
.build()
.debug_name("Debug Panel")
}

fn debug_process_icons(
Expand Down
1 change: 1 addition & 0 deletions lapce-app/src/panel/global_search_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ pub fn global_search_panel(
search_result(workspace, global_search, internal_command, config),
))
.style(|s| s.absolute().size_pct(100.0, 100.0).flex_col())
.debug_name("Global Search Panel")
}

fn search_result(
Expand Down
1 change: 1 addition & 0 deletions lapce-app/src/panel/plugin_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub fn plugin_panel(
window_tab_data.panel.section_open(PanelSection::Available),
)
.build()
.debug_name("Plugin Panel")
}

fn installed_view(plugin: PluginData) -> impl View {
Expand Down
1 change: 1 addition & 0 deletions lapce-app/src/panel/problem_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub fn problem_panel(
window_tab_data.panel.section_open(PanelSection::Warn),
)
.build()
.debug_name("Problem Panel")
}

fn problem_section(
Expand Down
1 change: 1 addition & 0 deletions lapce-app/src/panel/source_control_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ pub fn source_control_panel(
}
})
.style(|s| s.flex_col().size_pct(100.0, 100.0))
.debug_name("Source Control Panel")
}

fn file_diffs_view(source_control: SourceControlData) -> impl View {
Expand Down
1 change: 1 addition & 0 deletions lapce-app/src/panel/terminal_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub fn terminal_panel(window_tab_data: Rc<WindowTabData>) -> impl View {
}
})
.style(|s| s.absolute().size_pct(100.0, 100.0).flex_col())
.debug_name("Terminal Panel")
}

fn terminal_tab_header(window_tab_data: Rc<WindowTabData>) -> impl View {
Expand Down
Loading

0 comments on commit 8ac1976

Please sign in to comment.