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

fix(buttons): buttons on mac are out of screen #101

Merged
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
11 changes: 10 additions & 1 deletion Scenario/Editor/ImageEditor/ImageEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ImageEditor : EditorWindow
public static void ShowWindow()
{
ImageEditor window = GetWindow<ImageEditor>("Image Editor");
window.minSize = new Vector2(minimumWidth, window.minSize.y);
window.minSize = new Vector2(GetScreenWidth() * 0.8f, window.minSize.y);
}

public static void ShowWindow(Texture2D texture2D)
Expand All @@ -36,5 +36,14 @@ private void OnGUI()
{
imageEditorUI.DrawUI(this.position);
}

private static int GetScreenWidth()
{
#if UNITY_EDITOR_OSX
return Screen.resolutions[Screen.resolutions.Length - 1].width / 2;
#else
return Screen.currentResolution.width;
#endif
}
mrbusysky marked this conversation as resolved.
Show resolved Hide resolved
}
}
22 changes: 14 additions & 8 deletions Scenario/Editor/ImageEditor/ImageEditorUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private void DrawRightSection(Rect position)
private void DrawMiddleSection(Rect position)
{
// Middle Section
float middleSectionWidth = position.width * 0.8f;
float middleSectionWidth = position.width * 0.4f;
EditorGUILayout.BeginVertical(GUILayout.Width(middleSectionWidth));
{
CustomStyle.Space(18);
Expand Down Expand Up @@ -352,7 +352,7 @@ private void DrawCanvasWithImage()
float aspectRatio = (float)uploadedImage.width / (float)uploadedImage.height;
float width = Mathf.Min(uploadedImage.width, maxSize);
float height = width / aspectRatio;

Rect rect = GUILayoutUtility.GetRect(width, height, GUILayout.ExpandWidth(false),
GUILayout.ExpandHeight(false));

Expand Down Expand Up @@ -452,17 +452,20 @@ private Rect DrawLeftSection(Rect position)
CustomStyle.Space(10);

GUILayout.Label("Color", EditorStyles.boldLabel);

int colorButtonSize = 40;
int numColumns = Mathf.FloorToInt((leftSectionWidth - 0) / colorButtonSize);
int numColumns = 4;

//Save the original color of the GUI background color
Color originalColor = GUI.backgroundColor;

for (int i = 0; i < 35; i++)
{
if (i % numColumns == 0) EditorGUILayout.BeginHorizontal();

GUIStyle colorButtonStyle = new GUIStyle(GUI.skin.button);
Color color = Color.HSVToRGB((float)i / 35, 1, 1);
colorButtonStyle.normal.background = MakeTex(2, 2, color);
GUI.backgroundColor = color; //swap the background color to the color we want. so every new GUI component will get this color

if (GUILayout.Button("", colorButtonStyle, GUILayout.Width(colorButtonSize),
GUILayout.Height(colorButtonSize)))
Expand All @@ -473,6 +476,9 @@ private Rect DrawLeftSection(Rect position)
if (i % numColumns == numColumns - 1 || i == 34) EditorGUILayout.EndHorizontal();
}

//GUI will now draw with default color
GUI.backgroundColor = originalColor;

CustomStyle.Space(10);

int[] brushSizes = new[] { 6, 12, 16, 24, 30, 40, 48, 64 };
Expand Down Expand Up @@ -520,7 +526,7 @@ private Rect DrawLeftSection(Rect position)
GUILayout.EndHorizontal();
}
EditorGUILayout.EndVertical();

return position;
}

Expand Down Expand Up @@ -734,7 +740,7 @@ private void AddToCanvasHistory()
private void UndoCanvas()
{
if (canvasHistoryIndex <= 0) return;

// Save the current state to the redo stack
Texture2D redoImage = new Texture2D(canvasImage.width, canvasImage.height, TextureFormat.RGBA32, false, true);
redoImage.SetPixels(canvasImage.GetPixels());
Expand All @@ -750,7 +756,7 @@ private void UndoCanvas()
private void RedoCanvas()
{
if (redoHistory.Count <= 0) return;

// Save the current state to the undo stack
Texture2D undoImage = new Texture2D(canvasImage.width, canvasImage.height, TextureFormat.RGBA32, false, true);
undoImage.SetPixels(canvasImage.GetPixels());
Expand Down
Loading