Skip to content

Commit

Permalink
Merge pull request #27 from pragmatrix/massive-logs
Browse files Browse the repository at this point in the history
Massive Logs Example - A simple log viewer.
  • Loading branch information
pragmatrix committed Jul 2, 2024
2 parents cd45b8f + c5f7116 commit b0ce721
Show file tree
Hide file tree
Showing 27 changed files with 1,333 additions and 138 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@
"hitbox",
"inlyne",
"Interactor",
"JETBRAINS",
"mult",
"multisampled",
"multiview",
"rasterizer",
"reqwest",
"rpass",
"rsqrt",
"shortcodes",
"SSEDT",
"striked",
"Syntect",
"tasklist",
"termwiz",
"texel",
"texels",
"textbox",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ cargo run --release --example markdown

## Acronyms used in the code.

- DR: Decision Record.
- OO: Optimization Opportunity
- NI: Naming Issue
- DI: Design Issue (e.g. something does not seem to belong here)
22 changes: 12 additions & 10 deletions examples/code/examples/code-viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use massive_scene::PositionedShape;
use massive_shell::{shell, ApplicationContext};
use shared::{
application::{Application, UpdateResponse},
code_viewer::{self, AttributedCode},
attributed_text::{self, AttributedText},
};

const CANVAS_ID: &str = "massive-code";
Expand Down Expand Up @@ -60,7 +60,7 @@ async fn code_viewer(mut ctx: ApplicationContext) -> Result<()> {

// let code: AttributedCode =
// serde_json::from_str(&fs::read_to_string("/tmp/code.json").unwrap()).unwrap();
let code: AttributedCode = postcard::from_bytes(include_bytes!("code.postcard")).unwrap();
let code: AttributedText = postcard::from_bytes(include_bytes!("code.postcard")).unwrap();

// Shape and layout text.

Expand All @@ -69,12 +69,13 @@ async fn code_viewer(mut ctx: ApplicationContext) -> Result<()> {
// let font_size = 16.;
// let line_height = 20.;

let (glyph_runs, height) = code_viewer::shape_text(
let (glyph_runs, height) = attributed_text::shape_text(
&mut font_system,
&code.text,
&code.attributes,
font_size,
line_height,
None,
);

// Camera
Expand All @@ -98,16 +99,17 @@ async fn code_viewer(mut ctx: ApplicationContext) -> Result<()> {
)
.await?;

let mut application = Application::new(SizeI::new(1280, height as u64));
let mut current_matrix = application.matrix();
let page_size = SizeI::new(1280, height as u64);
let mut application = Application::default();
let mut current_matrix = application.matrix(page_size);
let matrix = director.cast(current_matrix);
let position = director.cast(matrix.clone().into());

// Hold the positioned shapes in this context, otherwise they will disappear.
let _positioned_shapes: Vec<_> = glyph_runs
.into_iter()
.map(|run| director.cast(PositionedShape::new(position.clone(), run)))
.collect();
let _positioned_shape = director.cast(PositionedShape::new(
position.clone(),
glyph_runs.into_iter().map(|m| m.into()).collect::<Vec<_>>(),
));

director.action()?;

Expand All @@ -123,7 +125,7 @@ async fn code_viewer(mut ctx: ApplicationContext) -> Result<()> {

// DI: This check has to be done in the renderer and the renderer has to decide when it
// needs to redraw.
let new_matrix = application.matrix();
let new_matrix = application.matrix(page_size);
if new_matrix != current_matrix {
matrix.update(new_matrix);
current_matrix = new_matrix;
Expand Down
27 changes: 16 additions & 11 deletions examples/code/examples/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ use load_cargo::{LoadCargoConfig, ProcMacroServerChoice};
use project_model::CargoConfig;
use shared::{
application::{Application, UpdateResponse},
code_viewer,
attributed_text,
};
use syntax::{AstNode, SyntaxKind, WalkEvent};
use tracing::info;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Registry};
use vfs::VfsPath;
use winit::dpi::LogicalSize;

use crate::code_viewer::TextAttribute;
use crate::attributed_text::TextAttribute;
use massive_geometry::{Camera, Color, SizeI};
use massive_scene::PositionedShape;
use massive_shapes::TextWeight;
Expand Down Expand Up @@ -225,7 +225,7 @@ async fn application(mut ctx: ApplicationContext) -> Result<()> {

// Store for the web viewer.

let attributed_code = code_viewer::AttributedCode {
let attributed_code = attributed_text::AttributedText {
text: file_text.to_string(),
attributes: attributes.clone(),
};
Expand All @@ -249,12 +249,13 @@ async fn application(mut ctx: ApplicationContext) -> Result<()> {
// let font_size = 16.;
// let line_height = 20.;

let (glyph_runs, height) = code_viewer::shape_text(
let (glyph_runs, height) = attributed_text::shape_text(
&mut font_system,
&file_text,
&attributes,
font_size,
line_height,
None,
);

// Window
Expand All @@ -272,22 +273,26 @@ async fn application(mut ctx: ApplicationContext) -> Result<()> {

// Application

let mut application = Application::new(SizeI::new(1280, height as u64));
let page_size = SizeI::new(1280, height as u64);
let mut application = Application::default();

let font_system = Arc::new(Mutex::new(font_system));

let (mut renderer, mut director) = window
.new_renderer(font_system, camera, initial_size)
.await?;

let mut current_matrix = application.matrix();
let mut current_matrix = application.matrix(page_size);
let matrix = director.cast(current_matrix);
let position = director.cast(matrix.clone().into());

let _positioned_shapes: Vec<_> = glyph_runs
.into_iter()
.map(|run| director.cast(PositionedShape::new(position.clone(), run)))
.collect();
let _positioned_shape = director.cast(PositionedShape::new(
position.clone(),
glyph_runs
.into_iter()
.map(|run| run.into())
.collect::<Vec<_>>(),
));

director.action()?;

Expand All @@ -303,7 +308,7 @@ async fn application(mut ctx: ApplicationContext) -> Result<()> {

// DI: This check has to be done in the renderer and the renderer has to decide when it
// needs to redraw.
let new_matrix = application.matrix();
let new_matrix = application.matrix(page_size);
if new_matrix != current_matrix {
matrix.update(new_matrix);
current_matrix = new_matrix;
Expand Down
21 changes: 21 additions & 0 deletions examples/logs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "logs"
version = "0.1.0"
edition = "2021"

[dev-dependencies]
termwiz = "0.22.0"

shared = { path = "../shared" }

massive-geometry = { workspace = true }
massive-shell = { workspace = true }
massive-scene = { workspace = true }
massive-shapes = { workspace = true }

anyhow = { workspace = true }
cosmic-text = { workspace = true }
log = { workspace = true }
winit = { workspace = true }
env_logger = { workspace = true }
tokio = { workspace = true }
Loading

0 comments on commit b0ce721

Please sign in to comment.