mirror of https://github.com/buggins/dlangui.git
CanvasWidget, with example
This commit is contained in:
parent
ca58769a91
commit
0c2b25d558
|
@ -840,6 +840,19 @@ void main()
|
|||
|
||||
tabs.addTab((new SampleAnimationWidget("tab6")).layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT), "TAB_ANIMATION"c);
|
||||
|
||||
CanvasWidget canvas = new CanvasWidget("canvas");
|
||||
canvas.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
||||
canvas.onDrawListener = delegate(CanvasWidget canvas, DrawBuf buf, Rect rc) {
|
||||
int x = rc.left;
|
||||
int y = rc.top;
|
||||
buf.fillRect(Rect(x+20, y+20, x+150, y+200), 0x80FF80);
|
||||
buf.fillRect(Rect(x+90, y+80, x+250, y+250), 0x80FF80FF);
|
||||
canvas.font.drawText(buf, x + 40, y + 50, "fillRect()"d, 0xC080C0);
|
||||
canvas.font.drawText(buf, x + 300, y + 100, "drawPixel()"d, 0x000080);
|
||||
for (int i = 0; i < 80; i++)
|
||||
buf.drawPixel(x+300 + i * 4, y+140 + i * 3 % 100, 0xFF0000 + i * 2);
|
||||
};
|
||||
tabs.addTab(canvas, "TAB_CANVAS"c);
|
||||
|
||||
//==========================================================================
|
||||
|
||||
|
|
|
@ -32,4 +32,5 @@ TAB_BUTTONS=Buttons
|
|||
TAB_ANIMATION=Animation
|
||||
TAB_TABLE_LAYOUT=Table layout
|
||||
TAB_EDITORS=Editors
|
||||
TAB_CANVAS=Canvas
|
||||
|
||||
|
|
|
@ -994,3 +994,38 @@ class ScrollBar : AbstractSlider, OnClickHandler {
|
|||
}
|
||||
}
|
||||
|
||||
/// interface - slot for onClick
|
||||
interface OnDrawHandler {
|
||||
void doDraw(CanvasWidget canvas, DrawBuf buf, Rect rc);
|
||||
}
|
||||
|
||||
/// canvas widget - draw on it either by overriding of doDraw() or by assigning of onDrawListener
|
||||
class CanvasWidget : Widget {
|
||||
|
||||
Listener!OnDrawHandler onDrawListener;
|
||||
|
||||
this(string ID = null) {
|
||||
super(ID);
|
||||
}
|
||||
|
||||
override void measure(int parentWidth, int parentHeight) {
|
||||
measuredContent(parentWidth, parentHeight, 0, 0);
|
||||
}
|
||||
|
||||
void doDraw(DrawBuf buf, Rect rc) {
|
||||
if (onDrawListener.assigned)
|
||||
onDrawListener(this, buf, rc);
|
||||
}
|
||||
|
||||
override void onDraw(DrawBuf buf) {
|
||||
if (visibility != Visibility.Visible)
|
||||
return;
|
||||
super.onDraw(buf);
|
||||
Rect rc = _pos;
|
||||
applyMargins(rc);
|
||||
auto saver = ClipRectSaver(buf, rc, alpha);
|
||||
applyPadding(rc);
|
||||
doDraw(buf, rc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue