Skip to content

Commit e65f161

Browse files
author
gabriel
committed
implement views id
1 parent df531d1 commit e65f161

5 files changed

Lines changed: 42 additions & 4 deletions

File tree

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66

77
public class Activity extends Context {
88
Window mWindow;
9+
private boolean running;
910

10-
public void onCreate(){}
11-
public void onDestroy(){}
12-
public void onPause(){}
13-
public void onResume(){}
11+
public void onCreate(){ running = true; }
12+
public void onDestroy(){ running = false; }
13+
public void onPause(){ running = false; }
14+
public void onResume(){ running = true; }
15+
16+
protected boolean isRunning() {
17+
return running;
18+
}
1419

1520
public void finish() {
1621
mWindow.destroy();
@@ -23,6 +28,10 @@ public void switchActivity(Valuable<Activity> provider) {
2328
Application.boot(window, provider.get());
2429
}
2530

31+
public <T extends View> T findViewById(String id) {
32+
return mWindow.getContentView().findViewById(id);
33+
}
34+
2635
public void setContentView(String layoutName){
2736
setContentView(getLayoutInflater().inflate(layoutName));
2837
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class GlfwWindow extends Window {
2323
private boolean destroyed = true;
2424
private boolean visible;
2525
private boolean running = false;
26+
private final Point position = new Point();
2627
private WindowObserver observer;
2728

2829
public GlfwWindow() {
@@ -48,6 +49,8 @@ private void refresh() {
4849
int[][] buffer = new int[2][1];
4950
GLFW.glfwGetWindowSize(window, buffer[0], buffer[1]);
5051
windowSize.set(buffer[0][0], buffer[1][0]);;
52+
GLFW.glfwGetWindowPos(window, buffer[0], buffer[1]);
53+
position.set(buffer[0][0], buffer[1][0]);
5154
}
5255

5356
private int frames = 0;
@@ -158,6 +161,8 @@ public void setVisible(boolean visible) {
158161
} else {
159162
GLFW.glfwHideWindow(window);
160163
}
164+
165+
GLFW.glfwSetWindowPos(window, position.x, position.y);
161166
}
162167

163168
@Override

src/br/nullexcept/mux/view/AttrList.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package br.nullexcept.mux.view;
22

33
public class AttrList {
4+
public static final String id = "id";
45
public static final String textColor = "textColor";
56
public static final String text = "text";
67
public static final String textSize = "textSize";

src/br/nullexcept/mux/view/View.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public class View {
2929
private final int hashCode = hash();
3030
private final Rect rect = new Rect();
3131
private Object tag;
32+
private String id;
33+
3234
private Drawable background;
3335
private float alpha = 1.0f;
3436
private float scale = 1.0f;
@@ -66,6 +68,7 @@ public View(Context context, AttributeList attrs) {
6668
attrs.searchFloat(AttrList.alpha, this::setAlpha);
6769
attrs.searchDrawable(AttrList.background, this::setBackground);
6870
attrs.searchRaw(AttrList.pointerIcon, value -> setPointerIcon(new PointerIcon(PointerIcon.Model.fromName(value))));
71+
attrs.searchRaw(AttrList.id, value -> id = value);
6972
attrs.searchRaw(AttrList.gravity, value -> {
7073
String[] types = value.split("\\|");
7174
int gravity = 0;
@@ -305,6 +308,13 @@ public <T extends View> T findViewByTag(Object tag) {
305308
return null;
306309
}
307310

311+
public <T extends View> T findViewById(String id) {
312+
if (id != null && Objects.equals(id, this.id)) {
313+
return (T) this;
314+
}
315+
return null;
316+
}
317+
308318
protected void dispatchKeyEvent(KeyEvent event) {
309319
onKeyEvent(event);
310320
}

src/br/nullexcept/mux/view/ViewGroup.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,19 @@ public <T extends View> T findViewByTag(Object tag) {
220220
return self;
221221
}
222222

223+
@Override
224+
public <T extends View> T findViewById(String tag) {
225+
T self = super.findViewById(tag);
226+
if (self == null){
227+
for (View child: children){
228+
if ((self = child.findViewById(tag)) != null){
229+
return self;
230+
}
231+
}
232+
}
233+
return self;
234+
}
235+
223236
public static class LayoutParams {
224237
public static final int MATCH_PARENT = -1;
225238
public static final int WRAP_CONTENT = -2;

0 commit comments

Comments
 (0)