Skip to content

Commit

Permalink
Code improvements and release improvisations (#18)
Browse files Browse the repository at this point in the history
* Initial develop commit

* SVG Preview is rendered as PNG (#1)

* Initial save of png file

* Cleanup render warnings

* Add file dialog for save file

* Fixes

* adapt svg_result

* add logging

* Eliminate compile errors.
Update Readme

* Add tests

* Add Github Actions

* Save a sized png

* Fix compiler warnings

* small fixes

* more modular png module

* refactor main view

* img based preview

* Use prelude

* scaling of image and editor view

* empty svg will not produce a png error.

* add tabview

* try view size in button

* Refactoring the preview

* add width to parsing

* png preview

* move buttons to dedicated module

* small corrections

* Better approach

* fixing update behaviour of editor

* cleanup

* editor displays full size if no preview is around

* No more crashes when try to render errors

* correct display of error in preview

* add save button

* Activate Dependabot on develop

* Correct typo in README.MD

* Gh cicd setup (#6)

* Setup github actions

* Release Workflow

* Cargo fmt

* Cargo Clippy Fixes

* fix fmt

* Fix mainview (#7)

* Fullsize svg preview container

* Fix compiler messages

* Fix tag extraction to stop after first version match (#9)

* provide write access to tag job (#11)

* Optimise pipeline (#13)

* Optimise execution of unit tests

* fix release action

* Fix branch for release (#15)

* Mainview refactor (#17)

* refactoring subviews in own modules

* fmt & clippy

* update package version in toml

* optimise release build
  • Loading branch information
ict-cloud authored Feb 2, 2025
1 parent 80057ad commit 57196a2
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 47 deletions.
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "PikchrMirror"
version = "0.1.0"
version = "0.1.1"
edition = "2021"

[dependencies]
Expand All @@ -16,3 +16,9 @@ version = "0.44.*"
git = "https://github.com/lapce/floem"
# rev = "b9bcd24"
features = ["editor", "default-image-formats", "rfd-async-std"]

[profile.release]
opt-level = "s" # or "z"
codegen-units = 1
lto = "thin" #alternatives "fat" or "false"
strip = "debuginfo"
41 changes: 41 additions & 0 deletions src/view/edview.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use editor::command::{Command, CommandExecuted};
use editor::core::command::EditCommand;
use editor::text::{default_dark_color, SimpleStyling};
use floem::prelude::*;

pub const DFLT_TEXT: &str = r#"arrow right 200% "Markdown" "Source"
box rad 10px "Markdown" "Formatter" "(markdown.c)" fit
arrow right 200% "HTML+SVG" "Output"
arrow <-> down 70% from last box.s
box same "Pikchr" "Formatter" "(pikchr.c)" fit
"#;

pub fn textedit_view(i_editorstring: &RwSignal<String>) -> TextEditor {
let hide_gutter_a = RwSignal::new(false);
let rawdocstr = *i_editorstring;

let editor = text_editor(DFLT_TEXT)
.styling(SimpleStyling::new())
.style(|s| s.flex_col().size_full())
.editor_style(default_dark_color)
.editor_style(move |s| s.hide_gutter(hide_gutter_a.get()))
.pre_command(|ev| {
if matches!(ev.cmd, Command::Edit(EditCommand::Undo)) {
println!("Undo command executed on editor B, ignoring!");
return CommandExecuted::Yes;
}
CommandExecuted::No
})
.update(move |dlta| {
let txt = dlta.deltas().last().unwrap();
log::debug!("Editor changed \n new delta: {:?}", txt);
let rawdoc = if txt.new_document_len() == 0 {
String::from("")
} else {
String::from(dlta.editor.unwrap().text().clone())
};
rawdocstr.set(rawdoc);
})
.placeholder("Some placeholder text");
editor
}
49 changes: 4 additions & 45 deletions src/view/mainview.rs
Original file line number Diff line number Diff line change
@@ -1,63 +1,22 @@
use crate::view::tabview;
use editor::command::{Command, CommandExecuted};
use editor::core::command::EditCommand;
use editor::text::{default_dark_color, SimpleStyling};
use crate::view::{edview, svgview, tabview};
use floem::keyboard::{Key, NamedKey};
use floem::prelude::*;

const DFLT_TEXT: &str = r#"arrow right 200% "Markdown" "Source"
box rad 10px "Markdown" "Formatter" "(markdown.c)" fit
arrow right 200% "HTML+SVG" "Output"
arrow <-> down 70% from last box.s
box same "Pikchr" "Formatter" "(pikchr.c)" fit
"#;

pub fn app_view() -> impl IntoView {
let rawdocstr = create_rw_signal(DFLT_TEXT.to_string());
let rawdocstr = create_rw_signal(edview::DFLT_TEXT.to_string());

let p: Vec<u8> = Vec::new();

let pikpreview = create_rw_signal(p);

let hide_gutter_a = RwSignal::new(false);
let editor = edview::textedit_view(&rawdocstr);

let editor = text_editor(DFLT_TEXT)
.styling(SimpleStyling::new())
.style(|s| s.flex_col().size_full())
.editor_style(default_dark_color)
.editor_style(move |s| s.hide_gutter(hide_gutter_a.get()))
.pre_command(|ev| {
if matches!(ev.cmd, Command::Edit(EditCommand::Undo)) {
println!("Undo command executed on editor B, ignoring!");
return CommandExecuted::Yes;
}
CommandExecuted::No
})
.update(move |dlta| {
let txt = dlta.deltas().last().unwrap();
log::debug!("Editor changed \n new delta: {:?}", txt);
let rawdoc = if txt.new_document_len() == 0 {
String::from("")
} else {
String::from(dlta.editor.unwrap().text().clone())
};
rawdocstr.set(rawdoc);
})
.placeholder("Some placeholder text");
let doc = editor.doc();

// preview png should be rendered behind the button and stored in a rw_signal
// the save version should then be rendered dedicated with another size

let svg_preview = dyn_container(
move || pikpreview.get(),
move |pv| {
let pv_ref = pv.clone();
img(move || pv_ref.to_vec())
}, // scaling needs to be dynamic to adapt the dyn_container
)
.scroll()
.style(|s| s.flex_col().size_full());
let svg_preview = svgview::svgpreview_container(&pikpreview);

// doc needs to be dynamic to handover to the function otherwise it will not react on changes.
let ref_doc = &doc.clone();
Expand Down
2 changes: 2 additions & 0 deletions src/view/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pub mod edview;
pub mod mainview;
pub mod svgview;
pub mod tabview;
11 changes: 11 additions & 0 deletions src/view/svgview.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use floem::prelude::*;

pub fn svgpreview_container(i_preview_sig: &RwSignal<Vec<u8>>) -> Scroll {
let preview_sig = *i_preview_sig;
dyn_container(
move || preview_sig.get(),
move |pv| img(move || pv.to_vec()),
)
.scroll()
.style(|s| s.flex_col().size_full())
}
2 changes: 1 addition & 1 deletion src/view/tabview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn tabbar_container(
i_rawstr: &RwSignal<String>,
i_pngpreview: &RwSignal<Vec<u8>>,
i_preview_id: ViewId,
) -> impl IntoView {
) -> Container {
let render = render_button(i_rawstr, i_pngpreview, i_preview_id);
let clear = clear_button(i_doc);
let save = save_button(*i_rawstr);
Expand Down

0 comments on commit 57196a2

Please sign in to comment.