protected void DrawChildren() { if (m_subviews.Count > 0) { for (int i = 0; i < m_subviews.Count; ++i) { CView subview = m_subviews[i]; if (!subview.IsEnabled && GUI.enabled) { GUI.enabled = false; try { subview.OnGUI(); } finally { GUI.enabled = true; } } else { subview.OnGUI(); } } } }
protected virtual bool KeyDownEventHandler(CView view, CEvent evt) { switch (evt.keyCode) { case KeyCode.UpArrow: { if (m_lastSelectedIndex > m_cellsEntries.HeadIndex && !evt.control) { int nextSelectedIndex = m_lastSelectedIndex - 1; ScrollUntilRowVisible(nextSelectedIndex); SwitchSelectedCell(nextSelectedIndex); return(true); } if (FirstVisibleCellIndex > m_cellsEntries.HeadIndex) { if (IsCellFullyVisible(FirstVisibleCellIndex)) { ScrollUntilRowVisible(FirstVisibleCellIndex - 1); } else { ScrollUntilRowVisible(FirstVisibleCellIndex); } return(true); } return(false); } case KeyCode.DownArrow: { if (m_lastSelectedIndex != -1 && m_lastSelectedIndex < m_cellsEntries.Length - 1 && !evt.control) { int nextSelectedIndex = m_lastSelectedIndex + 1; ScrollUntilRowVisible(nextSelectedIndex); SwitchSelectedCell(nextSelectedIndex); return(true); } if (LastVisibleCellIndex != 1 && LastVisibleCellIndex < m_cellsEntries.Length - 1) { if (IsCellFullyVisible(LastVisibleCellIndex)) { ScrollUntilRowVisible(LastVisibleCellIndex + 1); } else { ScrollUntilRowVisible(LastVisibleCellIndex); } return(true); } return(false); } } return(false); }
void OnGUI() { if (m_rootView == null) { m_oldSize = new Vector2(this.Width, this.Height); m_rootView = CreateRootView(); if (m_rootView == null) { throw new NullReferenceException("Root view should not be null"); } CreateUI(); RunStart(); } if (m_oldSize.x != this.Width || m_oldSize.y != this.Height) { m_oldSize = new Vector2(this.Width, this.Height); OnSizeChanged(); } m_rootView.OnGUI(); m_dirty = true; CEvent.Destroy(); }
public void RemoveSubview(CView view) { if (view.ParentView == this) { m_subviews.Remove(view); view.ParentView = null; } }
protected override void CreateUI() { const float indent = 12; CView contentView = new CView(this.Width - 2 * indent, this.Height - 2 * indent); contentView.X = indent; contentView.Y = indent; AddSubview(contentView); GUIStyle titleStyle = new GUIStyle(GUI.skin.label); titleStyle.fontSize = 20; CLabel titleLabel = new CLabel("Lunar Plugin for Unity", titleStyle); contentView.AddSubview(titleLabel); CLabel copyrightLabel = new CLabel("(C) 2015 Space Madness", EditorStyles.miniLabel); copyrightLabel.Height += 20; contentView.AddSubview(copyrightLabel); CView buttonsView = new CView(); CButton twitterButton = new CButton("Follow @LunarPlugin", delegate(CButton button) { Application.OpenURL("https://twitter.com/intent/follow?screen_name=LunarPlugin&user_id=2939274198"); }); twitterButton.Width = contentView.Width; buttonsView.AddSubview(twitterButton); CButton facebookButton = new CButton("Facebook Page", delegate(CButton button) { Application.OpenURL("https://www.facebook.com/LunarPlugin"); }); facebookButton.Width = contentView.Width; buttonsView.AddSubview(facebookButton); CButton emailButton = new CButton("Send Email", delegate(CButton button) { Application.OpenURL("mailto:[email protected]?subject=Lunar%20plugin%20feedback&body=Hey%20Alex%2C%0A%0AI%27ve%20just%20checked%20the%20Lunar%20plugin.%20Nice%20job%2C%20man%21%20Still%2C%20there%27s%20some%20stuff%20I%20don%27t%20really%20like.%20For%20example%2C%20...%0A%0AFix%20it%2C%20you%20son%20of%20a%20bitch%2C%20or%20go%20to%20Hell%21%0A%0ASincerely%2C%0A%0AYour%20Lunar%20Plugin%20User"); }); emailButton.Width = contentView.Width; buttonsView.AddSubview(emailButton); buttonsView.ArrangeVert(5); buttonsView.ResizeToFitSubviews(); buttonsView.Height += 20; contentView.AddSubview(buttonsView); contentView.ArrangeVert(); CLabel thanksLabel = new CLabel("Thanks for using Lunar!"); contentView.AddSubview(thanksLabel); thanksLabel.Align(0.5f, 1.0f); }
public static void Show(CView rootView) { if (rootView == null) { throw new NullReferenceException("Root view is null"); } m_rootView = rootView; }
public virtual void Repaint() { CView rootView = RootView; if (rootView != null) { rootView.Repaint(); } }
////////////////////////////////////////////////////////////////////////////// #region Subviews public CView AddSubview(CView view) { if (m_subviews == m_emptyList) { m_subviews = new List <CView>(1); } m_subviews.Add(view); view.ParentView = this; return(view); }
private bool MouseDoubleClickHandler(CView view, CEvent evt) { FocusControl(); if (OnMouseDoubleClick(evt)) { Repaint(); return(true); } return(false); }
public void ResizeToFitSubviews() { float newWidth = 0; float newHeight = 0; for (int i = 0; i < m_subviews.Count; ++i) { CView v = m_subviews[i]; newWidth = Mathf.Max(newWidth, v.X + v.Width); newHeight = Mathf.Max(newHeight, v.Y + v.Height); } Width = newWidth; Height = newHeight; }
private bool KeyDownHandler(CView view, CEvent evt) { if (TextKeyDelegate == null) { return(false); } if (m_firstKeyDown) { m_firstKeyDown = false; IsCtrlPressed = evt.control; IsShiftPressed = evt.shift; IsAltPressed = evt.alt; IsCmdPressed = evt.command; KeyCode key = GetKeyCode(evt); if (OnKeyPress(key)) { return(true); } try { if (TextKeyDelegate(this, key, true)) { return(true); } } catch (Exception e) { CLog.error(e); } } if (CEvent.current.keyCode == KeyCode.Tab || CEvent.current.character == '\t') { CEvent.current.Use(); // disable focus traversal on the tab key } return(false); }
protected virtual void OnResize(float dx, float dy) { for (int i = 0; i < m_subviews.Count; ++i) { CView subview = m_subviews[i]; CViewAutoresizing mask = subview.AutoresizeMask; if (mask == CViewAutoresizing.None) { continue; } float dw = 0; float dh = 0; if ((mask & CViewAutoresizing.FlexibleWidth) != 0) { dw = dx; subview.Width += dw; } else if ((mask & CViewAutoresizing.FlexibleLeftMargin) != 0) { subview.X += dx; } if ((mask & CViewAutoresizing.FlexibleHeight) != 0) { dh = dy; subview.Height += dh; } else if ((mask & CViewAutoresizing.FlexibleTopMargin) != 0) { subview.Y += dy; } if (dx != 0 || dy != 0) { subview.OnResize(dw, dh); } } }
protected void DestroyRootView() { m_rootView = null; }
public void AttachRight(CView other, float indent = 0.0f) { X = other.X + other.Width + indent; }
public void AttachLeft(CView other, float indent = 0.0f) { X = other.X - Width - indent; }
public void AttachUnder(CView other, float indent = 0.0f) { Y = other.Y + other.Height + indent; }
public void AttachAbove(CView other, float indent = 0.0f) { Y = other.Y - Height - indent; }
public void AddSubview(CView view) { m_rootView.AddSubview(view); }
private bool KeyUpEventHandler(CView view, CEvent evt) { return(false); }