Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make window smaller than 100 pixels

Tags:

processing

I try to make a status bar on the bottom of my screen, but the window can not be made less than 100 pixels. I'm working on Processing 3.0.1.

I use the following code

void setup() {
      surface.setResizable(true);
      surface.setSize(300, 20);
      surface.setLocation(displayWidth-300, displayHeight-50);
    }

void draw() {
  background(128);
}

any ideas??

Thank you all in advance

J!

like image 659
Johntor Avatar asked Sep 26 '22 03:09

Johntor


1 Answers

If you remove the surface.setResizable(true); statement, you can see the canvas is 300x20, but the window is not:

Processing 3.0 sketch window

Processing 3.0 has a lot of changes including refactoring the windowing code, which previously relied on Java's AWT package.

Going through the current source code, you can see:

static public final int MIN_WINDOW_WIDTH = 128;
static public final int MIN_WINDOW_HEIGHT = 128;

defined in PSurface.java line 34 and used through out PSurfaceAWT.java to ensure these minimum window dimensions.

Trying to access the Surface's canvas (println(surface.getNative());) I can it's listed as processing.awt.PSurfaceAWT$SmoothCanvas and I can see a SmoothCanvas class with a getFrame() method which looks promising, but that doesn't seem to be accessible (even though it's a public method of a public class).

So by default, at this time, I'd say resizing the window to be smaller than 128x128 in Processing 3.x is a no go.

If Processing 3.x and smaller window is a must it might be possible to tweak the source code yourself and recompile the core library, but this may bite you later on when having multiple Processing project with multiple versions of the Processing core library. I wouldn't recommend tinkering with the core library normally.

If you can use Processing 2.x for your project, making the window size smaller than 100 pixels is achievable:

PApplet resized window

import java.awt.Dimension;

int w = 300;
int h = 20;
int appBarHeight = 23;//this is on OSX, on Windows/Linux this may be different

void setup() {
  size(w, h);
  frame.setResizable(true);
}

void draw() {
  if (frame.getHeight() != h+appBarHeight){//wait for Processing to finish setting up it's window dimensions (including minimum window dimensions)
    frame.setSize(w,h+appBarHeight);//set your dimensions
  }
  background(128);
}
like image 64
George Profenza Avatar answered Oct 03 '22 13:10

George Profenza