Skip to content

Commit

Permalink
Shader Editor: Improve UI layout
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadelessFox committed Mar 26, 2024
1 parent fec3049 commit f80ab87
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.shade.platform.ui.util.UIUtils;
import com.shade.util.NotNull;
import com.sun.jna.ptr.PointerByReference;
import net.miginfocom.swing.MigLayout;

import javax.swing.*;
import java.awt.*;
Expand Down Expand Up @@ -55,12 +54,16 @@ private void updateTabs() {
continue;
}

pane.addTab(entry.programType().name(), new ProgramPanel(entry));
pane.addTab(entry.programType().toString(), new ProgramPanel(entry));
}
}

private static class ProgramPanel extends JComponent {
private final HwShader.Entry entry;

public ProgramPanel(@NotNull HwShader.Entry entry) {
this.entry = entry;

final JTextArea area = new JTextArea("// No decompiled data");
area.setFont(new Font(Font.MONOSPACED, area.getFont().getStyle(), area.getFont().getSize()));
area.setEditable(false);
Expand All @@ -73,19 +76,16 @@ public ProgramPanel(@NotNull HwShader.Entry entry) {
});

final JToolBar mainToolbar = new JToolBar();
mainToolbar.add(new ExportAction(entry));
mainToolbar.add(button);
mainToolbar.add(new ExportAction());

setLayout(new MigLayout("ins panel,wrap", "[grow,fill]", "[grow,fill][]"));
add(new JScrollPane(area));
add(mainToolbar);
setLayout(new BorderLayout());
add(UIUtils.createScrollPane(area, 0, 0, 1, 0), BorderLayout.CENTER);
add(mainToolbar, BorderLayout.SOUTH);
}

private class ExportAction extends AbstractAction {
final private byte[] programBlob;

public ExportAction(@NotNull HwShader.Entry entry) {
programBlob = entry.program().blob();
public ExportAction() {
putValue(SMALL_ICON, UIManager.getIcon("Action.exportIcon"));
putValue(SHORT_DESCRIPTION, "Export binary data");
setEnabled(true);
Expand All @@ -103,7 +103,7 @@ public void actionPerformed(ActionEvent event) {
}

try {
Files.write(chooser.getSelectedFile().toPath(), programBlob);
Files.write(chooser.getSelectedFile().toPath(), entry.program().blob());
} catch (IOException e) {
UIUtils.showErrorDialog(e, "Error exporting data");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,22 @@ public static Program read(@NotNull ByteBuffer buffer, int size) {
}

public enum ProgramType {
CP,
GP,
VP,
FP
CP("Compute Program"),
GP("Geometry Program"),
VP("Vertex Program"),
FP("Fragment Program");

private final String name;

ProgramType(@NotNull String name) {
this.name = name;
}


@Override
public String toString() {
return name;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.shade.platform.model.Disposable;
import com.shade.platform.model.util.BufferUtils;
import com.shade.platform.model.util.IOUtils;
import com.shade.platform.ui.UIColor;
import com.shade.platform.ui.controls.FileChooser;
import com.shade.platform.ui.util.UIUtils;
import com.shade.util.NotNull;
Expand Down Expand Up @@ -68,13 +67,7 @@ public void componentResized(ComponentEvent e) {
inspectorTable.getColumnModel().getColumn(0).setPreferredWidth(70);
inspectorTable.getColumnModel().getColumn(0).setMaxWidth(70);

final JScrollPane inspectorPane = new JScrollPane(inspectorTable) {
@Override
public void updateUI() {
super.updateUI();
setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIColor.SHADOW));
}
};
final JScrollPane inspectorPane = UIUtils.createScrollPane(inspectorTable, 0, 0, 1, 0);
inspectorPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

final JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.shade.platform.ui.util;

import com.formdev.flatlaf.FlatClientProperties;
import com.shade.platform.ui.UIColor;
import com.shade.platform.ui.controls.validation.InputValidator;
import com.shade.platform.ui.controls.validation.Validation;
import com.shade.platform.ui.dialogs.ExceptionDialog;
Expand Down Expand Up @@ -405,6 +406,17 @@ public void updateUI() {
};
}

@NotNull
public static JScrollPane createScrollPane(@Nullable Component view, int top, int left, int bottom, int right) {
return new JScrollPane(view) {
@Override
public void updateUI() {
super.updateUI();
setBorder(BorderFactory.createMatteBorder(top, left, bottom, right, UIColor.SHADOW));
}
};
}

@NotNull
public static JLabel createBoldLabel() {
return createBoldLabel("");
Expand Down

0 comments on commit f80ab87

Please sign in to comment.