Skip to content

Commit 38a73a8

Browse files
Change window icon and more doc
1 parent 520b4bb commit 38a73a8

13 files changed

Lines changed: 166 additions & 51 deletions

File tree

MasterUI.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<sourceFolder url="file://$MODULE_DIR$/assets" type="java-resource" relativeOutputPath="assets" />
88
<sourceFolder url="file://$MODULE_DIR$/res" type="java-resource" relativeOutputPath="res" />
99
<excludeFolder url="file://$MODULE_DIR$/.idea" />
10+
<excludeFolder url="file://$MODULE_DIR$/docs" />
1011
<excludeFolder url="file://$MODULE_DIR$/lib" />
1112
<excludeFolder url="file://$MODULE_DIR$/out" />
1213
</content>

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
Java library for make a beautiful UI, code design is based in android ui.
66
That project uses OpenGLES 2.0 for render, so that is compatible with many actual devices.
77

8+
>**[Use Guide](docs/HELLO_WORLD.md)**
9+
810
# Usage example
911

1012
```java
@@ -22,12 +24,6 @@ public class Example extends Activity {
2224
view.setBackground(new ColorDrawable(Color.RED));
2325
setContentView(view);
2426
}
25-
26-
@Override
27-
public void onDestroy() {
28-
super.onDestroy();
29-
Application.stop();
30-
}
3127
}
3228
```
3329

