Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved separation of style and content/state/layout, and various other #141

Merged
merged 3 commits into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,7 @@ private void setStyle() {
String colorBackground = (String) theme.get("background");
String colorTransparent = "#00FFFFFF";

rootStyle.put("x", rootStyle, 0f);
rootStyle.put("y", rootStyle, 0f);
rootStyle.put("w", rootStyle, 0.2f);
rootStyle.put("h", rootStyle, 0.2f);

rootStyle.put("enabled", rootStyle, true);
rootStyle.put("opacity", rootStyle, 1.0f);
rootStyle.put("visibility", rootStyle, "visible");

rootStyle.put("background", rootStyle, colorPrimaryShade);
rootStyle.put("backgroundHover", rootStyle, "#88000000");
Expand Down Expand Up @@ -554,15 +547,13 @@ public Bitmap takeViewScreenshot(View v) {
return AndroidUtils.takeScreenshotView(v);
}

public View getViewById(String id) {
public View getViewById(int id) {
ArrayList<View> views = ((PViewsArea) (viewTree.get(0))).viewArray;

for (View v : views) {
PViewMethodsInterface vmi = (PViewMethodsInterface) v;
String viewId = (String) vmi.getProps().get("id");
if (id.equals(viewId)) {
if (vmi.id() == id) {
return v;
} else {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import androidx.fragment.app.FragmentTransaction;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import io.phonk.runner.apidoc.annotation.PhonkClass;
Expand Down Expand Up @@ -161,20 +160,6 @@ public PAbsoluteLayout newAbsoluteLayout() {
return pAbsoluteLayout;
}

public View addView(PViewMethodsInterface v) {
Map props = v.getProps();
// String type = props.get("type").toString();
Object x = props.get("x");
Object y = props.get("y");
Object w = props.get("w");
Object h = props.get("h");

// PViewMethodsInterface btn = (PViewMethodsInterface) newView(type, props);
this.addView((View) v, x, y, w, h);

return (View) v;
}

/**
* Adds a view created with new (newButton, newSlider, newText, etc) to the layout
*
Expand Down Expand Up @@ -285,11 +270,8 @@ public void background(String c) {
*/
@PhonkMethod
public PButton addButton(String label, Object x, Object y, Object w, Object h) {
Map<String, String> map = new HashMap<>();
map.put("text", label);

PButton b = (PButton) newView("button", map);
// b.text(label);
PButton b = (PButton) newView("button");
b.text(label);
addView(b, x, y, w, h);
return b;
}
Expand Down Expand Up @@ -449,15 +431,15 @@ public PText addText(Object x, Object y, Object w, Object h) {
@PhonkMethod
public PText addText(String text, Object x, Object y) {
PText tv = (PText) newView("text");
tv.setText(text);
tv.text(text);
addView(tv, x, y, -1, -1);
return tv;
}

@PhonkMethod
public PText addText(String label, Object x, Object y, Object w, Object h) {
PText tv = (PText) newView("text");
tv.setText(label);
tv.text(label);
addView(tv, x, y, w, h);
return tv;
}
Expand Down Expand Up @@ -509,23 +491,22 @@ public PToggle addToggle(Object x, Object y, Object w, Object h) {
*/
@PhonkMethod
public PToggle addToggle(final String[] text, Object x, Object y, Object w, Object h) {
HashMap<String, String> map = new HashMap();
PToggle t = (PToggle) newView("toggle");

if (text.length == 1) {
map.put("text", text[0]);
map.put("textOn", text[0]);
map.put("textOff", text[0]);
t.text(text[0]);
t.textOn(text[0]);
t.textOff(text[0]);
} else if (text.length == 2) {
map.put("text", text[0]);
map.put("textOn", text[1]);
map.put("textOff", text[0]);
t.text(text[0]);
t.textOn(text[1]);
t.textOff(text[0]);
} else if (text.length == 3) {
map.put("text", text[0]);
map.put("textOn", text[1]);
map.put("textOff", text[2]);
t.text(text[0]);
t.textOn(text[1]);
t.textOff(text[2]);
}

PToggle t = (PToggle) newView("toggle", map);
addView(t, x, y, w, h);

return t;
Expand Down Expand Up @@ -583,9 +564,9 @@ public PSlider addSlider(Object x, Object y, Object w, Object h) {
*/
@PhonkMethod
public PKnob addKnob(Object x, Object y, Object w, Object h) {
PKnob slider = (PKnob) newView("knob");
addView(slider, x, y, w, h);
return slider;
PKnob knob = (PKnob) newView("knob");
addView(knob, x, y, w, h);
return knob;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,6 @@ public void backgroundColor(String c) {
@PhonkMethod(description = "Adds a view", example = "")
@PhonkMethodParam(params = {"view", "x", "y", "w", "h"})
public void addView(View v, Object x, Object y, Object w, Object h) {
if (v instanceof PViewMethodsInterface) {
StylePropertiesProxy map = (StylePropertiesProxy) ((PViewMethodsInterface) v).getProps();
map.eventOnChange = false;
map.put("x", x);
map.put("y", y);
map.put("w", w);
map.put("h", h);
map.eventOnChange = true;
}

int mx = mAppRunner.pUtil.sizeToPixels(x, mWidth);
int my = mAppRunner.pUtil.sizeToPixels(y, mHeight);
int mw = mAppRunner.pUtil.sizeToPixels(w, mWidth);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,25 @@ public class PButton extends androidx.appcompat.widget.AppCompatButton implement
public final StylePropertiesProxy props = new StylePropertiesProxy();

// the props are transformed / accessed using the styler object
public final ButtonStyler styler;
public final Styler styler;

private Typeface mFont;
private int mStyle;

private ReturnInterface onPressCallback;
private ReturnInterface onReleaseCallback;

public PButton(AppRunner appRunner, Map initProps) {
super(appRunner.getAppContext());

styler = new ButtonStyler(appRunner, this, props);
styler = new Styler(appRunner, this, props);
props.eventOnChange = false;
props.put("textStyle", props, "bold");
props.put("textAlign", props, "center");
// props.put("srcTintPressed", props, appRunner.pUi.theme.get("colorSecondary"));
props.put("text", props, "");
Styler.fromTo(initProps, props);
props.eventOnChange = true;
styler.apply();

setTypeface(mFont);
}

@SuppressLint("ClickableViewAccessibility")
Expand Down Expand Up @@ -103,6 +101,10 @@ public PButton text(String label) {
return this;
}

public String text() {
return getText().toString();
}

@PhonkMethod(description = "Triggers the function when the button is clicked", example = "")
@PhonkMethodParam(params = {"function"})
public PButton onClick(final ReturnInterface callbackfn) {
Expand Down Expand Up @@ -150,41 +152,34 @@ public PButton onLongPress(final ReturnInterface callbackfn) {
return this;
}

@PhonkMethod(description = "Changes the font type to the button", example = "")
@PhonkMethodParam(params = {"Typeface"})
public PButton textFont(Typeface f) {
mFont = f;
this.setTypeface(f);
@Override
public PButton textFont(Typeface font) {
mFont = font;
this.setTypeface(font, mStyle);
MLog.d(TAG, "--> " + "font");

return this;
}

@Override
public View textSize(int size) {
this.textSize(size);
setTextSize(size);
return this;
}

@Override
@PhonkMethod(description = "Changes the font text color", example = "")
@PhonkMethodParam(params = {"colorHex"})
public PButton textColor(String c) {
this.setTextColor(Color.parseColor(c));
return this;
}

@Override
@PhonkMethod(description = "Changes the font text color", example = "")
@PhonkMethodParam(params = {"colorHex"})
public PButton textColor(int c) {
this.setTextColor(c);
return this;
}

@Override
@PhonkMethod(description = "Changes the text size", example = "")
@PhonkMethodParam(params = {"size"})
public View textSize(float size) {
this.setTextSize(size);

Expand All @@ -193,6 +188,7 @@ public View textSize(float size) {

@Override
public View textStyle(int style) {
mStyle = style;
this.setTypeface(mFont, style);
return this;
}
Expand All @@ -203,8 +199,6 @@ public View textAlign(int alignment) {
return this;
}

@PhonkMethod(description = "Changes the background color", example = "")
@PhonkMethodParam(params = {"colorHex"})
public PButton background(String c) {
this.setBackgroundColor(Color.parseColor(c));
return this;
Expand Down Expand Up @@ -243,27 +237,23 @@ public void set(float x, float y, float w, float h) {

public PAnimation anim() {
return new PAnimation(this);
} @Override
}

@Override
public void setProps(Map style) {
styler.setProps(style);
}

class ButtonStyler extends Styler {
ButtonStyler(AppRunner appRunner, View view, StylePropertiesProxy props) {
super(appRunner, view, props);
}

@Override
public void apply() {
super.apply();

text(mProps.get("text").toString());
}
} @Override
@Override
public Map getProps() {
return props;
}

@Override
public int id() {
return getId();
}




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import java.util.Map;

import io.phonk.runner.apidoc.annotation.PhonkClass;
import io.phonk.runner.apidoc.annotation.PhonkMethod;
import io.phonk.runner.apidoc.annotation.PhonkMethodParam;
import io.phonk.runner.apprunner.AppRunner;
import io.phonk.runner.apprunner.api.common.ReturnInterface;
import io.phonk.runner.apprunner.api.common.ReturnObject;
Expand All @@ -41,6 +39,9 @@ public class PCheckBox extends androidx.appcompat.widget.AppCompatCheckBox imple
public final StylePropertiesProxy props = new StylePropertiesProxy();
public final Styler styler;

private Typeface mFont;
private int mStyle;

public PCheckBox(AppRunner appRunner) {
super(appRunner.getAppContext());
styler = new Styler(appRunner, this, props);
Expand All @@ -60,7 +61,8 @@ public PCheckBox onChange(final ReturnInterface callbackfn) {

@Override
public View textFont(Typeface font) {
this.setTypeface(font);
mFont = font;
this.setTypeface(font, mStyle);
return this;
}

Expand All @@ -77,8 +79,6 @@ public View textColor(String textColor) {
}

@Override
@PhonkMethod(description = "Changes the font text color", example = "")
@PhonkMethodParam(params = {"colorHex"})
public View textColor(int c) {
this.setTextColor(c);
return this;
Expand All @@ -92,7 +92,8 @@ public View textSize(float textSize) {

@Override
public View textStyle(int style) {
this.setTypeface(null, style);
mStyle = style;
this.setTypeface(mFont, style);
return this;
}

Expand All @@ -117,4 +118,9 @@ public Map getProps() {
return props;
}

@Override
public int id() {
return getId();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,9 @@ public void setProps(Map style) {
public Map getProps() {
return props;
}

@Override
public int id() {
return getId();
}
}
Loading