public override void Initialize() { base.Initialize(); _canvasImage = _rootElement.Q <Image>("CanvasImage"); _canvasImage.RegisterCallback <PointerDownEvent>(e => PaintDocument.StartPainting()); _canvasImage.RegisterCallback <PointerUpEvent>(e => PaintDocument.StopPainting()); _toolButtons = new ToolButton[PaintDocument.Tools.Length]; for (var i = 0; i < PaintDocument.Tools.Length; i++) { var tool = PaintDocument.Tools[i]; if (tool == null) { throw new Exception("Empty tool in tools list of PaintView"); } _toolButtons[i] = _rootElement.Q <ToolButton>(tool.name); _toolButtons[i].Clicked += () => SelectTool(tool); if (tool.name == "EraserTool") { _toolButtons[i].DoubleClicked += PaintDocument.Clear; } } _undoButton = _rootElement.Q <ToolButton>("Undo"); _undoButton.Clicked += () => PaintDocument.Undo(); _redoButton = _rootElement.Q <ToolButton>("Redo"); _redoButton.Clicked += () => PaintDocument.Redo(); _closeButton = _rootElement.Q <ToolButton>("Close"); _closeButton.Clicked += () => OpenView("BookView"); _colorPalette = _rootElement.Q <ColorPalette>(); _colorPalette.Choices = ColorSet.Colors; _colorPalette.RegisterCallback <ChangeEvent <Color> >(evt => PaintDocument.Color = evt.newValue); _colorPalette.Value = PaintDocument.Color; _brushSizePalette = _rootElement.Q <BrushSizePalette>(); _brushSizePalette.Choices = BrushSizeSet.BrushSizes; _brushSizePalette.RegisterCallback <ChangeEvent <float> >(evt => PaintDocument.BrushSize = evt.newValue); _brushSizePalette.Value = PaintDocument.BrushSize; }
public void AddPreIcon(Image preIcon) { this.Insert(0, preIcon); preIcon.RegisterCallback <MouseDownEvent>(evt => { this.value = !this.value; }); preIcon.AddToClassList(UssClasses.DotsEditorCommon.CustomToolbarToggleIcon); m_Label = this.Q <Label>(); m_Label.RemoveFromClassList(UssClasses.DotsEditorCommon.CustomToolbarToggleOnlyLabel); m_Label.AddToClassList(UssClasses.DotsEditorCommon.CustomToolbarToggleLabel); }