text editor
git clone https://git.lucas.co/cce-text-editor.git
Refactor and adapt widgets to use UiContext and scale factor
Cargo.lock | 26 +++++++++++++-------------
Cargo.toml | 2 +-
Makefile | 2 +-
src/main.rs | 32 +++++++++++++++++---------------
4 files changed, 32 insertions(+), 30 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 876b8de..3e0efa3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -155,19 +155,7 @@ dependencies = [
]
[[package]]
-name = "cfg-if"
-version = "1.0.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
-
-[[package]]
-name = "cfg_aliases"
-version = "0.2.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
-
-[[package]]
-name = "clear-text-editor"
+name = "cce-text-editor"
version = "0.1.0"
dependencies = [
"bytemuck",
@@ -186,6 +174,18 @@ dependencies = [
"xkeysym",
]
+[[package]]
+name = "cfg-if"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
+
+[[package]]
+name = "cfg_aliases"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
+
[[package]]
name = "clear-ui"
version = "0.1.0"
diff --git a/Cargo.toml b/Cargo.toml
index 6d45b50..0a0202d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,5 +1,5 @@
[package]
-name = "clear-text-editor"
+name = "cce-text-editor"
version = "0.1.0"
edition = "2021"
diff --git a/Makefile b/Makefile
index 92a7bff..aebfd8a 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ build:
install: build
mkdir -p ~/.local/bin
- install -m 755 target/release/clear-text-editor ~/.local/bin/clear-text-editor
+ install -m 755 target/release/cce-text-editor ~/.local/bin/cce-text-editor
run:
cargo run
diff --git a/src/main.rs b/src/main.rs
index 5957906..bdfc418 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -36,6 +36,7 @@ struct TextEditorApp {
text_items: Vec<TextItem>,
font_system: FontSystem,
needs_rebuild: bool,
+ ui_context: clear_ui::context::UiContext,
}
impl TextEditorApp {
@@ -123,7 +124,7 @@ impl TextEditorApp {
// 3. Editor text labels
let font_family = self.editor.font_family.clone();
- for (label, bounds) in self.editor.text_labels_with_bounds() {
+ for (label, bounds) in self.editor.text_labels_with_bounds(&self.ui_context) {
let metrics = Metrics::new(label.font_size, label.font_size * 1.4);
let mut buf = Buffer::new(&mut self.font_system, metrics);
let family_val = match font_family.as_str() {
@@ -223,13 +224,14 @@ impl Application for TextEditorApp {
text_items: Vec::new(),
font_system: FontSystem::new(),
needs_rebuild: true,
+ ui_context: clear_ui::context::UiContext::new(),
}
}
fn settings(&self) -> WindowSettings {
WindowSettings {
title: "Clear Text Editor".to_string(),
- app_id: "clear-text-editor".to_string(),
+ app_id: "cce-text-editor".to_string(),
width: 800,
height: 600,
fullscreen: false,
@@ -345,13 +347,13 @@ impl Application for TextEditorApp {
let px = pos.x as f32;
let py = pos.y as f32;
- if self.btn_new.on_cursor_moved(px, py) { changed = true; }
- if self.btn_open.on_cursor_moved(px, py) { changed = true; }
- if self.btn_save.on_cursor_moved(px, py) { changed = true; }
- if self.btn_save_as.on_cursor_moved(px, py) { changed = true; }
- if self.btn_exit.on_cursor_moved(px, py) { changed = true; }
+ if self.btn_new.on_cursor_moved(px, py, &mut self.ui_context) { changed = true; }
+ if self.btn_open.on_cursor_moved(px, py, &mut self.ui_context) { changed = true; }
+ if self.btn_save.on_cursor_moved(px, py, &mut self.ui_context) { changed = true; }
+ if self.btn_save_as.on_cursor_moved(px, py, &mut self.ui_context) { changed = true; }
+ if self.btn_exit.on_cursor_moved(px, py, &mut self.ui_context) { changed = true; }
- if self.editor.on_cursor_moved(px, py) { changed = true; }
+ if self.editor.on_cursor_moved(px, py, &mut self.ui_context) { changed = true; }
if changed {
*needs_rebuild = true;
@@ -365,38 +367,38 @@ impl Application for TextEditorApp {
let px = pos.x as f32;
let py = pos.y as f32;
- if self.btn_new.mouse_input(button, state, px, py) {
+ if self.btn_new.mouse_input(button, state, px, py, &mut self.ui_context) {
changed = true;
if state == ElementState::Released && self.btn_new.take_click() {
msg_out = Some(AppMessage::NewDocument);
}
}
- if self.btn_open.mouse_input(button, state, px, py) {
+ if self.btn_open.mouse_input(button, state, px, py, &mut self.ui_context) {
changed = true;
if state == ElementState::Released && self.btn_open.take_click() {
msg_out = Some(AppMessage::OpenDocument);
}
}
- if self.btn_save.mouse_input(button, state, px, py) {
+ if self.btn_save.mouse_input(button, state, px, py, &mut self.ui_context) {
changed = true;
if state == ElementState::Released && self.btn_save.take_click() {
msg_out = Some(AppMessage::SaveDocument);
}
}
- if self.btn_save_as.mouse_input(button, state, px, py) {
+ if self.btn_save_as.mouse_input(button, state, px, py, &mut self.ui_context) {
changed = true;
if state == ElementState::Released && self.btn_save_as.take_click() {
msg_out = Some(AppMessage::SaveDocumentAs);
}
}
- if self.btn_exit.mouse_input(button, state, px, py) {
+ if self.btn_exit.mouse_input(button, state, px, py, &mut self.ui_context) {
changed = true;
if state == ElementState::Released && self.btn_exit.take_click() {
msg_out = Some(AppMessage::Exit);
}
}
- if self.editor.mouse_input(button, state, px, py) {
+ if self.editor.mouse_input(button, state, px, py, &mut self.ui_context) {
changed = true;
} else if state == ElementState::Pressed && button == MouseButton::Left {
self.editor.unfocus();
@@ -443,7 +445,7 @@ impl Application for TextEditorApp {
}
if !handled {
- if self.editor.keyboard_input(event) {
+ if self.editor.keyboard_input(event, &mut self.ui_context) {
handled = true;
}
}