Resize a button while it's active
Asked Answered
L

1

0

I want to resize a button while it’s being pressed. At the moment I have a style with no image as background (_style.normal.background = null) and Buttons are being drawn using some images and that style. I would like to define a size of the buttons being displayed for the same layer but in the active state instead of normal and I have no idea how to do it.

code:

public class Buildings : MainSubPanel {
	private Rect[] _boxes;
	private GUIStyle _style;
	private Texture2D[] _icons;
	
	public Buildings(Swapper swapper, Texture2D[] icons) : base(swapper){
		int i = 0;
		int n = 0;
		int shift = 10;
    	_icons = icons;
		_boxes = new Rect[12];
		_style = new GUIStyle();
		_style.normal.background = null;
		while(i < 3){
			while(n < 4){
				_boxes[i*4+n] = new Rect(15+shift+shift*n+50*n, 15+shift+shift*i+i*50, 50, 50);
				++n;
			}
			n = 0;
			++i;
		}
	}
	
	public override void draw(){
		int i = 0;
		while(i<_icons.Length){
			if(GUI.Button(_boxes<em>, _icons*, _style)){*</em>

* swapper.swap(i);
_
}*

* i++;*
* }*
* }*
}

Lamas answered 31/8, 2023 at 10:42 Comment(0)
S
0

You could use a different rect for the active button. It’s going to look weird though, as the active state in a button, when it’s not a selection grid (and even the the state is OnNormal) is very fast, just the time of a clic.

Subhuman answered 6/2, 2012 at 0:43 Comment(1)

A grid of buttons actually. The difference being that, when you clic one, it stays activated and deactive the previous one. For example, if you have a selection grid with those elements : "Banana", "Apple", "Strawberry", you can choose which one you're going to eat (only one mind you !). For the script part, check out the manual.

Subhuman

© 2022 - 2024 — McMap. All rights reserved.