Skip to content

Commit e11be67

Browse files
File select screen
1 parent 0e0bed8 commit e11be67

13 files changed

Lines changed: 558 additions & 249 deletions

Cargo.lock

Lines changed: 290 additions & 234 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
slint = {version = "1.12.1", features = ["renderer-software"]}
9+
slint = {version = "1", features = ["renderer-software"]}
1010
toml = "0"
1111
thiserror = "2"
1212
clap = { version = "4", features = ["derive"] }

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
8282

8383
register_filesystem_list_files(&ui, &moonraker_connection);
8484
register_filesystem_fetch_metadata(&ui, &moonraker_connection);
85+
register_filesystem_load_high_res_thumbnail(&ui, &moonraker_connection);
8586

8687
register_temperature_set_new_target_temperature(&ui, &moonraker_connection);
8788

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
use std::sync::Arc;
2+
3+
use moonraker_rs::{moonraker_connection::MoonrakerConnection, requests::{FileManagementRequestHandler, MoonrakerFileThumbnail}};
4+
use slint::{ComponentHandle, Image, Model, Rgba8Pixel, SharedPixelBuffer, SharedString, VecModel};
5+
use tokio::sync::Mutex;
6+
7+
use crate::{AppWindow, Filesystem, MoonrakerFile};
8+
9+
pub fn register_filesystem_load_high_res_thumbnail(ui: &AppWindow, moonraker_connection : &Arc<MoonrakerConnection>)
10+
{
11+
let ui_weak = ui.as_weak();
12+
let moonraker_connection = moonraker_connection.clone();
13+
14+
ui.global::<Filesystem>()
15+
.on_load_high_res_thumbnail(move |file_path| {
16+
let ui_weak = ui_weak.clone();
17+
let moonraker_connection = moonraker_connection.clone();
18+
19+
slint::spawn_local(async move {
20+
let thumbnails = match moonraker_connection
21+
.get_thumbnails_for_file(&file_path)
22+
.await
23+
{
24+
Ok(t) => t,
25+
Err(e) => {
26+
moonraker_connection.send_request_error(format!("Failed to get thumbnails for file {}: {}", file_path, e));
27+
return;
28+
}
29+
};
30+
31+
let mut selected_thumbnail : MoonrakerFileThumbnail = MoonrakerFileThumbnail {
32+
width: 0,
33+
height: 0,
34+
size: 0,
35+
thumbnail_path: String::from(""),
36+
};
37+
38+
for thumbnail in thumbnails {
39+
// No non-square thumbnails
40+
if thumbnail.height != thumbnail.width
41+
{
42+
continue;
43+
}
44+
45+
if thumbnail.height > 256
46+
{
47+
continue;
48+
}
49+
50+
if selected_thumbnail.width < thumbnail.width
51+
{
52+
selected_thumbnail = thumbnail;
53+
}
54+
}
55+
56+
if selected_thumbnail.width <= 0
57+
{
58+
return;
59+
}
60+
61+
let data = moonraker_connection
62+
.download_thumbnail(&selected_thumbnail.thumbnail_path)
63+
.await
64+
.unwrap();
65+
66+
// TODO: Error handling
67+
let image = image::load_from_memory(&data).unwrap().into_rgba8();
68+
let shared_buf: SharedPixelBuffer<Rgba8Pixel> =
69+
SharedPixelBuffer::clone_from_slice(
70+
image.as_raw(),
71+
image.width(),
72+
image.height(),
73+
);
74+
75+
let ui = ui_weak.upgrade().unwrap();
76+
ui.global::<Filesystem>().set_high_res_thumbnail(Image::from_rgba8(shared_buf));
77+
})
78+
.unwrap();
79+
});
80+
}

src/ui_functions/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub mod quick_action_execute;
1313
pub mod util_time_in_seconds_to_string;
1414
pub mod misc_set_power_device;
1515
pub mod misc_fetch_power_devices;
16+
pub mod filesystem_load_high_res_thumbnail;
1617

1718
pub use util_format_bytes::*;
1819
pub use filesystem_fetch_metadata::*;
@@ -28,4 +29,5 @@ pub use settings_set_ui_settings::*;
2829
pub use quick_action_execute::*;
2930
pub use util_time_in_seconds_to_string::*;
3031
pub use misc_set_power_device::*;
31-
pub use misc_fetch_power_devices::*;
32+
pub use misc_fetch_power_devices::*;
33+
pub use filesystem_load_high_res_thumbnail::*;

ui/assets/height.svg

Lines changed: 1 addition & 0 deletions
Loading

ui/assets/layer_height.svg

Lines changed: 1 addition & 0 deletions
Loading

ui/components/badge.slint

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Palette } from "std-widgets.slint";
2+
import { Constants } from "../constants.slint";
3+
import { HorizontalStart } from "horizontal.slint";
4+
import { Utils } from "../state.slint";
5+
6+
export component Badge inherits Rectangle {
7+
in property <string> text;
8+
in property <image> icon;
9+
in property <length> spacing: Constants.spacing-half / 2;
10+
in property <color> foreground: Palette.accent-foreground;
11+
height: 16px + Constants.padding;
12+
13+
background: Palette.accent-background;
14+
border-radius: Constants.radius-md;
15+
16+
hs := HorizontalStart {
17+
spacing: spacing;
18+
padding-left: Constants.padding-half;
19+
padding-right: Constants.padding-half;
20+
padding-top: Constants.padding-quarter;
21+
padding-bottom: Constants.padding-quarter;
22+
23+
if Utils.image_exists(icon): Image {
24+
source: icon;
25+
colorize: foreground;
26+
}
27+
28+
ta := Text {
29+
text: text;
30+
vertical-alignment: center;
31+
color: foreground;
32+
}
33+
}
34+
}

ui/components/small-button.slint

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ export component SmallButton inherits Rectangle {
3232
source: root.icon;
3333
colorize: Palette.control-foreground;
3434
vertical-alignment: center;
35+
width: 24px;
3536
}
3637

37-
Text {
38+
if root.text != "": Text {
3839
text: root.text;
3940
color: Palette.control-foreground;
4041
vertical-alignment: center;

ui/components/vertical.slint

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export component VerticalCenter inherits VerticalStart {
1515

1616
}
1717

18+
export component VerticalEnd inherits VerticalStart {
19+
alignment: LayoutAlignment.end;
20+
}
21+
1822
export component VerticalScrollable inherits Flickable {
1923
in property <length> list-padding <=> layout.padding;
2024
in property <length> list-spacing <=> layout.spacing;

0 commit comments

Comments
 (0)