Skip to content

Commit

Permalink
Use blueprints for TextInput
Browse files Browse the repository at this point in the history
  • Loading branch information
RealKC committed Feb 15, 2023
1 parent a191c3a commit c52e776
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 163 deletions.
46 changes: 41 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
use std::{env, process::Command};

fn main() {
// See: https://docs.rs/diesel_migrations/2.0.0-rc.1/diesel_migrations/macro.embed_migrations.html#automatic-rebuilds
println!("cargo:rerun-if-changed=migrations/");

glib_build_tools::compile_resources(
&["resources"],
"resources/resources.gresource.xml",
"compiled.gresource",
);
if std::option_env!("KCSHOT_LINTING").is_none() {
let blueprint_dir = env::var("OUT_DIR").unwrap() + "/resources";
compile_blueprints(&["src/editor/textdialog.blp"], &blueprint_dir);
glib_build_tools::compile_resources(
&[blueprint_dir.as_str(), "resources"],
"resources/resources.gresource.xml",
"compiled.gresource",
);
} else {
println!("cargo:rustc-cfg=kcshot_linting");
}
}

fn compile_blueprints(blueprints: &[&str], target: &str) {
let blueprint_compiler = std::env::var("BLUEPRINT_COMPILER_PATH")
.unwrap_or_else(|_| "blueprint-compiler".to_owned());

let mut blueprint_compiler = Command::new(blueprint_compiler);
blueprint_compiler
.arg("batch-compile")
.arg(target)
.arg("src/");

for blueprint in blueprints {
println!("cargo:rerun-if-changed={blueprint}");
blueprint_compiler.arg(blueprint);
}

let output = blueprint_compiler
.output()
.expect("Failed to execute blueprint-compiler");

if !output.status.success() {
panic!(
"blueprint-compiler returned {}, with stderr:\n{}",
output.status,
std::str::from_utf8(&output.stderr).unwrap()
);
}
}
3 changes: 3 additions & 0 deletions resources/resources.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
<file>editor/tool-text.png</file>
<file>editor/tool-pencil.png</file>
<file>editor/tool-colourpicker.png</file>

<!-- UI files generated from blueprints in build.rs -->
<file preprocess="xml-stripblanks" alias="ui/textdialog.ui">editor/textdialog.ui</file>
</gresource>
</gresources>
77 changes: 77 additions & 0 deletions src/editor/textdialog.blp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using Gtk 4.0;

template KCShotTextInput : Gtk.Box {
orientation: vertical;
spacing: 2;

// Button area
Gtk.Box {
orientation: horizontal;
spacing: 4;
margin-start: 10;
margin-end: 10;

Gtk.FontButton font_button {
margin-bottom: 5;
}

Gtk.Button colour_button {
margin-bottom: 5;
width-request: 25;
height-request: 25;

clicked => on_colour_button_clicked() swapped;

child: Gtk.DrawingArea colour_button_drawing_area {
accessible-role: img;
width-request: 25;
height-request: 25;
};
}
}

// Text input area
Gtk.Box {
orientation: horizontal;
spacing: 2;

Gtk.Box {
orientation: vertical;
spacing: 2;

Gtk.Label { label: "Input"; }
Gtk.TextView input_view {
margin-top: 7;
margin-start: 10;
margin-bottom: 5;
width-request: 250;
height-request: 250;
wrap-mode: word;

buffer: Gtk.TextBuffer {
changed => on_input_textbuffer_changed() swapped;
};
}
}

Gtk.Box {
orientation: vertical;
spacing: 2;

Gtk.Label { label: "Preview"; }
Gtk.TextView preview {
margin-top: 7;
margin-end: 10;
margin-bottom: 5;
width-request: 250;
height-request: 250;
wrap-mode: word;
}
}
}

Gtk.Label {
label: "You can use CommonMark Markdown or <a href=\"https://docs.gtk.org/Pango/pango_markup.html\" title=\"Pango markup\">Pango markup</a> to format your text.";
use-markup: true;
}
}
Loading

0 comments on commit c52e776

Please sign in to comment.