Skip to content

Commit

Permalink
live-preview: Sort selection popup by area of elements
Browse files Browse the repository at this point in the history
This is an alternate mode in the selection popup, click on
the button next to the search bar to activate.
  • Loading branch information
hunger committed Dec 10, 2024
1 parent 4d309f6 commit ae97be5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ SPDX-License-Identifier = "LicenseRef-qskinny"
path = [
"tools/lsp/ui/assets/chevron-down.svg",
"tools/lsp/ui/assets/inspect.svg",
"tools/lsp/ui/assets/list-filter.svg",
"tools/lsp/ui/assets/layout-sidebar**.svg",
"tools/lsp/ui/assets/search.svg",
"tools/lsp/ui/assets/sync.svg",
Expand Down
13 changes: 12 additions & 1 deletion tools/lsp/preview/element_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,21 @@ pub fn selection_stack_at(
pub fn filter_sort_selection_stack(
model: slint::ModelRc<crate::preview::ui::SelectionStackFrame>,
filter: slint::SharedString,
sort_by_area: bool,
) -> slint::ModelRc<crate::preview::ui::SelectionStackFrame> {
use slint::ModelExt;

eprintln!("filter: {filter}");
let model = if sort_by_area {
Rc::new(model.sort_by(|a, b| {
let a_area = a.width * a.height;
let b_area = b.width * b.height;

a_area.partial_cmp(&b_area).unwrap_or(std::cmp::Ordering::Equal)
}))
.into()
} else {
model
};

let filter = filter.to_string();

Expand Down
2 changes: 1 addition & 1 deletion tools/lsp/ui/api.slint
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ export global Api {

// ## Element selection:
callback selection-stack-at(x: length, y: length) -> [SelectionStackFrame];
pure callback filter-sort-selection-stack(model: [SelectionStackFrame], filter: string) -> [SelectionStackFrame];
pure callback filter-sort-selection-stack(model: [SelectionStackFrame], filter: string, sort-by-area: bool) -> [SelectionStackFrame];
pure callback find-selected-selection-stack-frame([SelectionStackFrame]) -> SelectionStackFrame;
callback select-element(file: string, offset: int, x: length, y: length);

Expand Down
1 change: 1 addition & 0 deletions tools/lsp/ui/assets/list-filter.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 8 additions & 2 deletions tools/lsp/ui/components/selection-popup.slint
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © SixtyFPS GmbH <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

import { ListView, Palette, ScrollView, LineEdit } from "std-widgets.slint";
import { ListView, Palette, ScrollView, LineEdit, Button } from "std-widgets.slint";
import { EditorFontSettings, EditorSizeSettings, EditorSpaceSettings, EditorPalette } from "./styling.slint";
import { Api, SelectionStackFrame } from "../api.slint";
import { Icons } from "styling.slint";
Expand Down Expand Up @@ -165,14 +165,20 @@ component PopupInner inherits Rectangle {
self.focus();
}
}

sort-by-area-button := Button {
checkable: true;
icon: Icons.list-filter;
colorize-icon: true;
}
}

ScrollView {
height: (root.visible-frames * root.frame-height);

list-view := VerticalLayout {

for frame[index] in Api.filter-sort-selection-stack(root.selection-stack, filter-edit.text): frame-rect := Rectangle {
for frame[index] in Api.filter-sort-selection-stack(root.selection-stack, filter-edit.text, sort-by-area-button.checked): frame-rect := Rectangle {
height: root.frame-height;

function frame-color(frame: SelectionStackFrame) -> brush {
Expand Down
1 change: 1 addition & 0 deletions tools/lsp/ui/components/styling.slint
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Palette } from "std-widgets.slint";
export global Icons {
out property <image> add: @image-url("../assets/add.svg");
out property <image> chevron-down: @image-url("../assets/chevron-down.svg");
out property <image> list-filter: @image-url("../assets/list-filter.svg");
out property <image> inspect: @image-url("../assets/inspect.svg");
out property <image> search: @image-url("../assets/search.svg");
out property <image> sidebar-left-off: @image-url("../assets/layout-sidebar-left-off.svg");
Expand Down

0 comments on commit ae97be5

Please sign in to comment.