Skip to content

Commit

Permalink
Refactored quick start code
Browse files Browse the repository at this point in the history
  • Loading branch information
abey79 committed Oct 12, 2023
1 parent 47127df commit 54efcd1
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 58 deletions.
3 changes: 3 additions & 0 deletions crates/re_viewer/data/quick_start_guides/cpp_native.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## C++ Quick Start

TODO(ab)
3 changes: 3 additions & 0 deletions crates/re_viewer/data/quick_start_guides/how_does_it_work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### How does it work?

TBC
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
use re_data_store::StoreDb;
use re_log_types::{
ApplicationId, DataRow, EntityPath, RowId, StoreId, StoreInfo, StoreKind, StoreSource, Time,
TimePoint,
};
use re_viewer_context::{SystemCommand, SystemCommandSender};

pub(super) fn python_quick_start(
command_sender: &re_viewer_context::CommandSender,
) -> anyhow::Result<()> {
let text_doc =
re_types::archetypes::TextDocument::new(
r#"
## Python Quick Start

### Installing the Rerun SDK
Expand Down Expand Up @@ -69,35 +56,4 @@ rr.log(
# log data as a 3D point cloud archetype
rr.Points3D(positions, colors=colors, radii=0.5)
)
```
### How does it work?
TBC
"#
.trim(),
)
.with_media_type(re_types::components::MediaType::markdown());

let row = DataRow::from_archetype(
RowId::random(),
TimePoint::timeless(),
EntityPath::from("quick_start"),
&text_doc,
)?;

let store_info = StoreInfo {
application_id: ApplicationId::from("Python Quick Start"),
store_id: StoreId::random(StoreKind::Recording),
is_official_example: true,
started: Time::now(),
store_source: StoreSource::InAppGuides,
store_kind: StoreKind::Recording,
};

let store_db = StoreDb::from_info_and_rows(store_info, [row])?;

command_sender.send_system(SystemCommand::LoadStoreDb(store_db));

Ok(())
}
```
3 changes: 3 additions & 0 deletions crates/re_viewer/data/quick_start_guides/rust_native.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Rust Quick Start

TODO(ab)
1 change: 0 additions & 1 deletion crates/re_viewer/src/ui/welcome_screen/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mod example_page;
mod python_quick_start;
mod welcome_page;

use egui::Widget;
Expand Down
96 changes: 84 additions & 12 deletions crates/re_viewer/src/ui/welcome_screen/welcome_page.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use super::{
large_text_button, python_quick_start::python_quick_start, status_strings,
url_large_text_button, WelcomeScreenResponse,
};
use super::{large_text_button, status_strings, url_large_text_button, WelcomeScreenResponse};
use egui::{NumExt, Ui};
use re_log_types::LogMsg;
use itertools::Itertools;
use re_data_store::StoreDb;
use re_log_types::{
ApplicationId, DataRow, EntityPath, LogMsg, RowId, StoreId, StoreInfo, StoreKind, StoreSource,
Time, TimePoint,
};
use re_smart_channel::ReceiveSet;
use re_ui::UICommandSender;
use re_viewer_context::{SystemCommand, SystemCommandSender};

const RUST_QUICKSTART: &str = "https://www.rerun.io/docs/getting-started/rust";
const SPACE_VIEWS_HELP: &str = "https://www.rerun.io/docs/getting-started/viewer-walkthrough";

/// Show the welcome page.
Expand Down Expand Up @@ -59,14 +61,39 @@ fn onboarding_content_ui(
Visualize synchronized data from multiple processes, locally or over a network.",
image: &re_ui::icons::WELCOME_SCREEN_LIVE_DATA,
add_buttons: Box::new(|ui: &mut egui::Ui| {
// TODO(ab): activate when C++ is ready!
// url_large_text_button(ui, "C++", CPP_QUICKSTART);
if large_text_button(ui, "C++").clicked() {
open_quick_start(
command_sender,
[
include_str!("../../../data/quick_start_guides/cpp_native.md"),
include_str!("../../../data/quick_start_guides/how_does_it_work.md"),
],
"C++ Quick Start",
"cpp_quick_start",
);
}
if large_text_button(ui, "Python").clicked() {
if let Err(err) = python_quick_start(command_sender) {
re_log::error!("Failed to load Python quick start: {}", err);
}
open_quick_start(
command_sender,
[
include_str!("../../../data/quick_start_guides/python_native.md"),
include_str!("../../../data/quick_start_guides/how_does_it_work.md"),
],
"Python Quick Start",
"python_quick_start",
);
}
if large_text_button(ui, "Rust").clicked() {
open_quick_start(
command_sender,
[
include_str!("../../../data/quick_start_guides/rust_native.md"),
include_str!("../../../data/quick_start_guides/how_does_it_work.md"),
],
"Rust Quick Start",
"rust_quick_start",
);
}
url_large_text_button(ui, "Rust", RUST_QUICKSTART);

false
}),
Expand Down Expand Up @@ -236,3 +263,48 @@ fn image_banner(ui: &mut egui::Ui, icon: &re_ui::Icon, column_width: f32, max_im
);
});
}

fn open_quick_start<'a>(
command_sender: &re_viewer_context::CommandSender,
parts: impl IntoIterator<Item = &'a str>,
app_id: impl AsRef<str>,
entity_path: impl AsRef<str>,
) {
let markdown = parts.into_iter().join("\n");
let res = open_markdown_recording(command_sender, &markdown, app_id, entity_path);
if let Err(err) = res {
re_log::error!("Failed to load quick start: {}", err);
}
}

fn open_markdown_recording(
command_sender: &re_viewer_context::CommandSender,
markdown: impl AsRef<str>,
app_id: impl AsRef<str>,
entity_path: impl AsRef<str>,
) -> anyhow::Result<()> {
let text_doc = re_types::archetypes::TextDocument::new(markdown.as_ref())
.with_media_type(re_types::components::MediaType::markdown());

let row = DataRow::from_archetype(
RowId::random(),
TimePoint::timeless(),
EntityPath::from(entity_path.as_ref()),
&text_doc,
)?;

let store_info = StoreInfo {
application_id: ApplicationId::from(app_id.as_ref()),
store_id: StoreId::random(StoreKind::Recording),
is_official_example: true,
started: Time::now(),
store_source: StoreSource::InAppGuides,
store_kind: StoreKind::Recording,
};

let store_db = StoreDb::from_info_and_rows(store_info, [row])?;

command_sender.send_system(SystemCommand::LoadStoreDb(store_db));

Ok(())
}

0 comments on commit 54efcd1

Please sign in to comment.