Browse Source

support border and border-color uiml attributes

Kolja Strohm 8 months ago
parent
commit
4bfb0623d8
4 changed files with 185 additions and 57 deletions
  1. BIN
      Framework Tests/Framwork.dll
  2. 109 15
      UIMLView.cpp
  3. 62 25
      UIMLView.h
  4. 14 17
      XML.cpp

BIN
Framework Tests/Framwork.dll


+ 109 - 15
UIMLView.cpp

@@ -50,7 +50,36 @@ void UIMLElement::layout(XML::Element& element,
         }
     }
     z.setSize(width, height);
-    if (element.hasAttribute("align-left"))
+    if (element.hasAttribute("align-x"))
+    {
+        Text la = element.getAttributeValue("align-x");
+        int x = 0;
+        if (la.istGleich("start"))
+            x = 0;
+        else if (la.istGleich("end"))
+            x = pWidth;
+        else if (la.istGleich("center"))
+            x = pWidth / 2 - width / 2;
+        else
+        {
+            XML::Editor ed
+                = element.zParent()->selectChildsByAttribute("id", la);
+            generalLayouter.layout(*ed.begin().val(),
+                *generalLayouter.zZeichnungById(la),
+                pWidth,
+                pHeight,
+                generalLayouter);
+            Zeichnung* laz = generalLayouter.zZeichnungById(la);
+            if (laz) x = laz->getX();
+        }
+        if (element.hasAttribute("margin-x"))
+        {
+            Text mt = element.getAttributeValue("margin-x");
+            x += calculateSize(mt, pWidth);
+        }
+        z.setX(x);
+    }
+    else if (element.hasAttribute("align-left"))
     {
         Text la = element.getAttributeValue("align-left");
         int x = 0;
@@ -108,7 +137,36 @@ void UIMLElement::layout(XML::Element& element,
         }
         z.setX(x);
     }
