public CommentView(GraphComment comment) { target = comment; SetPosition(comment.position); styleSheets.Add(Resources.Load <StyleSheet>("Styles/CommentView")); m_TitleContainer = new VisualElement(); m_TitleContainer.AddToClassList("titleContainer"); m_TitleEditor = new TextField(); var input = m_TitleEditor.Q(TextField.textInputUssName); input.RegisterCallback <KeyDownEvent>(OnTitleKeyDown); input.RegisterCallback <FocusOutEvent>(e => { OnFinishEditingTitle(); }); m_TitleContainer.Add(m_TitleEditor); m_TitleLabel = new Label(); m_TitleLabel.text = comment.title; m_TitleContainer.Add(m_TitleLabel); m_TitleEditor.style.display = DisplayStyle.None; Add(m_TitleContainer); ClearClassList(); AddToClassList("commentView"); capabilities |= Capabilities.Selectable | Capabilities.Movable | Capabilities.Deletable | Capabilities.Resizable; RegisterCallback <GeometryChangedEvent>(OnGeometryChanged); RegisterCallback <MouseDownEvent>(OnMouseDown); RegisterCallback <DetachFromPanelEvent>((e) => OnDestroy()); this.AddManipulator(new ContextualMenuManipulator(BuildContextualMenu)); Enum.TryParse(target.theme, out m_Theme); SetTheme(m_Theme); }
/// <summary> /// Add a new comment to the canvas and the associated Graph /// /// If there are selected nodes, this'll encapsulate the selection with /// the comment box. Otherwise, it'll add at defaultPosition. /// </summary> private void AddComment() { // Pad out the bounding box a bit more on the selection float padding = 30; // TODO: Remove hardcoding Rect bounds = GetBounds(selection); if (bounds.width < 1 || bounds.height < 1) { Vector2 worldPosition = contentViewContainer.WorldToLocal(m_LastMousePosition); bounds.x = worldPosition.x; bounds.y = worldPosition.y; // TODO: For some reason CSS minWidth/minHeight isn't being respected. // Maybe I need to wait for CSS to load before setting bounds? bounds.width = 150 - padding * 2; bounds.height = 100 - padding * 3; } bounds.x -= padding; bounds.y -= padding * 2; bounds.width += padding * 2; bounds.height += padding * 3; var comment = new GraphComment(); comment.title = "New Comment"; comment.position = bounds; var commentView = new CommentView(comment); commentView.onResize += Dirty; m_Graph.comments.Add(comment); m_CommentViews.Add(commentView); AddElement(commentView); Dirty(commentView); }