added some more options to the rectangle layout

This commit is contained in:
hneemann 2019-02-09 13:20:48 +01:00
parent d22eb92100
commit 67cea2db82
5 changed files with 44 additions and 4 deletions

View File

@ -717,4 +717,16 @@ public final class Keys {
= new Key.KeyInteger("RectHeight", 3) = new Key.KeyInteger("RectHeight", 3)
.setMin(2); .setMin(2);
/**
* the position of the text in the rectangle
*/
public static final Key<Boolean> RECT_INSIDE
= new Key<>("RectInside", false).setSecondary();
/**
* the position of the text in the rectangle
*/
public static final Key<Boolean> RECT_BOTTOM
= new Key<>("RectBottom", false).setSecondary();
} }

View File

@ -23,6 +23,9 @@ public class RectShape implements Shape, DecoratingShape {
private final String label; private final String label;
private final int width; private final int width;
private final int height; private final int height;
private final boolean inside;
private final boolean bottom;
private final Integer fontSize;
/** /**
* Create a new instance * Create a new instance
@ -42,6 +45,9 @@ public class RectShape implements Shape, DecoratingShape {
width = attr.get(Keys.RECT_WIDTH); width = attr.get(Keys.RECT_WIDTH);
height = attr.get(Keys.RECT_HEIGHT); height = attr.get(Keys.RECT_HEIGHT);
inside = attr.get(Keys.RECT_INSIDE);
bottom = attr.get(Keys.RECT_BOTTOM);
fontSize = attr.get(Keys.FONT_SIZE);
} }
@Override @Override
@ -56,10 +62,21 @@ public class RectShape implements Shape, DecoratingShape {
@Override @Override
public void drawTo(Graphic graphic, Style highLight) { public void drawTo(Graphic graphic, Style highLight) {
Vector pos = new Vector(0, -2);
Style style = Style.NORMAL; int ofs = -3;
Orientation orientation = Orientation.LEFTBOTTOM;
if (inside ^ bottom) {
ofs = -ofs;
orientation = Orientation.LEFTTOP;
}
Vector pos = new Vector(0, ofs);
if (bottom)
pos = pos.add(0, height * SIZE);
Style style = Style.NORMAL.deriveFontStyle(fontSize, true);
if (!label.isEmpty()) if (!label.isEmpty())
graphic.drawText(pos, pos.add(1, 0), label, Orientation.LEFTBOTTOM, style); graphic.drawText(pos, pos.add(1, 0), label, orientation, style);
graphic.drawPolygon(new Polygon(true) graphic.drawPolygon(new Polygon(true)
.add(0, 0) .add(0, 0)

View File

@ -41,7 +41,10 @@ public class DummyElement implements Element {
public static final ElementTypeDescription RECTDESCRIPTION = new ElementTypeDescription("Rectangle", DummyElement.class) public static final ElementTypeDescription RECTDESCRIPTION = new ElementTypeDescription("Rectangle", DummyElement.class)
.addAttribute(Keys.LABEL) .addAttribute(Keys.LABEL)
.addAttribute(Keys.RECT_WIDTH) .addAttribute(Keys.RECT_WIDTH)
.addAttribute(Keys.RECT_HEIGHT); .addAttribute(Keys.RECT_HEIGHT)
.addAttribute(Keys.RECT_INSIDE)
.addAttribute(Keys.RECT_BOTTOM)
.addAttribute(Keys.FONT_SIZE);
/** /**
* Creates a new dummy element * Creates a new dummy element

View File

@ -1254,6 +1254,10 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
<string name="key_RectWidth_tt">Breite in Rastereinheiten</string> <string name="key_RectWidth_tt">Breite in Rastereinheiten</string>
<string name="key_RectHeight">Höhe</string> <string name="key_RectHeight">Höhe</string>
<string name="key_RectHeight_tt">Höhe in Rastereinheiten</string> <string name="key_RectHeight_tt">Höhe in Rastereinheiten</string>
<string name="key_RectInside">Text innen</string>
<string name="key_RectInside_tt">Text ins Innere des Rechtecks setzen.</string>
<string name="key_RectBottom">Text unten</string>
<string name="key_RectBottom_tt">Text unten ans Rechteck setzen.</string>
<string name="key_wideShape">Breites Symbol</string> <string name="key_wideShape">Breites Symbol</string>
<string name="key_wideShape_tt">Verwendet ein breiteres Symbol zur Darstellung des Gatters.</string> <string name="key_wideShape_tt">Verwendet ein breiteres Symbol zur Darstellung des Gatters.</string>

View File

@ -1243,6 +1243,10 @@
<string name="key_RectWidth_tt">Width in grid units</string> <string name="key_RectWidth_tt">Width in grid units</string>
<string name="key_RectHeight">Height</string> <string name="key_RectHeight">Height</string>
<string name="key_RectHeight_tt">Height in grid units</string> <string name="key_RectHeight_tt">Height in grid units</string>
<string name="key_RectInside">Text Inside</string>
<string name="key_RectInside_tt">Place text inside the rectangle.</string>
<string name="key_RectBottom">Text at Bottom</string>
<string name="key_RectBottom_tt">Place text at the bottom of the rectangle.</string>
<string name="key_wideShape">Wide Shape</string> <string name="key_wideShape">Wide Shape</string>
<string name="key_wideShape_tt">Uses a wider shape to visualize the gate.</string> <string name="key_wideShape_tt">Uses a wider shape to visualize the gate.</string>