#320 Select up/down 4.x-dev

Sun, 06 Jun 2021 08:33:38 +0300

author
cemkalyoncu
date
Sun, 06 Jun 2021 08:33:38 +0300
branch
4.x-dev
changeset 1691
90a9dd9dc80e
parent 1690
43b08e17672d
child 1692
f666ff6c4671

#320 Select up/down

Source/Gorgon/Graphics/AdvancedPrinter.h file | annotate | diff | comparison | revisions
Source/Gorgon/String/AdvancedTextBuilder.h file | annotate | diff | comparison | revisions
Source/Gorgon/UI/ComponentStack.cpp file | annotate | diff | comparison | revisions
Source/Gorgon/Widgets/Label.cpp file | annotate | diff | comparison | revisions
Source/Gorgon/Widgets/Textarea.cpp file | annotate | diff | comparison | revisions
--- a/Source/Gorgon/Graphics/AdvancedPrinter.h	Sun May 30 00:34:31 2021 +0300
+++ b/Source/Gorgon/Graphics/AdvancedPrinter.h	Sun Jun 06 08:33:38 2021 +0300
@@ -28,7 +28,6 @@
     class AdvancedPrinter : public TextPrinter {
     public:
         
-
         class Region {
         public:
             Region() = default;
--- a/Source/Gorgon/String/AdvancedTextBuilder.h	Sun May 30 00:34:31 2021 +0300
+++ b/Source/Gorgon/String/AdvancedTextBuilder.h	Sun Jun 06 08:33:38 2021 +0300
@@ -534,7 +534,7 @@
             CSI(Graphics::internal::CSI_DISPLAY_IMAGE);
             Index(index);
             
-            int margintype = margins == Geometry::Margin{0} ? 0 : ((margins.Left == margins.Top == margins.Right == margins.Bottom) ? 1 : 2);
+            int margintype = margins == Geometry::Margin{0} ? 0 : ((margins.Left == margins.Top) && (margins.Right == margins.Bottom) && (margins.Top == margins.Bottom) ? 1 : 2);
             
             if(offset == Geometry::Point(0, 0)) {
                 Index(side | (margintype << 4)); //side and maybe margin
@@ -571,7 +571,7 @@
             CSI(Graphics::internal::CSI_DISPLAY_IMAGE);
             Index(index);
             
-            int margintype = margins == Geometry::Margin{0} ? 0 : ((margins.Left == margins.Top == margins.Right == margins.Bottom) ? 1 : 2);
+            int margintype = margins == Geometry::Margin{0} ? 0 : ((margins.Left == margins.Top) && (margins.Right == margins.Bottom) && (margins.Top == margins.Bottom) ? 1 : 2);
             
             if(offset == Geometry::Point(0, 0)) {
                 Index(side | 0b1000 | (margintype << 4)); //side, size and maybe margin
--- a/Source/Gorgon/UI/ComponentStack.cpp	Sun May 30 00:34:31 2021 +0300
+++ b/Source/Gorgon/UI/ComponentStack.cpp	Sun Jun 06 08:33:38 2021 +0300
@@ -1326,7 +1326,7 @@
 
     Geometry::Bounds ComponentStack::BoundsOf(int ind) {
         //component does not exist
-        if(stacksizes[ind] == 0)
+        if(ind == -1 || stacksizes[ind] == 0)
             return {0, 0, 0, 0};
         
         //update needed?
@@ -1347,6 +1347,10 @@
             
             //get the parent
             cur = &get(cur->parent);
+            
+            if(auto lyr = storage.at(&cur->GetTemplate())->layer) {
+                off += lyr->GetLocation();
+            }
 
             //accumulate the parent offset
             off += cur->location;
--- a/Source/Gorgon/Widgets/Label.cpp	Sun May 30 00:34:31 2021 +0300
+++ b/Source/Gorgon/Widgets/Label.cpp	Sun Jun 06 08:33:38 2021 +0300
@@ -110,6 +110,7 @@
         stack.SetClickEvent([this](auto, auto point, auto btn) {
             if(btn == Input::Mouse::Button::Left) {
                 auto &regions = stack.GetRegions();
+                point -= stack.BoundsOf(stack.IndexOfTag(UI::ComponentTemplate::ContentsTag)).TopLeft();
                 
                 for(auto &r : regions) {
                     if(IsInside(r.Bounds, point)) {
--- a/Source/Gorgon/Widgets/Textarea.cpp	Sun May 30 00:34:31 2021 +0300
+++ b/Source/Gorgon/Widgets/Textarea.cpp	Sun Jun 06 08:33:38 2021 +0300
@@ -130,6 +130,26 @@
 
                     updateselection();
                 }
+                else if(key == Input::Keyboard::Keycodes::Up) {
+                    glyphbyte selprev = selstart;
+                    sellen = {0, 0};
+                    
+                    moveselup();
+                    sellen = {selstart.glyph - selprev.glyph, selstart.byte - selprev.byte};
+                    selstart = selprev;
+
+                    updateselection();
+                }
+                else if(key == Input::Keyboard::Keycodes::Down) {
+                    glyphbyte selprev = selstart;
+                    sellen = {0, 0};
+                    
+                    moveseldown();
+                    sellen = {selstart.glyph - selprev.glyph, selstart.byte - selprev.byte};
+                    selstart = selprev;
+
+                    updateselection();
+                }
             }
             else if(Input::Keyboard::CurrentModifier == Modifier::None) {
 
@@ -390,7 +410,7 @@
         
         checkprinter();
         
-        auto bounds = stack.TagBounds(UI::ComponentTemplate::ContentsTag);
+        auto bounds = stack.BoundsOf(stack.IndexOfTag(UI::ComponentTemplate::ContentsTag));
         
         location -= bounds.TopLeft();
         
@@ -414,7 +434,7 @@
         
         checkprinter();
         
-        auto bounds = stack.TagBounds(UI::ComponentTemplate::ContentsTag);
+        auto bounds = stack.BoundsOf(stack.IndexOfTag(UI::ComponentTemplate::ContentsTag));
         
         location -= bounds.TopLeft();
         
@@ -439,7 +459,6 @@
         }
     }
 
-
     void Textarea::set(const std::string &value) {
         text = value;
         glyphcount = String::UnicodeGlyphCount(text);
@@ -465,7 +484,6 @@
         }
     }
 
-
     void Textarea::moveselleft() {
         if(selstart.glyph > 0) {
             selstart.glyph--;
@@ -477,7 +495,6 @@
         }
     }
 
-
     void Textarea::moveselright() {
         if(selstart.glyph < glyphcount) {
             selstart.glyph++;
@@ -488,7 +505,7 @@
     void Textarea::moveselup() {
         auto bounds = stack.TagBounds(UI::ComponentTemplate::ContentsTag);
         selstart.glyph = printer->GetCharacterIndex(
-            text, bounds.GetSize().Width, {cursorlocation.X, cursorlocation.Y+1-printer->GetHeight()}, true
+            text, bounds.GetSize().Width, Geometry::Point{cursorlocation.X, cursorlocation.Y-1} + ScrollOffset(), true
         );
         selstart.byte = getbyteoffset(selstart.glyph);
         sellen = {0, 0};
@@ -498,7 +515,7 @@
     void Textarea::moveseldown() {
         auto bounds = stack.TagBounds(UI::ComponentTemplate::ContentsTag);
         selstart.glyph = printer->GetCharacterIndex(
-            text, bounds.GetSize().Width, {cursorlocation.X, cursorlocation.Y+1+printer->GetHeight()}, true
+            text, bounds.GetSize().Width, Geometry::Point{cursorlocation.X, cursorlocation.Y+1+printer->GetHeight()} + ScrollOffset(), true
         );
         selstart.byte = getbyteoffset(selstart.glyph);
         sellen = {0, 0};

mercurial