From 79505790aa1f39761a71e8e5e30b8432f4237292 Mon Sep 17 00:00:00 2001
From: StaffEngineer <111751109+StaffEngineer@users.noreply.github.com>
Date: Tue, 26 Sep 2023 13:37:41 +0100
Subject: [PATCH] Add text position Left (#56)

---
 examples/restricted_input.rs |  5 +++--
 src/lib.rs                   | 13 ++++++++++---
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/examples/restricted_input.rs b/examples/restricted_input.rs
index a5b8bd8..65b93fc 100644
--- a/examples/restricted_input.rs
+++ b/examples/restricted_input.rs
@@ -25,12 +25,13 @@ fn setup(mut commands: Commands, windows: Query<&Window, With<PrimaryWindow>>) {
                 line_height: 16.,
                 scale_factor: primary_window.scale_factor() as f32,
             },
-            max_chars: CosmicMaxChars(15),
+            max_chars: CosmicMaxChars(23),
             max_lines: CosmicMaxLines(1),
             text: CosmicText::OneStyle(
-                "1 line 15 chars! But this\n is longer\n than is\n allowed by\n the limits.\n"
+                "1 line 25 chars! But this a b c d e f g\n is longer\n than is\n allowed by\n the limits.\n"
                     .into(),
             ),
+            text_position: CosmicTextPosition::Left { padding: 20 },
             ..default()
         })
         .id();
diff --git a/src/lib.rs b/src/lib.rs
index 1bacfb6..a1b1d43 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -36,7 +36,12 @@ impl Default for CosmicText {
 pub enum CosmicTextPosition {
     #[default]
     Center,
-    TopLeft,
+    TopLeft {
+        padding: i32,
+    },
+    Left {
+        padding: i32,
+    },
 }
 
 #[derive(Event, Debug)]
@@ -1014,7 +1019,8 @@ fn cosmic_edit_bevy_events(
                     get_x_offset(editor.0.buffer()),
                     get_y_offset(editor.0.buffer()),
                 ),
-                CosmicTextPosition::TopLeft => (0, 0),
+                CosmicTextPosition::TopLeft { padding } => (*padding, *padding),
+                CosmicTextPosition::Left { padding } => (*padding, get_y_offset(editor.0.buffer())),
             };
             let point = |node_cursor_pos: (f32, f32)| {
                 (
@@ -1209,7 +1215,8 @@ fn redraw_buffer_common(
             CosmicTextPosition::Center => {
                 (get_y_offset(editor.buffer()), get_x_offset(editor.buffer()))
             }
-            CosmicTextPosition::TopLeft => (0, 0),
+            CosmicTextPosition::TopLeft { padding } => (*padding, *padding),
+            CosmicTextPosition::Left { padding } => (get_y_offset(editor.buffer()), *padding),
         };
 
         editor.draw(
-- 
GitLab