| 1 |
import harmonia.ui.application; |
|---|
| 2 |
import harmonia.ui.window; |
|---|
| 3 |
import harmonia.ui.widget; |
|---|
| 4 |
import harmonia.ui.events; |
|---|
| 5 |
import harmonia.ui.controls.editbox; |
|---|
| 6 |
import harmonia.ui.controls.scrollbar; |
|---|
| 7 |
import harmonia.ui.controls.listbox; |
|---|
| 8 |
import harmonia.ui.controls.buttons; |
|---|
| 9 |
import harmonia.ui.containers.splitter; |
|---|
| 10 |
import harmonia.ui.containers.tabs; |
|---|
| 11 |
import harmonia.html.view; |
|---|
| 12 |
import harmonia.gx.images; |
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
//| |
|---|
| 16 |
//| static module ctor |
|---|
| 17 |
//| |
|---|
| 18 |
//| Harmonia way to setup GUI application |
|---|
| 19 |
//| |
|---|
| 20 |
|
|---|
| 21 |
static this() |
|---|
| 22 |
{ |
|---|
| 23 |
Application.onStart = |
|---|
| 24 |
// Runtime started. Statics were intitalized. |
|---|
| 25 |
// Voulez-vous dancer? |
|---|
| 26 |
function void() |
|---|
| 27 |
{ |
|---|
| 28 |
// create MainWindow here |
|---|
| 29 |
(new MyWindow()).state = Window.STATE.SHOWN; |
|---|
| 30 |
}; |
|---|
| 31 |
|
|---|
| 32 |
Application.onStop = |
|---|
| 33 |
// All windows closed so do graceful quit. |
|---|
| 34 |
function void() |
|---|
| 35 |
{ |
|---|
| 36 |
// close files, etc. |
|---|
| 37 |
}; |
|---|
| 38 |
} |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
class MyWindow: Window |
|---|
| 42 |
{ |
|---|
| 43 |
Image im; |
|---|
| 44 |
HtmlPanel hp; |
|---|
| 45 |
|
|---|
| 46 |
Splitter splitter; |
|---|
| 47 |
Tabs tabs; |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
this() |
|---|
| 51 |
{ |
|---|
| 52 |
this ~= (splitter = new Splitter(true)); |
|---|
| 53 |
|
|---|
| 54 |
// listbox below |
|---|
| 55 |
ListBox lb = new ListBox(); |
|---|
| 56 |
splitter ~= lb; |
|---|
| 57 |
lb.place = rect(10,40,80,140); |
|---|
| 58 |
|
|---|
| 59 |
// fill it by items |
|---|
| 60 |
static string[] items = |
|---|
| 61 |
[ |
|---|
| 62 |
"One", |
|---|
| 63 |
"Two", |
|---|
| 64 |
"Three", |
|---|
| 65 |
"Four", |
|---|
| 66 |
"Five", |
|---|
| 67 |
"Six Six Six Six Six Six Six Six", |
|---|
| 68 |
"Seven", |
|---|
| 69 |
"Eight", |
|---|
| 70 |
]; |
|---|
| 71 |
lb.addItems( items ); |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
tabs = new Tabs; |
|---|
| 75 |
splitter ~= tabs; |
|---|
| 76 |
|
|---|
| 77 |
// HTML panel |
|---|
| 78 |
hp = new HtmlView(); |
|---|
| 79 |
hp.name = "HTML Test"; |
|---|
| 80 |
tabs ~= hp; |
|---|
| 81 |
|
|---|
| 82 |
hp.load |
|---|
| 83 |
("<HTML back-color='edit dialog' padding=8px> |
|---|
| 84 |
<H1 padding=3px>H1:This is <I>HTML text</I> loaded into <B>HTMLView</B> - scrollable HTML container.</H1> |
|---|
| 85 |
<P>Inline image:<IMG src='test.png'/> and <CODE> code example; </CODE></P> |
|---|
| 86 |
<P height=100% padding=10pt border-width=3px border-style='solid none none none' border-color=dialog-shadow > |
|---|
| 87 |
This paragraph declared as <CODE><P height=100%></CODE>. This means that it will take 100% of height left from other elements. |
|---|
| 88 |
This is a major difference from standard HTML - percents here are <I>percents from free space</I>. |
|---|
| 89 |
<BR/>Notice 3 pixel bar at the left side - it is left border of the paragraph. Such percents are used instead of flex'es in XUL.</P> |
|---|
| 90 |
<TABLE cellspacing=10px cellpadding=10px padding=10px border-width=1px border-style=solid border-color=dialog-shadow > |
|---|
| 91 |
<TR> |
|---|
| 92 |
<TD width=30% height=100%>Inline editbox: <INPUT type=text value='hello world' width=100px /> |
|---|
| 93 |
and button:<INPUT type=button value='button' width=60px /> |
|---|
| 94 |
and combobox: |
|---|
| 95 |
<INPUT type=select width=60px> |
|---|
| 96 |
<OPTION>One</OPTION> |
|---|
| 97 |
<OPTION>Two</OPTION> |
|---|
| 98 |
<OPTION>Three</OPTION> |
|---|
| 99 |
<OPTION>Four</OPTION> |
|---|
| 100 |
<OPTION>Five</OPTION> |
|---|
| 101 |
<OPTION>Six Six Six Six Six Six Six Six</OPTION> |
|---|
| 102 |
<OPTION>Seven</OPTION> |
|---|
| 103 |
<OPTION>Eight</OPTION> |
|---|
| 104 |
<OPTION>Nine</OPTION> |
|---|
| 105 |
<OPTION>Ten</OPTION> |
|---|
| 106 |
</INPUT> |
|---|
| 107 |
</TD> |
|---|
| 108 |
<TD>two</TD> |
|---|
| 109 |
<TD width=40 back-color='dialog-light scrollbar' border='1px solid dialog-shadow'>1</TD> |
|---|
| 110 |
</TR> |
|---|
| 111 |
<TR> |
|---|
| 112 |
<TD border='1px solid dialog-shadow' text-align=right>right aligned cell with border</TD> |
|---|
| 113 |
<TD>four</TD> |
|---|
| 114 |
<TD back-color='dialog-light scrollbar' border='1px solid dialog-shadow'>2</TD> |
|---|
| 115 |
</TR> |
|---|
| 116 |
<TR> |
|---|
| 117 |
<TD colspan=2 back-color='dialog-light dialog-shadow'>colspan=2, table cells with gradient backgrounds</TD> |
|---|
| 118 |
<TD back-color='dialog-light dialog-light scrollbar dialog-shadow'>3</TD> |
|---|
| 119 |
</TR> |
|---|
| 120 |
</TABLE> |
|---|
| 121 |
<P>Hyperlink test: <A href='http://terrainformatica.com'>Terra Informatica</A></P> |
|---|
| 122 |
</HTML>"); |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
for(int i = 1; i < 10; ++i) |
|---|
| 126 |
{ |
|---|
| 127 |
HtmlPanel w = new HtmlPanel(); |
|---|
| 128 |
w.name = toUTF16(format("Test #%d", i)); |
|---|
| 129 |
tabs ~= w; |
|---|
| 130 |
w.load(format("<HTML back-color=edit border='1px solid dialog-shadow' padding=8px>Test #<B>%d</B></HTML>", i)); |
|---|
| 131 |
} |
|---|
| 132 |
|
|---|
| 133 |
im = Image.load("pngtest.png"); |
|---|
| 134 |
|
|---|
| 135 |
} |
|---|
| 136 |
|
|---|
| 137 |
override void drawContent(Graphics g) |
|---|
| 138 |
{ |
|---|
| 139 |
super.drawContent(g); |
|---|
| 140 |
if(im !== null) |
|---|
| 141 |
{ |
|---|
| 142 |
// draw the Bird - PNG with alpha |
|---|
| 143 |
auto Graphics ig = new Graphics(im); |
|---|
| 144 |
rect src = rect(im.dimension); |
|---|
| 145 |
point dst = place.pointOf(1); // top right corner, see NUM keypad why 1 |
|---|
| 146 |
dst.y -= im.dimension.y; |
|---|
| 147 |
g.copyRect(dst,src,ig); |
|---|
| 148 |
} |
|---|
| 149 |
} |
|---|
| 150 |
|
|---|
| 151 |
override void doLayout() |
|---|
| 152 |
{ |
|---|
| 153 |
rect r = clientPlace; |
|---|
| 154 |
r.origin.y += 20; |
|---|
| 155 |
r.corner.y -= 20; |
|---|
| 156 |
splitter.place = r; |
|---|
| 157 |
} |
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
} |
|---|