mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
put more things in the model
This commit is contained in:
parent
0556e61ca2
commit
103cccd61b
7 changed files with 81 additions and 60 deletions
|
@ -15,5 +15,5 @@ If you encounter an error like `gfx_backend_vulkan ... Failed to detect any vali
|
||||||
We thank the following open source projects in particular for inspiring us when designing the Roc editor:
|
We thank the following open source projects in particular for inspiring us when designing the Roc editor:
|
||||||
- [learn-wgpu](https://github.com/sotrh/learn-wgpu)
|
- [learn-wgpu](https://github.com/sotrh/learn-wgpu)
|
||||||
- [rgx](https://github.com/cloudhead/rgx)
|
- [rgx](https://github.com/cloudhead/rgx)
|
||||||
- [Elm](https://github.com/elm/compiler)
|
|
||||||
- [elm-editor](https://github.com/jxxcarlson/elm-editor)
|
- [elm-editor](https://github.com/jxxcarlson/elm-editor)
|
||||||
|
- [iced](https://github.com/hecrj/iced)
|
|
@ -51,9 +51,15 @@ These are potentially inspirational resources for the editor's design.
|
||||||
* [Blueprints](https://docs.unrealengine.com/en-US/Engine/Blueprints/index.html) visual scripting (not suggesting visual scripting for Roc)
|
* [Blueprints](https://docs.unrealengine.com/en-US/Engine/Blueprints/index.html) visual scripting (not suggesting visual scripting for Roc)
|
||||||
|
|
||||||
* [Live Programing](https://www.microsoft.com/en-us/research/project/live-programming/?from=http%3A%2F%2Fresearch.microsoft.com%2Fen-us%2Fprojects%2Fliveprogramming%2Ftypography.aspx#!publications) by [Microsoft Research] it contains many interesting research papers.
|
* [Live Programing](https://www.microsoft.com/en-us/research/project/live-programming/?from=http%3A%2F%2Fresearch.microsoft.com%2Fen-us%2Fprojects%2Fliveprogramming%2Ftypography.aspx#!publications) by [Microsoft Research] it contains many interesting research papers.
|
||||||
|
|
||||||
|
### Productivity features
|
||||||
|
|
||||||
* When refactoring;
|
* When refactoring;
|
||||||
- cutting and pasting code to a new file should automatically add imports to the new file and delete them from the old file.
|
- cutting and pasting code to a new file should automatically add imports to the new file and delete them from the old file.
|
||||||
- When renaming a function for example, references in comments should be brought to the user's attention.
|
- When renaming a function for example, references in comments should be brought to the user's attention.
|
||||||
|
* Automatically create all "arms" when pattern matching after entering `when var is` based on the type.
|
||||||
|
- All `when ... is` should be updated if the type is changed, e.g. adding Indigo to the Color type should add an arm everywhere where `when color is` is used.
|
||||||
|
|
||||||
|
|
||||||
### Non-Code Related Inspiration
|
### Non-Code Related Inspiration
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ use crate::rect::{Rect};
|
||||||
use crate::error::{print_err};
|
use crate::error::{print_err};
|
||||||
use crate::ortho::{init_ortho, update_ortho_buffer, OrthoResources};
|
use crate::ortho::{init_ortho, update_ortho_buffer, OrthoResources};
|
||||||
use crate::selection::{create_selection_rects};
|
use crate::selection::{create_selection_rects};
|
||||||
use crate::model::{RawSelection, Position};
|
use crate::tea::model;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
@ -42,7 +42,7 @@ mod colors;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
mod vec_result;
|
mod vec_result;
|
||||||
mod selection;
|
mod selection;
|
||||||
mod model;
|
mod tea;
|
||||||
|
|
||||||
/// The editor is actually launched from the CLI if you pass it zero arguments,
|
/// The editor is actually launched from the CLI if you pass it zero arguments,
|
||||||
/// or if you provide it 1 or more files or directories to open on launch.
|
/// or if you provide it 1 or more files or directories to open on launch.
|
||||||
|
@ -116,7 +116,7 @@ fn run_event_loop() -> Result<(), Box<dyn Error>> {
|
||||||
let mut glyph_brush = build_glyph_brush(&gpu_device, render_format)?;
|
let mut glyph_brush = build_glyph_brush(&gpu_device, render_format)?;
|
||||||
|
|
||||||
let is_animating = true;
|
let is_animating = true;
|
||||||
let mut text_state = "aaaaaaaaa\nbbbbbbbbbb\ncccccccccc\ndddddddddd\neeeeeee\nffffffff\ngggggggg".to_owned();//String::new();
|
let mut ed_model = model::init_model();
|
||||||
let mut keyboard_modifiers = ModifiersState::empty();
|
let mut keyboard_modifiers = ModifiersState::empty();
|
||||||
|
|
||||||
// Render loop
|
// Render loop
|
||||||
|
@ -169,7 +169,7 @@ fn run_event_loop() -> Result<(), Box<dyn Error>> {
|
||||||
event: event::WindowEvent::ReceivedCharacter(ch),
|
event: event::WindowEvent::ReceivedCharacter(ch),
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
update_text_state(&mut text_state, &ch);
|
update_text_state(&mut ed_model, &ch);
|
||||||
}
|
}
|
||||||
//Keyboard Input
|
//Keyboard Input
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
|
@ -206,44 +206,41 @@ fn run_event_loop() -> Result<(), Box<dyn Error>> {
|
||||||
|
|
||||||
let glyph_bounds_rects = queue_all_text(
|
let glyph_bounds_rects = queue_all_text(
|
||||||
&size,
|
&size,
|
||||||
&text_state,
|
&ed_model.file_text,
|
||||||
&mut glyph_brush,
|
&mut glyph_brush,
|
||||||
);
|
);
|
||||||
|
|
||||||
let selection =
|
if let Some(selection) = ed_model.selection_opt {
|
||||||
RawSelection {
|
let selection_rects_res = create_selection_rects(selection, &glyph_bounds_rects);
|
||||||
start_pos: Position {line: 1, column: 3},
|
|
||||||
end_pos: Position {line: 4, column: 2}
|
|
||||||
};
|
|
||||||
let selection_rects_res = create_selection_rects(selection, &glyph_bounds_rects);
|
|
||||||
|
|
||||||
match selection_rects_res {
|
match selection_rects_res {
|
||||||
Ok(selection_rects) =>
|
Ok(selection_rects) =>
|
||||||
if !selection_rects.is_empty() {
|
if !selection_rects.is_empty() {
|
||||||
let rect_buffers = create_rect_buffers(
|
let rect_buffers = create_rect_buffers(
|
||||||
&gpu_device,
|
&gpu_device,
|
||||||
&mut encoder,
|
&mut encoder,
|
||||||
&selection_rects,
|
&selection_rects,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||||
attachment: &frame.view,
|
attachment: &frame.view,
|
||||||
resolve_target: None,
|
resolve_target: None,
|
||||||
ops: wgpu::Operations::default(),
|
ops: wgpu::Operations::default(),
|
||||||
}],
|
}],
|
||||||
depth_stencil_attachment: None,
|
depth_stencil_attachment: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
render_pass.set_pipeline(&rect_pipeline);
|
render_pass.set_pipeline(&rect_pipeline);
|
||||||
render_pass.set_bind_group(0, &ortho.bind_group, &[]);
|
render_pass.set_bind_group(0, &ortho.bind_group, &[]);
|
||||||
render_pass.set_vertex_buffer(0, rect_buffers.vertex_buffer.slice(..));
|
render_pass.set_vertex_buffer(0, rect_buffers.vertex_buffer.slice(..));
|
||||||
render_pass.set_index_buffer(rect_buffers.index_buffer.slice(..));
|
render_pass.set_index_buffer(rect_buffers.index_buffer.slice(..));
|
||||||
render_pass.draw_indexed(0..rect_buffers.num_rects, 0, 0..1);
|
render_pass.draw_indexed(0..rect_buffers.num_rects, 0, 0..1);
|
||||||
|
|
||||||
drop(render_pass);
|
drop(render_pass);
|
||||||
},
|
},
|
||||||
Err(e) => print_err(&e) //TODO draw error text on screen
|
Err(e) => print_err(&e) //TODO draw error text on screen
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw all text
|
// draw all text
|
||||||
|
@ -373,19 +370,19 @@ fn queue_all_text(
|
||||||
text::queue_text_draw(&code_text, glyph_brush)
|
text::queue_text_draw(&code_text, glyph_brush)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_text_state(text_state: &mut String, received_char: &char) {
|
fn update_text_state(ed_model: &mut model::Model, received_char: &char) {
|
||||||
match received_char {
|
match received_char {
|
||||||
'\u{8}' | '\u{7f}' => {
|
'\u{8}' | '\u{7f}' => {
|
||||||
// In Linux, we get a '\u{8}' when you press backspace,
|
// In Linux, we get a '\u{8}' when you press backspace,
|
||||||
// but in macOS we get '\u{7f}'.
|
// but in macOS we get '\u{7f}'.
|
||||||
text_state.pop();
|
ed_model.file_text.pop();
|
||||||
}
|
}
|
||||||
'\u{e000}'..='\u{f8ff}' | '\u{f0000}'..='\u{ffffd}' | '\u{100000}'..='\u{10fffd}' => {
|
'\u{e000}'..='\u{f8ff}' | '\u{f0000}'..='\u{ffffd}' | '\u{100000}'..='\u{10fffd}' => {
|
||||||
// These are private use characters; ignore them.
|
// These are private use characters; ignore them.
|
||||||
// See http://www.unicode.org/faq/private_use.html
|
// See http://www.unicode.org/faq/private_use.html
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
text_state.push(*received_char);
|
ed_model.file_text.push(*received_char);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
|
|
||||||
pub struct Model {
|
|
||||||
caret_pos: Position,
|
|
||||||
selection: RawSelection
|
|
||||||
}
|
|
||||||
|
|
||||||
//Is model.rs the right place for these structs?
|
|
||||||
pub struct Position {
|
|
||||||
pub line: usize,
|
|
||||||
pub column: usize
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct RawSelection {
|
|
||||||
pub start_pos: Position,
|
|
||||||
pub end_pos: Position
|
|
||||||
}
|
|
|
@ -3,7 +3,7 @@ use crate::rect::{Rect};
|
||||||
use crate::vec_result::{get_res};
|
use crate::vec_result::{get_res};
|
||||||
use crate::error::{EdResult, InvalidSelection};
|
use crate::error::{EdResult, InvalidSelection};
|
||||||
use crate::colors;
|
use crate::colors;
|
||||||
use crate::model::{RawSelection};
|
use crate::tea::model::{RawSelection};
|
||||||
use snafu::ensure;
|
use snafu::ensure;
|
||||||
|
|
||||||
//using the "parse don't validate" pattern
|
//using the "parse don't validate" pattern
|
||||||
|
|
2
editor/src/tea/mod.rs
Normal file
2
editor/src/tea/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
pub mod model;
|
32
editor/src/tea/model.rs
Normal file
32
editor/src/tea/model.rs
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Model {
|
||||||
|
pub file_text: String,
|
||||||
|
pub caret_pos: Position,
|
||||||
|
pub selection_opt: Option<RawSelection>
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_model() -> Model {
|
||||||
|
Model {
|
||||||
|
file_text:
|
||||||
|
String::new(),
|
||||||
|
caret_pos:
|
||||||
|
Position {
|
||||||
|
line: 0, column: 0
|
||||||
|
},
|
||||||
|
selection_opt:
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Is model.rs the right place for these structs?
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct Position {
|
||||||
|
pub line: usize,
|
||||||
|
pub column: usize
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct RawSelection {
|
||||||
|
pub start_pos: Position,
|
||||||
|
pub end_pos: Position
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue