From 697b50a05784794e724e7a4acf7983efad4445cb Mon Sep 17 00:00:00 2001
From: Eugen Ciur <eugen@papermerge.com>
Date: Sat, 29 Jan 2022 09:07:35 +0100
Subject: [PATCH] adding ui_select element

---
 app/modifiers/ui_select.js | 31 ++++++++++++++++++++++++++++++-
 app/styles/app.scss        |  1 +
 app/styles/ui_select.scss  |  4 ++++
 3 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100644 app/styles/ui_select.scss

diff --git a/app/modifiers/ui_select.js b/app/modifiers/ui_select.js
index dd5e580..ecce28b 100644
--- a/app/modifiers/ui_select.js
+++ b/app/modifiers/ui_select.js
@@ -42,13 +42,42 @@ class UISelect {
   }
 
   update(x, y) {
-    console.log(`Updating ui selection ${x} ${y}`);
+    let height, width, top, left;
+
+    this.current_x = x;
+    this.current_y = y;
+
+    width = Math.abs(this.current_x - this.start_x);
+    height = Math.abs(this.current_y - this.start_y);
+
+    if (this.select_div) {
+
+      if (this.current_y <  this.start_y) {
+        this.select_div.top = `${this.current_y + 7}px`;
+        top = this.current_y + 7;
+      } else {
+        this.select_div.top = `${this.start_y}px`;
+        top = this.start_y;
+      }
+      if (this.current_x <  this.start_x) {
+        this.select_div.left = `${this.current_x + 7}px`;
+        left = this.current_x + 7;
+      } else {
+        this.select_div.left = `${this.start_x}px`;
+        left = this.start_x;
+      }
+      this.select_div.width = `${width}px`;
+      this.select_div.height = `${height}px`;
+      console.log(`select_div.width = ${width}`);
+      console.log(`select_div.height = ${height}`);
+    }
   }
 
   _create_selection_div(x, y) {
 
     let div = document.createElement('div');
 
+    div.setAttribute('id',  'ui-select');
     div.style.position = 'absolute';
     div.style.top = `${y}px`;
     div.style.left = `${x}px`;
diff --git a/app/styles/app.scss b/app/styles/app.scss
index f09accd..1f5db0c 100644
--- a/app/styles/app.scss
+++ b/app/styles/app.scss
@@ -8,6 +8,7 @@
 @import "./document_version.scss";
 @import "./search.scss";
 @import "./preferences.scss";
+@import "./ui_select.scss";
 
 
 body {
diff --git a/app/styles/ui_select.scss b/app/styles/ui_select.scss
new file mode 100644
index 0000000..3f95a13
--- /dev/null
+++ b/app/styles/ui_select.scss
@@ -0,0 +1,4 @@
+#ui-select {
+    background-color: #e6f5ff40;
+    border: 1px solid #e6f5ff;
+}
\ No newline at end of file
-- 
GitLab