-    if (element.hasAttribute("align-top"))
+    if (element.hasAttribute("align-y"))
+    {
+        Text ta = element.getAttributeValue("align-y");
+        int y = 0;
+        if (ta.istGleich("start"))
+            y = 0;
+        else if (ta.istGleich("end"))
+            y = pHeight;
+        else if (ta.istGleich("center"))
+            y = pHeight / 2 - height / 2;
+        else
+        {
+            XML::Editor ed
+                = element.zParent()->selectChildsByAttribute("id", ta);
+            generalLayouter.layout(*ed.begin().val(),
+                *generalLayouter.zZeichnungById(ta),
+                pWidth,
+                pHeight,
+                generalLayouter);
+            Zeichnung* taz = generalLayouter.zZeichnungById(ta);
+            if (taz) y = taz->getY();
+        }
+        if (element.hasAttribute("margin-y"))
+        {
+            Text mt = element.getAttributeValue("margin-y");
+            y += calculateSize(mt, pHeight);
+        }
+        z.setY(y);
+    }
+    else if (element.hasAttribute("align-top"))
     {
         Text ta = element.getAttributeValue("align-top");
         int y = 0;
@@ -179,9 +237,23 @@ void UIMLElement::layout(XML::Element& element,
         y = calculateSize(yt, pHeight);
     }
     z.setPosition(x, y);
+    ZeichnungHintergrund* zh = dynamic_cast<ZeichnungHintergrund*>(&z);
+    if (zh)
+    {
+        if (element.hasAttribute("border"))
+        {
+            int br = (int)element.getAttributeValue("border");
+            zh->setStyle(ZeichnungHintergrund::Style::Rahmen, br > 0);
+            zh->setRahmenBreite((int)element.getAttributeValue("border"));
+        }
+        if (element.hasAttribute("border-color"))
+        {
+            zh->setRahmenFarbe((int)element.getAttributeValue("border-color"));
+        }
+    }
+    // recursive layout
     pWidth = z.getInnenBreite();
     pHeight = z.getInnenHeight();
-    // recursive layout
     for (auto i = element.getChilds(); i; i++)
     {
         Zeichnung* z = 0;
@@ -832,7 +904,7 @@ bool Framework::UIMLFrame::updateElement(
     int index = 0;
     for (auto i = element.getChilds(); i; i++)
     {
-        Text id = element.getAttributeValue("id");
+        Text id = i->getAttributeValue("id");
         Zeichnung* z = generalFactory.zZeichnungById(id);
         if (!id.getLength() || !z || f->getMembers().indexOf(z) < 0
             || !generalFactory.updateElement(*i.val(), *z, generalFactory))
@@ -877,9 +949,29 @@ void UIMLFrame::layout(XML::Element& element,
         f->zTTextFeld()->setSchriftFarbe(
             (int)element.getAttributeValue("title-text-color"));
     }
+    if (element.hasAttribute("width"))
+    {
+        Text w = element.getAttributeValue("width");
+        if (w.istGleich("auto"))
+        {
+            z.setWidth(f->getNeededChildWidth());
+        }
+    }
+    if (element.hasAttribute("height"))
+    {
+        Text h = element.getAttributeValue("height");
+        if (h.istGleich("auto"))
+        {
+            z.setHeight(f->getNeededChildHeight());
+        }
+    }
     if (element.hasAttribute("display"))
     {
-        UIMLElement::layout(element, z, pWidth, pHeight, generalLayouter); // calculate all sizes
+        UIMLElement::layout(element,
+            z,
+            pWidth,
+            pHeight,
+            generalLayouter); // calculate all sizes
         if (element.getAttributeValue("display").istGleich("column"))
         {
             int gap = calculateSize(element.getAttributeValue("gap"), pHeight);
@@ -925,16 +1017,18 @@ void UIMLFrame::layout(XML::Element& element,
             }
         }
     }
-    UIMLElement::layout(element, z, pWidth, pHeight, generalLayouter); // calculate all remaining positions
-    if (element.hasAttribute("font-size"))
-        if (element.getAttributeValue("vScroll").istGleich("auto"))
-        {
-            f->setStyle(
-                Fenster::Style::VScroll,
-                f->getNeededChildHeight() > f->getInnenHeight());
-            f->setVSBScroll(10);
-            f->updateVScroll();
-        }
+    UIMLElement::layout(element,
+        z,
+        pWidth,
+        pHeight,
+        generalLayouter); // calculate all remaining positions
+    if (element.getAttributeValue("vScroll").istGleich("auto"))
+    {
+        f->setStyle(Fenster::Style::VScroll,
+            f->getNeededChildHeight() > f->getInnenHeight());
+        f->setVSBScroll(10);
+        f->updateVScroll();
+    }
     if (element.getAttributeValue("hScroll").istGleich("auto"))
     {
         f->setStyle(Fenster::Style::HScroll,

+ 62 - 25
UIMLView.h

@@ -48,8 +48,32 @@ namespace Framework
             values concatenated by the operators +, -, / or *
           + auto: attribute will be ignored here and may be handled by the
             subclasses
+        - (string) align-x: sets the x coordinate of the view. The value of
+          margin-x will be added
+          + start: 0
+          + end: parentWidth
+          + center: parentWidth / 2 - width / 2
+          + id of other element: other element x
+        - (string) margin-x: only available if align-x is specified.
+          + (int)%: specifies the distance to its x aligned coordinate in
+            percentage of parentWidth
+          + (int): specifies the distance to its x aligned coordinate in pixel
+          + (expression): calculates the distance from an expression that
+            contains values concatenated by the operators +, -, / or *
+        - (string) align-y: sets the y coordinate of the view. The value of
+          margin-y will be added
+          + start: 0
+          + end: parentWidth
+          + center: parentHeight / 2 - height / 2
+          + id of other element: other element y
+        - (string) margin-y: only available if align-y is specified.
+          + (int)%: specifies the distance to its y aligned coordinate in
+            percentage of parentHeight
+          + (int): specifies the distance to its y aligned coordinate in pixel
+          + (expression): calculates the distance from an expression that
+            contains values concatenated by the operators +, -, / or *
         - (string) align-left: sets the x coordinate of the view. The value of
-          margin-left will be added
+          margin-left will be added. Will be ignored when align-x is present.
           + start: 0
           + end: parentWidth
           + center: parentWidth / 2 - width / 2
@@ -59,10 +83,11 @@ namespace Framework
             percentage of parentWidth
           + (int): specifies the distance to its left aligned coordinate in
             pixel
-          + (expression): calculates the width from an expression that contains
+          + (expression): calculates the distance from an expression that
+            contains values concatenated by the operators +, -, / or *
         - (string) align-right: sets the x coordinate of the view. The value of
-          margin-right will be subtracted. Will be ignored when align-left is
-          present.
+          margin-right will be subtracted. Will be ignored when align-x or
+          align-left is present.
           + start: -width
           + end: parentWidth - width
           + center: parentWidth / 2 - width / 2
@@ -72,10 +97,10 @@ namespace Framework
             percentage of parentWidth
           + (int): specifies the distance to its right aligned coordinate in
             pixel
-          + (expression): calculates the width from an expression that contains
-            values concatenated by the operators +, -, / or *
+          + (expression): calculates the distance from an expression that
+            contains values concatenated by the operators +, -, / or *
         - (string) align-top: sets the y coordinate of the view. The value of
-          margin-top will be added
+          margin-top will be added. Will be ignored when align-y is present.
           + start: 0
           + end: parentHeight
           + center: parentHeight / 2 - height / 2
@@ -84,11 +109,11 @@ namespace Framework
           + (int)%: specifies the distance to its top aligned coordinate in
             percentage of parentHeight
           + (int): specifies the distance to its top aligned coordinate in pixel
-          + (expression): calculates the width from an expression that contains
-            values concatenated by the operators +, -, / or *
+          + (expression): calculates the distance from an expression that
+            contains values concatenated by the operators +, -, / or *
         - (string) align-bottom: sets the y coordinate of the view. The value of
-          margin-bottom will be subtracted. Will be ignored when align-top is
-          present.
+          margin-bottom will be subtracted. Will be ignored when align-y or
+          align-top is present.
           + start: -height
           + end: parentHeight - height
           + center: parentHeight / 2 - height / 2
@@ -98,19 +123,25 @@ namespace Framework
             percentage of parentHeight
           + (int): specifies the distance to its bottom aligned coordinate in
             pixel
-          + (expression): calculates the width from an expression that contains
-            values concatenated by the operators +, -, / or *
+          + (expression): calculates the distance from an expression that
+            contains values concatenated by the operators +, -, / or *
         - (string) x: sets the x coordinate of the view. overwrites align-left
-          and align-right
+          and align-right and align-x
           + (int)%: specifies the x coordinate in percentage of parentWidth
           + (int): specifies the x coordinate in pixel
-          + (expression): calculates the width from an expression that contains
+          + (expression): calculates the x coordinate from an expression that
+            contains values concatenated by the operators +, -, / or *
         - (string) y: sets the y coordinate of the view. overwrites align-top
-          and align-bottom
+          and align-bottom and align-y
           + (int)%: specifies the y coordinate in percentage of parentHeight
           + (int): specifies the y coordinate in pixel
-          + (expression): calculates the width from an expression that contains
+          + (expression): calculates the y from an expression that contains
             values concatenated by the operators +, -, / or *
+
+      additional attributes if the created view is an instance of
+      ZeichnungHintergrund:
+        - (int) border: width of the border in pixel
+        - (int) border-color: color of the border format: 0xAARRGGBB
     */
     class UIMLElement : public virtual ReferenceCounter
     {
@@ -176,8 +207,8 @@ namespace Framework
         - disabled: removes the style TextFeld::Style::Editierbar
         - (string) width: sets the with
           + auto: setzt the width to the calculated needed width
-        - (string) height: sets the with
-          + auto: setzt the width to the calculated needed width
+        - (string) height: sets the height
+          + auto: setzt the height to the calculated needed height
         - (string) vScroll: adds a vertical scroll bar
           + auto: the max vertical scroll size is set to the needed text height
             and the click scroll per pixel will be set to font size
@@ -252,8 +283,8 @@ namespace Framework
         - disabled: removes the style TextFeld::Style::Editierbar
         - (string) width: sets the with
           + auto: setzt the width to the calculated needed width
-        - (string) height: sets the with
-          + auto: setzt the width to the calculated needed width
+        - (string) height: sets the height
+          + auto: setzt the height to the calculated needed height
         - (string) vScroll: adds a vertical scroll bar
           + auto: the max vertical scroll size is set to the needed text height
             and the click scroll per pixel will be set to font size
@@ -294,8 +325,8 @@ namespace Framework
         - disabled: removes the style TextFeld::Style::Editierbar
         - (string) width: sets the with
           + auto: setzt the width to the calculated needed width
-        - (string) height: sets the with
-          + auto: setzt the width to the calculated needed width
+        - (string) height: sets the height
+          + auto: setzt the height to the calculated needed height
         - (string) vScroll: adds a vertical scroll bar
           + auto: the max vertical scroll size is set to the needed text height
             and the click scroll per pixel will be set to font size
@@ -360,9 +391,15 @@ namespace Framework
           + (expression): calculates the width from an expression that contains
             values concatenated by the operators +, -, / or *
         - (string) vScroll: adds a vertical scroll bar
-          + auto: the max vertical scroll size is set to the needed child elements height
+          + auto: the max vertical scroll size is set to the needed child
+      elements height
         - (int) hScroll: adds a hotizontal scroll bar
-          + auto: the max horizontal scroll size is set to the needed child elements width
+          + auto: the max horizontal scroll size is set to the needed child
+      elements width
+        - (string) width: sets the with
+          + auto: setzt the width to the calculated needed width
+        - (string) height: sets the height
+          + auto: setzt the height to the calculated needed height
     */
     class UIMLFrame : public UIMLElement
     {

+ 14 - 17
XML.cpp

@@ -516,24 +516,21 @@ Text Element::toString() const
          i++, j++)
     {
         ret += i->getText();
-        if (j->getLength())
+        if (j->hat('"'))
         {
-            if (j->hat('"'))
-            {
-                ret += "='";
-                Text txt = j->getText();
-                txt.ersetzen("'", "\\'");
-                ret += txt;
-                ret += "'";
-            }
-            else
-            {
-                ret += "=\"";
-                Text txt = j->getText();
-                txt.ersetzen("\"", "\\\"");
-                ret += txt;
-                ret += "\"";
-            }
+            ret += "='";
+            Text txt = j->getText();
+            txt.ersetzen("'", "\\'");
+            ret += txt;
+            ret += "'";
+        }
+        else
+        {
+            ret += "=\"";
+            Text txt = j->getText();
+            txt.ersetzen("\"", "\\\"");
+            ret += txt;
+            ret += "\"";
         }
         if (i.hasNext()) ret += " ";
     }