Skip to content

Commit

Permalink
fix isDecorated not working, added nicer scrollbar
Browse files Browse the repository at this point in the history
  • Loading branch information
Osiris-Team committed Jul 12, 2023
1 parent 41bb1a0 commit 37d6f4a
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/osiris/desku/App.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.osiris.desku;

import com.osiris.desku.ui.Theme;
import com.osiris.desku.ui.UI;
import com.osiris.desku.ui.UIManager;
import com.osiris.desku.ui.css.Theme;
import com.osiris.jlib.Stream;
import com.osiris.jlib.logger.AL;
import org.apache.commons.io.FileUtils;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/osiris/desku/ui/Component.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.osiris.desku.ui;

import com.osiris.desku.App;
import com.osiris.desku.ui.css.CSS;
import com.osiris.desku.ui.display.Text;
import com.osiris.desku.ui.event.ClickEvent;
import com.osiris.desku.ui.event.ScrollEvent;
Expand Down Expand Up @@ -179,7 +180,7 @@ public boolean isAttached(){

// Update UI
if (!ui.isLoading.get()){
executeJS("comp.style." + Theme.getJSCompatibleCSSKey(attribute.getKey())
executeJS("comp.style." + CSS.getJSCompatibleCSSKey(attribute.getKey())
+ " = ``;\n"); // Change UI representation
}
} else {
Expand All @@ -193,7 +194,7 @@ public boolean isAttached(){

// Update UI
if (!ui.isLoading.get()){
executeJS("comp.style." + Theme.getJSCompatibleCSSKey(attribute.getKey())
executeJS("comp.style." + CSS.getJSCompatibleCSSKey(attribute.getKey())
+ " = `" + attribute.getValue() + "`;\n"); // Change UI representation
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/osiris/desku/ui/DesktopUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ public void windowClosing(WindowEvent e) {
frame.setFocusable(true);

// These must be called before showing the window
decorate(isDecorated); // Must be called before background()
if(isTransparent) background("#00000000");
decorate(isDecorated);

frame.setVisible(true);
frame.requestFocus();
Expand Down Expand Up @@ -355,8 +355,14 @@ public void background(String hexColor) throws InterruptedException, InvocationT
SwingUtilities.invokeAndWait(() -> {
Color color = convertCSSColor(hexColor);
frame.setBackground(color);
frame.getContentPane().setBackground(color);
//frame.getContentPane().setBackground(color); TODO find out why this makes the frame clickthorugh
//browserContainer.setBackground(color);
if(content != null) content.putStyle("background-color", hexColor);

if(hexColor.equals("#00000000")){
//frame.setOpacity(0.99f); // Slightly transparent to allow mouse events
//TODO doesnt fix shit
}
});
}
}
52 changes: 52 additions & 0 deletions src/main/java/com/osiris/desku/ui/css/CSS.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.osiris.desku.ui.css;

import java.util.ArrayList;
import java.util.List;

public class CSS {
/**
* https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors
*/
public String selector;
public List<Theme.Attribute> attributes = new ArrayList<>();

public CSS(String selector) {
this.selector = selector;
}

/**
* Replaces all hyphens by their uppercase version
* of their next char.
*/
public static String getJSCompatibleCSSKey(String s){
int indexOfHyphen = 0;
while(true){
indexOfHyphen = s.indexOf("-");
if(indexOfHyphen == -1) break;
String c = String.valueOf(s.charAt(indexOfHyphen + 1));
s = s.replaceAll("-"+c, c.toUpperCase());
}
return s;
}

public String toCSS() {
StringBuilder sb = new StringBuilder();
sb.append(selector+"{\n");
for (Attribute attr : attributes) {
sb.append(" ").append(attr.getKey()).append(": ").append(attr.getValue()).append(";\n");
}
sb.append("}\n");
return sb.toString();
}

public class Attribute extends org.jsoup.nodes.Attribute {
public Attribute(String key, String value) {
super(key, value);
attributes.add(this);
}

public String toCSS() {
return getKey() + ": " + getValue() + "; ";
}
}
}
30 changes: 30 additions & 0 deletions src/main/java/com/osiris/desku/ui/css/Scrollbar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.osiris.desku.ui.css;

public class Scrollbar extends CSS{

public Attribute width = new Attribute("width", "0.5rem");
public Attribute height = new Attribute("height", "0.5rem");
public Attribute backgroundClip = new Attribute("background-clip", "padding-box");
public Attribute border = new Attribute("border", "0.1rem solid transparent");
public Attribute color = new Attribute("color", "rgba(0, 0, 0, 0.3)");
public Thumb thumb = new Thumb();

public Scrollbar() {
super("*::-webkit-scrollbar,\n" +
"*::-webkit-scrollbar-thumb");
}

@Override
public String toCSS() {
return super.toCSS() + thumb.toCSS();
}

public class Thumb extends CSS{

public Attribute boxShadow = new Attribute("box-shadow", "inset 0 0 0 10px");

public Thumb() {
super("*::-webkit-scrollbar-thumb");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
package com.osiris.desku.ui;
package com.osiris.desku.ui.css;

import java.util.ArrayList;
import java.util.List;
public class Theme extends CSS{

public class Theme {
/**
* Replaces all hyphens by their uppercase version
* of their next char.
*/
public static String getJSCompatibleCSSKey(String s){
int indexOfHyphen = 0;
while(true){
indexOfHyphen = s.indexOf("-");
if(indexOfHyphen == -1) break;
String c = String.valueOf(s.charAt(indexOfHyphen + 1));
s = s.replaceAll("-"+c, c.toUpperCase());
}
return s;
}
public List<Attribute> attributes = new ArrayList<>();
// Space sizes
public Attribute spaceXS = new Attribute("--space-xs", "0.25rem");
public Attribute spaceS = new Attribute("--space-s", "0.5rem");
Expand All @@ -45,30 +28,18 @@ public static String getJSCompatibleCSSKey(String s){
public Attribute iconWidth = new Attribute("--icon-width", "16px");
public Attribute iconHeight = new Attribute("--icon-height", "16px");

public Scrollbar scrollbar = new Scrollbar();

public Theme() {
super("html");
}

@Override
public String toCSS() {
// All
StringBuilder sb = new StringBuilder();
sb.append("html{\n");
for (Attribute attr : attributes) {
sb.append(" ").append(attr.getKey()).append(": ").append(attr.getValue()).append(";\n");
}
sb.append("}\n");
// Icons
sb.append(".icon{" +
return super.toCSS() +
".icon{" +
"width: " + iconWidth.getValue()+ ";"+
"height: " + iconHeight.getValue()+ ";"+
"}");
return sb.toString();
}

public class Attribute extends org.jsoup.nodes.Attribute {
public Attribute(String key, String value) {
super(key, value);
attributes.add(this);
}

public String toCSS() {
return getKey() + ": " + getValue() + "; ";
}
"}\n" + scrollbar.toCSS();
}
}
1 change: 1 addition & 0 deletions src/test/java/com/osiris/desku/simple_app/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static void main(String[] args) throws Exception {

// Create windows
DesktopUI winHome = (DesktopUI) App.uis.create(home);
DesktopUI winHomeTransparent = (DesktopUI) App.uis.create(home, true, false, 30, 50);
//new NativeWindow(about).plusX(20).plusY(20);

// Exit main thread once all windows closed
Expand Down

0 comments on commit 37d6f4a

Please sign in to comment.