Skip to content

Commit

Permalink
Merge pull request #29 from Mathis-Hu/main
Browse files Browse the repository at this point in the history
Add alignment properties for buttons & fix label align compare to LED
  • Loading branch information
kasemir authored Jul 17, 2023
2 parents c734a3a + 787f9a1 commit 7134cb1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/main/java/dbwr/widgets/ActionButtonWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,35 @@ else if ("write_pv".equalsIgnoreCase(action_type))
getRuleSupport().handleColorRule(parent, xml, this,
"background_color", background_color,
"set_action_button_background_color");

handleTextAlignment(this, xml);
}

@Override
protected String getHTMLElement()
{
return "button";
}

static void handleTextAlignment(final Widget widget, final Element xml) throws Exception
{
widget.classes.add("AlignedText");
int align = XMLUtil.getChildInteger(xml, "horizontal_alignment").orElse(1);
if (align == 0)
widget.classes.add("AlignedHorizLeft");
else if (align == 1)
widget.classes.add("AlignedHorizCenter");
else if (align == 2)
widget.classes.add("AlignedRight");

align = XMLUtil.getChildInteger(xml, "vertical_alignment").orElse(1);
if (align == 0)
widget.classes.add("AlignedVertTop");
else if (align == 1)
widget.classes.add("AlignedVertCenter");
else if (align == 2)
widget.classes.add("AlignedBottom");
}

@Override
protected void fillHTML(final PrintWriter html, final int indent)
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/dbwr/widgets/BoolButtonWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public BoolButtonWidget(final ParentWidget parent, final Element xml) throws Exc
attributes.put("data-bit", Integer.toString(XMLUtil.getChildInteger(xml, "bit").orElse(-1)));

XMLUtil.getColor(xml, "foreground_color").ifPresent(color -> styles.put("color", color));

ActionButtonWidget.handleTextAlignment(this, xml);
}

@Override
Expand All @@ -72,13 +74,15 @@ protected void fillHTML(final PrintWriter html, final int indent)
int size = Math.min(width, height);
final int r = (int) (size/3.7);
size = r+r;

html.append("<svg class=\"LED\" style=\"width: " + size + "px; height: " + size + "px;\">");
html.append("<div class=\"AlignedText AlignedVertCenter\" style=\"height: " +size + "px;\">");
html.append("<svg class=\"LED\" style=\"width: " + size + "px; height: " + size + "px; padding-right: 5px;\">");
html.append("<ellipse cx=\"" + r + "\" cy=\"" + r + "\" rx=\"" + r + "\" ry=\"" + r + "\" fill=\"grey\"></ellipse>");
html.append("</svg>");
}
html.append("<span>");
html.append(" The Label");
html.append("</span>");
if(show_led)
html.append("</div>");
}
}

0 comments on commit 7134cb1

Please sign in to comment.