Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open editors list can now be collapsed by clicking it #1574

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions lapce-ui/src/explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,6 @@ impl Widget<LapceTabData> for FileExplorerFileList {
file_explorer.active_selected = path.clone();
ctx.request_paint();
}

LapceUICommand::FileExplorerRefresh => {
data.file_explorer.reload();
}
Expand All @@ -605,7 +604,6 @@ impl Widget<LapceTabData> for FileExplorerFileList {
ctx,
);
}

_ => (),
}
}
Expand Down Expand Up @@ -1208,6 +1206,9 @@ impl OpenEditorList {
.unwrap_or(&path)
.to_path_buf();
}
// TODO: Can be updated to use a disambiguation algorithm.
// For example when opening multiple lib.rs which usually sits
// under src/
hint = path
.parent()
.and_then(|s| s.to_str())
Expand Down Expand Up @@ -1444,6 +1445,8 @@ impl Widget<LapceTabData> for OpenEditorList {
.iter()
.map(|(_, tab)| tab.children.len())
.sum::<usize>();

// If there are split editor tabs, then we need to consider the group headers
let n = if data.main_split.editor_tabs.len() > 1 {
n + data.main_split.editor_tabs.len()
} else {
Expand All @@ -1457,6 +1460,7 @@ impl Widget<LapceTabData> for OpenEditorList {
let rect = ctx.region().bounding_box();
let mut i = 0;
let mut g = 0;

for (_, tab) in
data.main_split
.editor_tabs
Expand Down
126 changes: 95 additions & 31 deletions lapce-ui/src/panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,27 +94,23 @@ impl LapcePanel {
)>,
) -> Self {
let mut split = LapceSplit::new(split_id).panel(kind);
for (section_widget_id, header, content, size) in sections {
for (section_id, header, content, size) in sections {
let header = match header {
PanelHeaderKind::None => None,
PanelHeaderKind::Simple(s) => {
Some(PanelSectionHeader::new(s, kind).boxed())
}
PanelHeaderKind::Widget(w) => Some(w),
};
let section =
PanelSection::new(section_widget_id, header, content).boxed();
let section = PanelSection::new(header, content).boxed();

split = match size {
PanelSizing::Size(size) => {
split.with_child(section, Some(section_widget_id), size)
split.with_child(section, Some(section_id), size)
}
PanelSizing::Flex(resizable) => {
split.with_flex_child(section, Some(section_id), 1.0, resizable)
}
PanelSizing::Flex(resizable) => split.with_flex_child(
section,
Some(section_widget_id),
1.0,
resizable,
),
};
}
Self {
Expand Down Expand Up @@ -158,6 +154,8 @@ pub enum PanelHeaderKind {
}

struct PanelSection {
display_content: bool,
mouse_down: bool,
header: Option<WidgetPod<LapceTabData, Box<dyn Widget<LapceTabData>>>>,
content: WidgetPod<
LapceTabData,
Expand All @@ -167,18 +165,21 @@ struct PanelSection {

impl PanelSection {
pub fn new(
_widget_id: WidgetId,
header: Option<Box<dyn Widget<LapceTabData>>>,
content: Box<dyn Widget<LapceTabData>>,
) -> Self {
let content = LapceScroll::new(content).vertical();
Self {
display_content: true,
mouse_down: true,
header: header.map(WidgetPod::new),
content: WidgetPod::new(content),
}
}
}

const HEADER_HEIGHT: f64 = 30.0f64;

impl Widget<LapceTabData> for PanelSection {
fn event(
&mut self,
Expand All @@ -187,6 +188,37 @@ impl Widget<LapceTabData> for PanelSection {
data: &mut LapceTabData,
env: &Env,
) {
match event {
Event::MouseMove(mouse_pos) => {
if self.header.is_some()
&& Rect::new(0.0f64, 0.0f64, HEADER_HEIGHT, HEADER_HEIGHT)
.contains(mouse_pos.pos)
{
ctx.set_cursor(&Cursor::Pointer);
}
}
Event::MouseDown(mouse_pos) => {
if self.header.is_some()
&& Rect::new(0.0f64, 0.0f64, HEADER_HEIGHT, HEADER_HEIGHT)
.contains(mouse_pos.pos)
{
self.mouse_down = true
}
}
Event::MouseUp(mouse_pos) => {
if self.header.is_some()
&& self.mouse_down
&& Rect::new(0.0f64, 0.0f64, HEADER_HEIGHT, HEADER_HEIGHT)
.contains(mouse_pos.pos)
{
self.mouse_down = false;
self.display_content = !self.display_content;
ctx.request_layout();
}
}
_ => {}
}

if let Some(header) = self.header.as_mut() {
header.event(ctx, event, data, env);
}
Expand Down Expand Up @@ -227,40 +259,71 @@ impl Widget<LapceTabData> for PanelSection {
env: &Env,
) -> Size {
let self_size = bc.max();
let header_height = if let Some(header) = self.header.as_mut() {
let header_height = 30.0;
header.layout(

let header_size = if let Some(header) = self.header.as_mut() {
let s = header.layout(
ctx,
&BoxConstraints::tight(Size::new(self_size.width, header_height)),
&BoxConstraints::tight(Size::new(
self_size.width - HEADER_HEIGHT,
HEADER_HEIGHT,
)),
data,
env,
);
header.set_origin(ctx, data, env, Point::ZERO);
header_height
header.set_origin(ctx, data, env, Point::new(HEADER_HEIGHT, 0.0));
s
} else {
0.0
Size::ZERO
};

let content_size = self.content.layout(
ctx,
&BoxConstraints::new(
Size::ZERO,
Size::new(self_size.width, self_size.height - header_height),
),
data,
env,
);
self.content
.set_origin(ctx, data, env, Point::new(0.0, header_height));
let content_size = if self.display_content {
let s = self.content.layout(
ctx,
&BoxConstraints::new(
Size::ZERO,
Size::new(
self_size.width - HEADER_HEIGHT,
self_size.height - HEADER_HEIGHT,
),
),
data,
env,
);
self.content.set_origin(
ctx,
data,
env,
Point::new(0.0, header_size.height),
);
s
} else {
Size::ZERO
};

Size::new(content_size.width, header_height + content_size.height)
Size::new(self_size.width, header_size.height + content_size.height)
}

fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) {
self.content.paint(ctx, data, env);
if let Some(header) = self.header.as_mut() {
let icon_name = if self.display_content {
LapceIcons::PANEL_RESTORE
} else {
LapceIcons::PANEL_MAXIMISE
};

ctx.draw_svg(
&data.config.ui_svg(icon_name),
Size::new(HEADER_HEIGHT, HEADER_HEIGHT)
.to_rect()
.with_origin(Point::ZERO),
None,
);

header.paint(ctx, data, env);
}
if self.display_content {
self.content.paint(ctx, data, env);
}
}
}

Expand Down Expand Up @@ -315,6 +378,7 @@ impl Widget<LapceTabData> for PanelSectionHeader {

fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, _env: &Env) {
let rect = ctx.size().to_rect();

ctx.fill(
rect,
data.config
Expand Down
1 change: 0 additions & 1 deletion lapce-ui/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ impl Plugin {

pub fn new_panel(data: &LapceTabData) -> LapcePanel {
let split_id = WidgetId::next();

LapcePanel::new(
PanelKind::Plugin,
data.plugin.widget_id,
Expand Down