@@ -59,7 +55,7 @@ public class Example extends Activity {
5955

6056
### Interface
6157

62-
- 🟨 XML UI
58+
- 🟩 XML UI
6359
- 🟨 Themes
6460
- 🟨 Multi window
6561
- 🟨 Menus

build.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
<exclude name="**/.git/**"/>
2626
<exclude name="**/.hg/**"/>
2727
<exclude name="**/.svn/**"/>
28+
<exclude name="**/docs/**"/>
29+
<exclude name="**/out/**"/>
2830
<exclude name="**/CVS/**"/>
2931
<exclude name="**/__pycache__/**"/>
3032
<exclude name="**/_svn/**"/>

docs/HELLO_WORLD.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Bootstrap
2+
3+
Import .jar with library and natives. \
4+
Create folder structure on your project:
5+
> assets/\
6+
> res/
7+
8+
**assets**: Folder for save all assets from your project.\
9+
**res:** Folder for save all resources a like texts, layouts, icons, themes, etc.
10+
11+
**IMPORTANT:** Ouput folders need follow that structure too.
12+
13+
# Create a Hello World
14+
15+
You can create a hello world:
16+
17+
```java
18+
19+
public class Example extends Activity {
20+
public static void main(String[] args) {
21+
Application.initialize(Example::new);
22+
}
23+
24+
@Override
25+
public void onCreate() {
26+
super.onCreate();
27+
View view = new View(this);
28+
setTitle("Hello world!");
29+
view.setBackground(new ColorDrawable(Color.RED));
30+
setContentView(view);
31+
}
32+
}
33+
```
34+
35+
# Create a UI with XML.
36+
37+
For create complex UIs you can use XMLs, first you need create your layout file a like `res/layout/example.xml`, that is a example of a simple Hello world layout:
38+
39+
```xml
40+
<?xml version="1.0" encoding="UTF-8" ?>
41+
<LinearLayout
42+
width="match_parent"
43+
height="match_parent"
44+
background="?colorSurface"
45+
orientation="horizontal">
46+
<TextView
47+
width="match_parent"
48+
height="match_parent"
49+
text="Hello world"/>
50+
</LinearLayout>
51+
```
52+
53+
For import that layout, you can use ``setContentView(layoutId)`` in your activity.
54+
55+
```java
56+
57+
@Override
58+
public void onCreate() {
59+
super.onCreate();
60+
setContentView("example");
61+
}
62+
63+
```
64+
65+
### Change widgets from a xml layout.
66+
67+
For access and edit nodes created from xml layout, you can use method: ``findViewById('NODE_ID')``, and set tag id in your node.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<material-icon
3+
name="settings"
4+
color="#00BBB9"/>

res/layout/main.xml

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,8 @@
44
height="match_parent"
55
background="?colorSurface"
66
orientation="horizontal">
7-
8-
<ScrollView
9-
width="300dp"
10-
height="match_parent"
11-
background="?colorSurface">
12-
<include layout="example_list"/>
13-
</ScrollView>
14-
15-
<LinearLayout
16-
width="match_parent"
17-
height="match_parent"
18-
padding="20dp">
19-
20-
<Button
21-
width="match_parent"
22-
height="wrap_content"
23-
text="Example Button"/>
24-
<View width="10dp" height="10dp"/>
25-
<EditText
26-
width="256dp"
27-
height="wrap_content"
28-
textColor="#FFF"
29-
padding="20dp"/>
30-
<View width="10dp" height="10dp"/>
31-
<ImageView
32-
id="panda"
33-
width="200dp"
34-
height="200dp"
35-
background="?colorPrimary"
36-
rotation="45"
37-
alpha="0.2"
38-
src="@drawable/panda"/>
39-
<View width="10dp" height="10dp"/>
40-
<Switch/>
41-
</LinearLayout>
7+
<TextView
8+
width="match_parent"
9+
height="match_parent"
10+
text="Hello world"/>
4211
</LinearLayout>

res/style/defaults.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
<item name="background">@drawable/textarea_background</item>
3131
</style>
3232

33+
<style name="Widget.Window">
34+
<item name="icon">@drawable/default_window_icon</item>
35+
<item name="title">MasterUi - Project</item>
36+
</style>
37+
3338
<style name="Widget.Button">
3439
<item name="background">@drawable/button_background</item>
3540
<item name="gravity">center</item>

src/br/nullexcept/mux/app/Activity.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
package br.nullexcept.mux.app;
22

33
import br.nullexcept.mux.lang.Valuable;
4+
import br.nullexcept.mux.res.AttributeList;
5+
import br.nullexcept.mux.view.AttrList;
46
import br.nullexcept.mux.view.View;
57
import br.nullexcept.mux.view.Window;
68

79
public class Activity extends Context {
810
Window mWindow;
911
private boolean running;
1012

11-
public void onCreate(){ running = true; }
13+
public void onCreate(){
14+
running = true;
15+
AttributeList attrs = getResources().obtainStyled("Widget.Window");
16+
attrs.searchText("title", (text)-> mWindow.setTitle(""+text));
17+
attrs.searchDrawable("icon", (icon) -> mWindow.setIcon(icon));
18+
}
1219
public void onDestroy(){ running = false; }
1320
public void onPause(){ running = false; }
1421
public void onResume(){ running = true; }

src/br/nullexcept/mux/app/Looper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ public void loop(){
4747
try {
4848
runnable.run();
4949
} catch (Throwable e) {
50-
Log.error(LOG_TAG, "[ERROR ON LOOPER]");
51-
Log.error(LOG_TAG, e);
50+
Log.error(LOG_TAG, "[ERROR ON LOOPER]",e);
5251
stop = true;
5352
}
5453
}

src/br/nullexcept/mux/core/texel/GlfwWindow.java

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import br.nullexcept.mux.C;
44
import br.nullexcept.mux.app.Looper;
5-
import br.nullexcept.mux.graphics.Point;
5+
import br.nullexcept.mux.graphics.*;
66
import br.nullexcept.mux.graphics.fonts.Typeface;
77
import br.nullexcept.mux.hardware.GLES;
88
import br.nullexcept.mux.input.CharEvent;
@@ -12,10 +12,15 @@
1212
import br.nullexcept.mux.view.View;
1313
import br.nullexcept.mux.view.ViewGroup;
1414
import br.nullexcept.mux.view.Window;
15+
import org.lwjgl.BufferUtils;
1516
import org.lwjgl.glfw.GLFW;
17+
import org.lwjgl.glfw.GLFWImage;
1618
import org.lwjgl.nanovg.NVGColor;
1719
import org.lwjgl.nanovg.NanoVG;
1820
import org.lwjgl.opengles.GLES20;
21+
import org.lwjgl.system.MemoryUtil;
22+
23+
import java.nio.ByteBuffer;
1924

2025
import static org.lwjgl.glfw.GLFW.glfwSwapInterval;
2126

@@ -34,6 +39,8 @@ class GlfwWindow extends Window {
3439
public GlfwWindow() {
3540
window = GLFW.glfwCreateWindow(512, 512, "[title]", 0, C.GLFW_CONTEXT);
3641
eventManager = new GlfwEventManager(this);
42+
43+
GLFW.glfwIconifyWindow(window);
3744
GLFW.glfwSetWindowSizeLimits(window, 128,128, Integer.MAX_VALUE, Integer.MAX_VALUE);
3845
}
3946

@@ -270,6 +277,54 @@ public void destroy() {
270277
observer = null;
271278
}
272279

280+
@Override
281+
public void setIcon(Drawable icon) {
282+
int iconSize = 128;
283+
284+
icon.setBounds(new Rect(0,0,iconSize,iconSize));
285+
286+
CanvasTexel canvas = new CanvasTexel(iconSize, iconSize);
287+
canvas.begin();
288+
icon.draw(canvas);
289+
canvas.end();
290+
ByteBuffer buffer = BufferUtils.createByteBuffer((iconSize*iconSize)*4);
291+
292+
canvas.getFramebuffer().bind();
293+
GLES.glReadPixels(0,0, iconSize,iconSize, GLES20.GL_RGBA,GLES20.GL_UNSIGNED_BYTE,buffer);
294+
canvas.getFramebuffer().unbind();
295+
canvas.dispose();
296+
297+
new Thread(()->{
298+
buffer.rewind();
299+
ByteBuffer flipY = BufferUtils.createByteBuffer(buffer.capacity());
300+
flipY.position(0);
301+
byte[] row = new byte[iconSize*4];
302+
for (int i = 0; i < iconSize; i++) {
303+
buffer.position(
304+
(buffer.capacity()) - (row.length * (i+1))
305+
);
306+
buffer.get(row);
307+
flipY.position(row.length*i);
308+
flipY.put(row);
309+
}
310+
311+
MemoryUtil.memFree(buffer);
312+
flipY.flip();
313+
314+
if (!destroyed) {
315+
GLFWImage img = GLFWImage.create();
316+
img.width(canvas.getWidth());
317+
img.height(canvas.getHeight());
318+
img.pixels(flipY);
319+
320+
GLFWImage.Buffer bff = GLFWImage.malloc(1);
321+
bff.put(0, img);
322+
323+
GLFW.glfwSetWindowIcon(window, bff);
324+
}
325+
}).start();
326+
}
327+
273328
public void onMouseMoved(MotionEvent event) {
274329
container.performInputEvent(event);
275330
View child = container.getChildAt((int)event.getX(), (int)event.getY());

0 commit comments

Comments
 (0)