private void InitializeComponent() { _hBox = new HorizontalBox() { AllowPadding = true }; this.Child = _hBox; _group = new Group("Numbers") { AllowMargins = true }; _hBox.Children.Add(_group, true); _vBox = new VerticalBox() { AllowPadding = true }; _group.Child = _vBox; _spinBox = new SpinBox(0, 100); _slider = new Slider(0, 100); _progressBar = new ProgressBar(); _spinBox.ValueChanged += (sender, args) => { var value = _spinBox.Value; _slider.Value = value; _progressBar.Value = value; }; _slider.ValueChanged += (sender, args) => { var value = _slider.Value; _spinBox.Value = value; _progressBar.Value = value; }; _vBox.Children.Add(_spinBox); _vBox.Children.Add(_slider); _vBox.Children.Add(_progressBar); _ip = new ProgressBar(); _ip.Value = -1; _vBox.Children.Add(_ip); _group = new Group("Lists") { AllowMargins = true }; _hBox.Children.Add(_group, true); _vBox = new VerticalBox() { AllowPadding = true }; _group.Child = _vBox; _comboBox = new ComboBox(); _comboBox.Add("Combobox Item 1", "Combobox Item 2", "Combobox Item 3"); _vBox.Children.Add(_comboBox); _editableComboBox = new EditableComboBox(); _editableComboBox.Add("Editable Item 1", "Editable Item 2", "Editable Item 3"); _vBox.Children.Add(_editableComboBox); _radioButtons = new RadioButtonList(); _radioButtons.Add("Radio Button 1", "Radio Button 2", "Radio Button 3"); _vBox.Children.Add(_radioButtons); }
protected override Box CreateBoxCore(TexEnvironment environment) { var texFont = environment.MathFont; var style = environment.Style; // set thickness to default if default value should be used double lineHeight; var defaultLineThickness = texFont.GetDefaultLineThickness(style); if (this.useDefaultThickness) { lineHeight = this.lineRelativeThickness.HasValue ? this.lineRelativeThickness.Value * defaultLineThickness : defaultLineThickness; } else { lineHeight = new SpaceAtom(null, this.lineThicknessUnit, 0, this.lineThickness, 0) .CreateBox(environment).Height; } // Create boxes for numerator and demoninator atoms, and make them of equal width. var numeratorBox = this.Numerator == null ? StrutBox.Empty : this.Numerator.CreateBox(environment.GetNumeratorStyle()); var denominatorBox = this.Denominator == null ? StrutBox.Empty : this.Denominator.CreateBox(environment.GetDenominatorStyle()); if (numeratorBox.Width < denominatorBox.Width) { numeratorBox = new HorizontalBox(numeratorBox, denominatorBox.Width, this.numeratorAlignment); } else { denominatorBox = new HorizontalBox(denominatorBox, numeratorBox.Width, this.denominatorAlignment); } // Calculate preliminary shift-up and shift-down amounts. double shiftUp, shiftDown; if (style < TexStyle.Text) { shiftUp = texFont.GetNum1(style); shiftDown = texFont.GetDenom1(style); } else { shiftDown = texFont.GetDenom2(style); if (lineHeight > 0) { shiftUp = texFont.GetNum2(style); } else { shiftUp = texFont.GetNum3(style); } } // Create result box. var resultBox = new VerticalBox(); // add box for numerator. resultBox.Add(numeratorBox); // Calculate clearance and adjust shift amounts. var axis = texFont.GetAxisHeight(style); if (lineHeight > 0) { // Draw fraction line. // Calculate clearance amount. double clearance; if (style < TexStyle.Text) { clearance = 3 * lineHeight; } else { clearance = lineHeight; } // Adjust shift amounts. var delta = lineHeight / 2; var kern1 = shiftUp - numeratorBox.Depth - (axis + delta); var kern2 = axis - delta - (denominatorBox.Height - shiftDown); var delta1 = clearance - kern1; var delta2 = clearance - kern2; if (delta1 > 0) { shiftUp += delta1; kern1 += delta1; } if (delta2 > 0) { shiftDown += delta2; kern2 += delta2; } resultBox.Add(new StrutBox(0, kern1, 0, 0)); resultBox.Add(new HorizontalRule(environment, lineHeight, numeratorBox.Width, 0)); resultBox.Add(new StrutBox(0, kern2, 0, 0)); } else { // Do not draw fraction line. // Calculate clearance amount. double clearance; if (style < TexStyle.Text) { clearance = 7 * defaultLineThickness; } else { clearance = 3 * defaultLineThickness; } // Adjust shift amounts. var kern = shiftUp - numeratorBox.Depth - (denominatorBox.Height - shiftDown); var delta = (clearance - kern) / 2; if (delta > 0) { shiftUp += delta; shiftDown += delta; kern += 2 * delta; } resultBox.Add(new StrutBox(0, kern, 0, 0)); } // add box for denominator. resultBox.Add(denominatorBox); // Adjust height and depth of result box. resultBox.Height = shiftUp + numeratorBox.Height; resultBox.Depth = shiftDown + denominatorBox.Depth; return(resultBox); }
protected override Box CreateBoxCore(TexEnvironment environment) { var texFont = environment.MathFont; var style = environment.Style; if ((this.UseVerticalLimits.HasValue && !this.UseVerticalLimits.Value) || (!this.UseVerticalLimits.HasValue && style >= TexStyle.Text)) { // Attach atoms for limits as scripts. return(new ScriptsAtom(this.Source, this.BaseAtom, this.LowerLimitAtom, this.UpperLimitAtom) .CreateBox(environment)); } // Create box for base atom. Box baseBox; double delta; if (this.BaseAtom is SymbolAtom && this.BaseAtom.Type == TexAtomType.BigOperator) { // Find character of best scale for operator symbol. var opChar = texFont.GetCharInfo(((SymbolAtom)this.BaseAtom).Name, style).Value; if (style < TexStyle.Text && texFont.HasNextLarger(opChar)) { opChar = texFont.GetNextLargerCharInfo(opChar, style); } var charBox = new CharBox(environment, opChar) { Source = this.BaseAtom.Source }; charBox.Shift = -(charBox.Height + charBox.Depth) / 2 - environment.MathFont.GetAxisHeight(environment.Style); baseBox = new HorizontalBox(charBox); delta = opChar.Metrics.Italic; if (delta > TexUtilities.FloatPrecision) { baseBox.Add(new StrutBox(delta, 0, 0, 0)); } } else { baseBox = new HorizontalBox(this.BaseAtom == null ? StrutBox.Empty : this.BaseAtom.CreateBox(environment)); delta = 0; } // Create boxes for upper and lower limits. var upperLimitBox = this.UpperLimitAtom == null ? null : this.UpperLimitAtom.CreateBox( environment.GetSuperscriptStyle()); var lowerLimitBox = this.LowerLimitAtom == null ? null : this.LowerLimitAtom.CreateBox( environment.GetSubscriptStyle()); // Make all component boxes equally wide. var maxWidth = Math.Max(Math.Max(baseBox.Width, upperLimitBox == null ? 0 : upperLimitBox.Width), lowerLimitBox == null ? 0 : lowerLimitBox.Width); if (baseBox != null) { baseBox = ChangeWidth(baseBox, maxWidth); } if (upperLimitBox != null) { upperLimitBox = ChangeWidth(upperLimitBox, maxWidth); } if (lowerLimitBox != null) { lowerLimitBox = ChangeWidth(lowerLimitBox, maxWidth); } var resultBox = new VerticalBox(); var opSpacing5 = texFont.GetBigOpSpacing5(style); var kern = 0d; // Create and add box for upper limit. if (this.UpperLimitAtom != null) { resultBox.Add(new StrutBox(0, opSpacing5, 0, 0)); upperLimitBox.Shift = delta / 2; resultBox.Add(upperLimitBox); kern = Math.Max(texFont.GetBigOpSpacing1(style), texFont.GetBigOpSpacing3(style) - upperLimitBox.Depth); resultBox.Add(new StrutBox(0, kern, 0, 0)); } // Add box for base atom. resultBox.Add(baseBox); // Create and add box for lower limit. if (this.LowerLimitAtom != null) { resultBox.Add(new StrutBox(0, Math.Max(texFont.GetBigOpSpacing2(style), texFont.GetBigOpSpacing4(style) - lowerLimitBox.Height), 0, 0)); lowerLimitBox.Shift = -delta / 2; resultBox.Add(lowerLimitBox); resultBox.Add(new StrutBox(0, opSpacing5, 0, 0)); } // Adjust height and depth of result box. var baseBoxHeight = baseBox.Height; var totalHeight = resultBox.Height + resultBox.Depth; if (upperLimitBox != null) { baseBoxHeight += opSpacing5 + kern + upperLimitBox.Height + upperLimitBox.Depth; } resultBox.Height = baseBoxHeight; resultBox.Depth = totalHeight - baseBoxHeight; return(resultBox); }
protected override Box CreateBoxCore(TexEnvironment environment) { var texFont = environment.MathFont; var style = environment.Style; // Create box for base atom. var baseBox = this.BaseAtom == null ? StrutBox.Empty : this.BaseAtom.CreateBox(environment); if (this.SubscriptAtom == null && this.SuperscriptAtom == null) { if (baseBox is CharBox) { // This situation should only happen when CreateBox called on a temporary ScriptsAtom created from // BigOperatorAtom.CreateBox. The CharBox's Shift should then be fixed up. baseBox.Shift = -(baseBox.Height + baseBox.Depth) / 2 - environment.MathFont.GetAxisHeight(environment.Style); } return(baseBox); } // Create result box. var resultBox = new HorizontalBox(baseBox); // Get last font used or default Mu font. int lastFontId = baseBox.GetLastFontId(); if (lastFontId == TexFontUtilities.NoFontId) { lastFontId = texFont.GetMuFontId(); } var subscriptStyle = environment.GetSubscriptStyle(); var superscriptStyle = environment.GetSuperscriptStyle(); // Set delta value and preliminary shift-up and shift-down amounts depending on type of base atom. var delta = 0d; double shiftUp, shiftDown; if (this.BaseAtom is AccentedAtom) { var accentedBox = ((AccentedAtom)this.BaseAtom).BaseAtom.CreateBox(environment.GetCrampedStyle()); shiftUp = accentedBox.Height - texFont.GetSupDrop(superscriptStyle.Style); shiftDown = accentedBox.Depth + texFont.GetSubDrop(subscriptStyle.Style); } else if (this.BaseAtom is SymbolAtom && this.BaseAtom.Type == TexAtomType.BigOperator) { var charInfo = texFont.GetCharInfo(((SymbolAtom)this.BaseAtom).Name, style).Value; if (style < TexStyle.Text && texFont.HasNextLarger(charInfo)) { charInfo = texFont.GetNextLargerCharInfo(charInfo, style); } var charBox = new CharBox(environment, charInfo); charBox.Shift = -(charBox.Height + charBox.Depth) / 2 - environment.MathFont.GetAxisHeight( environment.Style); resultBox = new HorizontalBox(charBox); delta = charInfo.Metrics.Italic; if (delta > TexUtilities.FloatPrecision && this.SubscriptAtom == null) { resultBox.Add(new StrutBox(delta, 0, 0, 0)); } shiftUp = resultBox.Height - texFont.GetSupDrop(superscriptStyle.Style); shiftDown = resultBox.Depth + texFont.GetSubDrop(subscriptStyle.Style); } else if (this.BaseAtom is CharSymbol charSymbol) { var charFont = charSymbol.GetCharFont(texFont).Value; if (!charSymbol.IsTextSymbol || !texFont.HasSpace(charFont.FontId)) { delta = texFont.GetCharInfo(charFont, style).Value.Metrics.Italic; } if (delta > TexUtilities.FloatPrecision && this.SubscriptAtom == null) { resultBox.Add(new StrutBox(delta, 0, 0, 0)); delta = 0; } shiftUp = 0; shiftDown = 0; } else { shiftUp = baseBox.Height - texFont.GetSupDrop(superscriptStyle.Style); shiftDown = baseBox.Depth + texFont.GetSubDrop(subscriptStyle.Style); } Box superscriptBox = null; Box superscriptContainerBox = null; Box subscriptBox = null; Box subscriptContainerBox = null; if (this.SuperscriptAtom != null) { // Create box for superscript atom. superscriptBox = this.SuperscriptAtom.CreateBox(superscriptStyle); superscriptContainerBox = new HorizontalBox(superscriptBox); // Add box for script space. superscriptContainerBox.Add(scriptSpaceAtom.CreateBox(environment)); // Adjust shift-up amount. double p; if (style == TexStyle.Display) { p = texFont.GetSup1(style); } else if (environment.GetCrampedStyle().Style == style) { p = texFont.GetSup3(style); } else { p = texFont.GetSup2(style); } shiftUp = Math.Max(Math.Max(shiftUp, p), superscriptBox.Depth + Math.Abs(texFont.GetXHeight( style, lastFontId)) / 4); } if (this.SubscriptAtom != null) { // Create box for subscript atom. subscriptBox = this.SubscriptAtom.CreateBox(subscriptStyle); subscriptContainerBox = new HorizontalBox(subscriptBox); // Add box for script space. subscriptContainerBox.Add(scriptSpaceAtom.CreateBox(environment)); } // Check if only superscript is set. if (subscriptBox == null) { superscriptContainerBox.Shift = -shiftUp; resultBox.Add(superscriptContainerBox); return(resultBox); } // Check if only subscript is set. if (superscriptBox == null) { subscriptContainerBox.Shift = Math.Max(Math.Max(shiftDown, texFont.GetSub1(style)), subscriptBox.Height - 4 * Math.Abs(texFont.GetXHeight(style, lastFontId)) / 5); resultBox.Add(subscriptContainerBox); return(resultBox); } // Adjust shift-down amount. shiftDown = Math.Max(shiftDown, texFont.GetSub2(style)); // Reposition both subscript and superscript. double defaultLineThickness = texFont.GetDefaultLineThickness(style); // Space between subscript and superscript. double scriptsInterSpace = shiftUp - superscriptBox.Depth + shiftDown - subscriptBox.Height; if (scriptsInterSpace < 4 * defaultLineThickness) { shiftUp += 4 * defaultLineThickness - scriptsInterSpace; // Position bottom of superscript at least 4/5 of X-height above baseline. double psi = 0.8 * Math.Abs(texFont.GetXHeight(style, lastFontId)) - (shiftUp - superscriptBox.Depth); if (psi > 0) { shiftUp += psi; shiftDown -= psi; } } scriptsInterSpace = shiftUp - superscriptBox.Depth + shiftDown - subscriptBox.Height; // Create box containing both superscript and subscript. var scriptsBox = new VerticalBox(); superscriptContainerBox.Shift = delta; scriptsBox.Add(superscriptContainerBox); scriptsBox.Add(new StrutBox(0, scriptsInterSpace, 0, 0)); scriptsBox.Add(subscriptContainerBox); scriptsBox.Height = shiftUp + superscriptBox.Height; scriptsBox.Depth = shiftDown + subscriptBox.Depth; resultBox.Add(scriptsBox); return(resultBox); }
private void InitializeComponent() { _hBox = new HorizontalBox() { AllowPadding = true }; this.Child = _hBox; _vBox = new VerticalBox() { AllowPadding = true }; _hBox.Children.Add(_vBox); _vBox.Children.Add(new DatePicker()); _vBox.Children.Add(new TimePicker()); _vBox.Children.Add(new DateTimePicker()); _vBox.Children.Add(new FontPicker()); _vBox.Children.Add(new ColorPicker()); _hBox.Children.Add(new Separator(Orientation.Vertical)); _vBox = new VerticalBox() { AllowPadding = true }; _hBox.Children.Add(_vBox); _grid = new Grid() { AllowPadding = true }; _vBox.Children.Add(_grid); _button = new Button("Open File"); _entry = new Entry() { IsReadOnly = true }; _button.Click += (sender, args) => { var dialog = new OpenFileDialog(); if (!dialog.Show()) { _entry.Text = "(cancelled)"; return; } ; _entry.Text = dialog.Path; }; _grid.Children.Add(_button, 0, 0, 1, 1, 0, HorizontalAlignment.Stretch, 0, VerticalAlignment.Stretch); _grid.Children.Add(_entry, 1, 0, 1, 1, 1, HorizontalAlignment.Stretch, 0, VerticalAlignment.Stretch); _button = new Button("Save File"); _entry2 = new Entry() { IsReadOnly = true }; _button.Click += (sender, args) => { var dialog = new SaveFileDialog(); if (!dialog.Show()) { _entry2.Text = "(cancelled)"; return; } ; _entry2.Text = dialog.Path; }; _grid.Children.Add(_button, 0, 1, 1, 1, 0, HorizontalAlignment.Stretch, 0, VerticalAlignment.Stretch); _grid.Children.Add(_entry2, 1, 1, 1, 1, 1, HorizontalAlignment.Stretch, 0, VerticalAlignment.Stretch); _msgGrid = new Grid() { AllowPadding = true }; _grid.Children.Add(_msgGrid, 0, 2, 2, 1, 0, HorizontalAlignment.Center, 0, VerticalAlignment.Top); _button = new Button("Message Box"); _button.Click += (sender, args) => { MessageBox.Show("This is a normal message box.", "More detailed information can be shown here."); }; _msgGrid.Children.Add(_button, 0, 0, 1, 1, 0, HorizontalAlignment.Stretch, 0, VerticalAlignment.Stretch); _button = new Button("Error Box"); _button.Click += (sender, args) => { MessageBox.Show("This message box describes an error.", "More detailed information can be shown here.", MessageBoxTypes.Error); }; _msgGrid.Children.Add(_button, 1, 0, 1, 1, 0, HorizontalAlignment.Stretch, 0, VerticalAlignment.Stretch); }
private void InitializeComponent() { _container = new VerticalBox(); this.Child = _container; var hbox = new HorizontalBox(); _container.Children.Add(hbox); hbox.Children.Add(new Label("Size")); _width = new SpinBox(int.MinValue, int.MaxValue); hbox.Children.Add(_width, true); _height = new SpinBox(int.MinValue, int.MaxValue); hbox.Children.Add(_height, true); _fullscreen = new CheckBox("Fullscreen"); hbox.Children.Add(_fullscreen); _width.ValueChanged += (sender, args) => { var size = _mainWindow.Size; _mainWindow.Size = new Size(_width.Value, size.Height); }; _height.ValueChanged += (sender, args) => { var size = _mainWindow.Size; _mainWindow.Size = new Size(size.Width, _height.Value); }; _fullscreen.Checked += (sender, args) => { _mainWindow.FullScreen = true; UpdateSize(); }; _fullscreen.UnChecked += (sender, args) => { _mainWindow.FullScreen = false; UpdateSize(); }; _mainWindow.Resize += (sender, args) => { Console.WriteLine("size\n"); UpdateSize(); }; UpdateSize(); var checkbox = new CheckBox("Borderless"); checkbox.Checked += (sender, args) => { _mainWindow.Borderless = true; }; checkbox.UnChecked += (sender, args) => { _mainWindow.Borderless = false; }; _container.Children.Add(checkbox); var button = new Button("Borderless Resizes"); button.Click += (sender, args) => { if (!borderAHInit) { _borderAH = new AreaHandler(); borderAHInit = true; } var window = new Window("Border Resize Test", 300, 500); window.Borderless = true; var area = new Area(_borderAH); var b = new HorizontalBox(); b.Children.Add(area, true); window.Child = b; window.Show(); }; _container.Children.Add(button); hbox = new HorizontalBox(); _container.Children.Add(hbox, true); hbox.Children.Add(new Separator(Orientation.Vertical)); }
private void InitializeComponent() { _container = new VerticalBox(); this.Child = _container; _group = new Group("Moving Label"); _container.Children.Add(_group); _vBox = new VerticalBox(); _group.Child = _vBox; _hBox = new HorizontalBox(); _button = new Button("Move the Label!"); _button.Click += (sender, args) => { var to = _movingCurrent == 0 ? 1 : 0; _movingBoxes[_movingCurrent].Children.RemoveAt(0); _movingBoxes[to].Children.Add(_movingLabel); _movingCurrent = to; }; _hBox.Children.Add(_button, true); _hBox.Children.Add(new Label(""), true); _vBox.Children.Add(_hBox); _hBox = new HorizontalBox(); _movingBoxes[0] = new VerticalBox(); _hBox.Children.Add(_movingBoxes[0], true); _movingBoxes[1] = new VerticalBox(); _hBox.Children.Add(_movingBoxes[1], true); _vBox.Children.Add(_hBox); _movingLabel = new Label("This label moves!"); _movingBoxes[0].Children.Add(_movingLabel); _hBox = new HorizontalBox(); _button = new Button(MoveOutText); _button.Click += (sender, args) => { var btn = sender as Button; if (btn == null) { return; } if (_moveBack) { _mainBox.Children.RemoveAt(1); _mainTab.Children.Insert(0, _page1); btn.Text = MoveOutText; _moveBack = false; } else { _mainTab.Children.RemoveAt(0); _mainBox.Children.Add(_page1, true); btn.Text = MoveBackText; _moveBack = true; } }; _hBox.Children.Add(_button); _container.Children.Add(_hBox); _hBox = new HorizontalBox(); _hBox.Children.Add(new Label("Label Alignment Test")); _button = new Button("Open Menued Window"); _button.Click += (sender, args) => { OpenAnotherWindow(true); }; _hBox.Children.Add(_button); _button = new Button("Open Menuless Window"); _button.Click += (sender, args) => { OpenAnotherWindow(false); }; _hBox.Children.Add(_button); _button = new Button("Disabled Menued"); _button.Click += (sender, args) => { OpenAnotherDisabledWindow(true); }; _hBox.Children.Add(_button); _button = new Button("Disabled Menuless"); _button.Click += (sender, args) => { OpenAnotherDisabledWindow(false); }; _hBox.Children.Add(_button); _container.Children.Add(_hBox); _nestedBox = new HorizontalBox(); _innerhbox = new HorizontalBox(); _innerhbox.Children.Add(new Button("These")); _innerhbox.Children.Add(new Button("buttons") { Enabled = false }); _nestedBox.Children.Add(_innerhbox); _innerhbox = new HorizontalBox(); _innerhbox.Children.Add(new Button("are")); _innerhbox2 = new HorizontalBox(); _innerhbox2.Children.Add(new Button("in") { Enabled = false }); _innerhbox.Children.Add(_innerhbox2); _nestedBox.Children.Add(_innerhbox); _innerhbox = new HorizontalBox(); _innerhbox2 = new HorizontalBox(); _innerhbox2.Children.Add(new Button("nested")); _innerhbox3 = new HorizontalBox(); _innerhbox3.Children.Add(new Button("boxes") { Enabled = false }); _innerhbox2.Children.Add(_innerhbox3); _innerhbox.Children.Add(_innerhbox2); _nestedBox.Children.Add(_innerhbox); _container.Children.Add(_nestedBox); _hBox = new HorizontalBox(); _button = new Button("Enable Nested Box"); _button.Click += (sender, args) => { _nestedBox.Enabled = true; }; _hBox.Children.Add(_button); _button = new Button("Disable Nested Box"); _button.Click += (sender, args) => { _nestedBox.Enabled = false; }; _hBox.Children.Add(_button); _container.Children.Add(_hBox); _disabledTab = new Tab(); _disabledTab.Children.Add(new TabPage("Disabled", new Button("Button"))); _disabledTab.Children.Add(new TabPage("Tab", new Label("Label"))); _disabledTab.Enabled = false; _container.Children.Add(_disabledTab, true); _entry = new Entry(); _readonly = new Entry(); _entry.TextChanged += (sender, args) => { _readonly.Text = args.Text; }; _readonly.Text = "If you can see this, uiEntryReadOnly() isn't working properly."; _readonly.IsReadOnly = true; if (_readonly.IsReadOnly) { _readonly.Text = ""; } _container.Children.Add(_entry); _container.Children.Add(_readonly); _hBox = new HorizontalBox(); _button = new Button("Show Button 2"); _button2 = new Button("Button 2"); _button.Click += (sender, args) => { _button2.Show(); }; // It doesn't hide on unix. libui bug? _button2.Hide(); _hBox.Children.Add(_button, true); _hBox.Children.Add(_button2); _container.Children.Add(_hBox); }
private VerticalBox ApplyCellPaddings( TexEnvironment environment, IList <List <Box> > matrix, int columnCount, IList <List <CellGaps> > matrixCellGaps) { var rowsContainer = new VerticalBox(); for (var i = 0; i < matrix.Count; ++i) { var rowContainer = new HorizontalBox(); for (var j = 0; j < columnCount; ++j) { var cell = matrix[i][j]; var cellContainer = new VerticalBox(); var(topPadding, bottomPadding) = GetVerticalPadding(i, j); cellContainer.Add(topPadding); cellContainer.Add(cell); cellContainer.Add(bottomPadding); cellContainer.Height = cellContainer.TotalHeight; cellContainer.Depth = 0; var(leftPadding, rightPadding) = GetHorizontalPadding(i, j); if (leftPadding != null) { rowContainer.Add(leftPadding); } rowContainer.Add(cellContainer); rowContainer.Add(rightPadding); } rowsContainer.Add(rowContainer); } var axis = environment.MathFont.GetAxisHeight(environment.Style); var containerHeight = rowsContainer.TotalHeight; rowsContainer.Depth = containerHeight / 2 - axis; rowsContainer.Height = containerHeight / 2 + axis; return(rowsContainer); (Box TopPadding, Box BottomPadding) GetVerticalPadding(int i, int j) { var value = matrixCellGaps[i][j].Vertical; var topBox = new StrutBox(0.0, VerticalPadding / 2 + value, 0.0, VerticalPadding); var bottomBox = new StrutBox(0.0, VerticalPadding / 2 + value, 0.0, VerticalPadding); return(topBox, bottomBox); } (Box LeftPadding, Box RightPadding) GetHorizontalPadding(int i, int j) { var value = matrixCellGaps[i][j].Horizontal; var leftPadding = MatrixCellAlignment == MatrixCellAlignment.Left ? 0.0 : value; var rightPadding = MatrixCellAlignment == MatrixCellAlignment.Left ? value * 2 : value; var leftBox = MatrixCellAlignment == MatrixCellAlignment.Left ? null : new StrutBox(HorizontalPadding / 2 + leftPadding, 0.0, 0.0, 0.0); var rightBox = new StrutBox(HorizontalPadding / 2 + rightPadding, 0.0, 0.0, 0.0); return(leftBox, rightBox); } }
protected override Box CreateBoxCore(TexEnvironment environment) { CharSymbol GetBaseChar() { var baseAtom = this.BaseAtom; while (baseAtom is AccentedAtom a) { baseAtom = a.BaseAtom; } return(baseAtom as CharSymbol); } var texFont = environment.MathFont; var style = environment.Style; // Create box for base atom. var baseBox = this.BaseAtom == null ? StrutBox.Empty : this.BaseAtom.CreateBox(environment.GetCrampedStyle()); var baseCharFont = GetBaseChar()?.GetCharFont(texFont).Value; var skew = baseCharFont == null ? 0.0 : texFont.GetSkew(baseCharFont, style); // Find character of best scale for accent symbol. var accentChar = texFont.GetCharInfo(this.AccentAtom.Name, style).Value; while (texFont.HasNextLarger(accentChar)) { var nextLargerChar = texFont.GetNextLargerCharInfo(accentChar, style); if (nextLargerChar.Metrics.Width > baseBox.Width) { break; } accentChar = nextLargerChar; } var resultBox = new VerticalBox(); // Create and add box for accent symbol. Box accentBox; var accentItalicWidth = accentChar.Metrics.Italic; if (accentItalicWidth > TexUtilities.FloatPrecision) { accentBox = new HorizontalBox(new CharBox(environment, accentChar)); accentBox.Add(new StrutBox(accentItalicWidth, 0, 0, 0)); } else { accentBox = new CharBox(environment, accentChar); } resultBox.Add(accentBox); var delta = Math.Min(baseBox.Height, texFont.GetXHeight(style, accentChar.FontId)); resultBox.Add(new StrutBox(0, -delta, 0, 0)); // Centre and add box for base atom. Centre base box and accent box with respect to each other. var boxWidthsDiff = (baseBox.Width - accentBox.Width) / 2; accentBox.Shift = skew + Math.Max(boxWidthsDiff, 0); if (boxWidthsDiff < 0) { baseBox = new HorizontalBox(baseBox, accentBox.Width, TexAlignment.Center); } resultBox.Add(baseBox); // Adjust height and depth of result box. var depth = baseBox.Depth; var totalHeight = resultBox.Height + resultBox.Depth; resultBox.Depth = depth; resultBox.Height = totalHeight - depth; return(resultBox); }
protected override Box CreateBoxCore(TexEnvironment environment) { var texFont = environment.MathFont; var style = environment.Style; var axis = texFont.GetAxisHeight(style); //Region for adjustment vars double maxrowWidth = 0; //stores the max cell height for each row var RowsMaxCellHeight = new List <double>(); for (int i = 0; i < RowCount; i++) { RowsMaxCellHeight.Add(0); } //stores the max cell width for each column var ColumnsMaxCellWidth = new List <double>(); for (int i = 0; i < ColumnCount; i++) { ColumnsMaxCellWidth.Add(0); } //Create a vertical box to hold the rows and their cells var resultBox = new VerticalBox(); for (int i = 0; i < RowCount; i++) { //row top pad resultBox.Add(new StrutBox(maxrowWidth, CellBottomTopPadding / 2, 0, 0)); var rowbox = new HorizontalBox() { Tag = $"Row:{i}", }; for (int j = 0; j < ColumnCount; j++) { double maxrowHeight = 0; //cell left pad var cellleftpad = new StrutBox(CellLeftRightPadding / 2, 0, 0, 0) { Tag = $"CellLeftPad{i}:{j}", Shift = 0, }; //cell right pad var cellrightpad = new StrutBox(CellLeftRightPadding / 2, 0, 0, 0) { Tag = $"CellRightPad{i}:{j}", Shift = 0, }; //cell box var rowcellbox = TableCells[i][j] == null ? StrutBox.Empty : TableCells[i][j].CreateBox(environment); ColumnsMaxCellWidth[j] = rowcellbox.TotalWidth > ColumnsMaxCellWidth[j] ? rowcellbox.TotalWidth : ColumnsMaxCellWidth[j]; rowcellbox.Tag = "innercell"; //cell box holder var rowcolbox = new VerticalBox() { Tag = $"Cell{i}:{j}", ShowBounds = false }; var celltoppad = new StrutBox(rowcellbox.TotalWidth, CellBottomTopPadding / 2, 0, 0) { Tag = $"CellTopPad{i}:{j}", }; var cellbottompad = new StrutBox(rowcellbox.TotalWidth, CellBottomTopPadding / 2, 0, 0) { Tag = $"CellBottomPad{i}:{j}", }; rowcolbox.Add(celltoppad); rowcolbox.Add(rowcellbox); rowcolbox.Add(cellbottompad); //maxrowHeight += rowcolbox.TotalHeight; maxrowHeight += rowcellbox.TotalHeight + CellBottomTopPadding; rowcolbox.Width = rowcellbox.TotalWidth; //rowcolbox.Height = maxrowHeight; rowbox.Add(cellleftpad); rowbox.Add(rowcolbox); rowbox.Add(cellrightpad); RowsMaxCellHeight[i] = maxrowHeight > RowsMaxCellHeight[i] ? maxrowHeight : RowsMaxCellHeight[i]; } rowbox.Shift = 0; resultBox.Add(rowbox); //row bottom pad resultBox.Add(new StrutBox(maxrowWidth, CellBottomTopPadding / 2, 0, 0)); } int rows = 0; int columns = 0; //1->Left and right, 2->Top and Bottom //create the item below to hold the left-right gaps(Tuple.Item1) and top-bottom gaps (Tuple.Item2) for the rows List <List <Tuple <double, double> > > TableCellGaps = new List <List <Tuple <double, double> > >(); for (int i = 0; i < resultBox.Children.Count; i++) { var tablerowitem = resultBox.Children[i]; List <Tuple <double, double> > RowGaps = new List <Tuple <double, double> >(); if (tablerowitem is HorizontalBox && tablerowitem.Tag.ToString() == $"Row:{rows}") { for (int j = 0; j < ((HorizontalBox)tablerowitem).Children.Count; j++) { var rowcolitem = ((HorizontalBox)tablerowitem).Children[j]; if (rowcolitem is StrutBox) { rowcolitem.Height = RowsMaxCellHeight[rows]; } else if (rowcolitem is VerticalBox && rowcolitem.Tag.ToString() == $"Cell{rows}:{columns}") { double cellVShift = RowsMaxCellHeight[rows] - rowcolitem.TotalHeight; double cellHShift = ColumnsMaxCellWidth[columns] - rowcolitem.TotalWidth; ((HorizontalBox)tablerowitem).Children[j - 1].Shift = rowcolitem.Depth; // + (cellVShift / 2);//.Width += cellHShift / 2; ((HorizontalBox)tablerowitem).Children[j + 1].Shift = rowcolitem.Depth; // +(cellVShift / 2);// Width += cellHShift / 2; RowGaps.Add(new Tuple <double, double> (cellHShift / 2, cellVShift / 2)); columns++; } } columns = 0; rows++; TableCellGaps.Add(RowGaps); } } rows = 0; columns = 0; for (int i = 0; i < resultBox.Children.Count; i++) { var tablerowitem = resultBox.Children[i]; if (tablerowitem is HorizontalBox && tablerowitem.Tag.ToString() == $"Row:{rows}") { double rowwidth = 0; for (int j = 0; j < ((HorizontalBox)tablerowitem).Children.Count; j++) { var currowcolitem = ((HorizontalBox)tablerowitem).Children[j]; var prevrowcolitem = j > 0 ? ((HorizontalBox)tablerowitem).Children[j - 1] : ((HorizontalBox)tablerowitem).Children[j]; var nextrowcolitem = j < ((HorizontalBox)tablerowitem).Children.Count - 1 ? ((HorizontalBox)tablerowitem).Children[j + 1] : ((HorizontalBox)tablerowitem).Children[j]; if (currowcolitem is VerticalBox && Regex.IsMatch(currowcolitem.Tag.ToString(), @"Cell[0-9]+:[0-9]+")) { rowwidth += currowcolitem.TotalWidth; var leftstructboxtag = $"CellLeftPad{rows}:{columns}"; var rightstructboxtag = $"CellRightPad{rows}:{columns}"; switch (CellHorizontalAlignment) { case HorizontalAlignment.Left: { if (prevrowcolitem is StrutBox && prevrowcolitem.Tag.ToString() == leftstructboxtag) { //prevrowcolitem.Width += TableCellGaps[a][b].Item1; rowwidth += prevrowcolitem.TotalWidth; } if (nextrowcolitem is StrutBox && nextrowcolitem.Tag.ToString() == rightstructboxtag) { nextrowcolitem.Width += 2 * TableCellGaps[rows][columns].Item1; rowwidth += nextrowcolitem.TotalWidth; } break; } case HorizontalAlignment.Right: { if (prevrowcolitem is StrutBox && prevrowcolitem.Tag.ToString() == leftstructboxtag) { prevrowcolitem.Width += 2 * TableCellGaps[rows][columns].Item1; rowwidth += prevrowcolitem.TotalWidth; } if (nextrowcolitem is StrutBox && nextrowcolitem.Tag.ToString() == rightstructboxtag) { //nextrowcolitem.Width += TableCellGaps[a][b].Item1; rowwidth += nextrowcolitem.TotalWidth; } break; } case HorizontalAlignment.Center: { if (prevrowcolitem is StrutBox && prevrowcolitem.Tag.ToString() == leftstructboxtag) { prevrowcolitem.Width += TableCellGaps[rows][columns].Item1; rowwidth += prevrowcolitem.TotalWidth; } if (nextrowcolitem is StrutBox && nextrowcolitem.Tag.ToString() == rightstructboxtag) { nextrowcolitem.Width += TableCellGaps[rows][columns].Item1; rowwidth += nextrowcolitem.TotalWidth; } break; } case HorizontalAlignment.Stretch: { if (prevrowcolitem is StrutBox && prevrowcolitem.Tag.ToString() == leftstructboxtag) { prevrowcolitem.Width = 0; prevrowcolitem.Italic = 0; rowwidth += prevrowcolitem.TotalWidth; } if (nextrowcolitem is StrutBox && nextrowcolitem.Tag.ToString() == rightstructboxtag) { nextrowcolitem.Width = 0; nextrowcolitem.Italic = 0; rowwidth += nextrowcolitem.TotalWidth; } break; } default: break; } double cellheight = 0; //check the vertical cell gap size and increase appropriately for (int k = 0; k < ((VerticalBox)currowcolitem).Children.Count; k++) { var curcellitem = ((VerticalBox)currowcolitem).Children[k]; var prevcellitem = k > 0? ((VerticalBox)currowcolitem).Children[k - 1]:((VerticalBox)currowcolitem).Children[k]; var nextcellitem = k < (((VerticalBox)currowcolitem).Children.Count - 1)? ((VerticalBox)currowcolitem).Children[k + 1]:((VerticalBox)currowcolitem).Children[k]; if (curcellitem.Tag.ToString() == "innercell") { cellheight += curcellitem.TotalHeight; var topstructboxtag = $"CellTopPad{rows}:{columns}"; var bottomstructboxtag = $"CellBottomPad{rows}:{columns}"; switch (CellVerticalAlignment) { case VerticalAlignment.Bottom: { if (prevcellitem.Tag.ToString() == topstructboxtag) { prevcellitem.Height += 2 * TableCellGaps[rows][columns].Item2; //prevcellitem.Background = Brushes.Aquamarine; cellheight += prevcellitem.TotalHeight; if (prevcellitem.Height > (currowcolitem.Height / 2)) { } } if (nextcellitem.Tag.ToString() == bottomstructboxtag) { //nextcellitem.Height += TableCellGaps[a][b].Item2; //nextcellitem.Background = Brushes.BurlyWood; cellheight += nextcellitem.TotalHeight; } break; } case VerticalAlignment.Center: { if (prevcellitem.Tag.ToString() == topstructboxtag) { prevcellitem.Height += TableCellGaps[rows][columns].Item2; //prevcellitem.Background = Brushes.Aquamarine; cellheight += prevcellitem.TotalHeight; if (prevcellitem.Height > (currowcolitem.Height / 2)) { } } if (nextcellitem.Tag.ToString() == bottomstructboxtag) { nextcellitem.Height += TableCellGaps[rows][columns].Item2; //nextcellitem.Background = Brushes.BurlyWood; cellheight += nextcellitem.TotalHeight; } break; } case VerticalAlignment.Stretch: { if (prevcellitem.Tag.ToString() == topstructboxtag) { prevcellitem.Height = 0; prevcellitem.Depth = 0; //prevcellitem.Background = Brushes.Aquamarine; cellheight += prevcellitem.TotalHeight; if (prevcellitem.Height > (currowcolitem.Height / 2)) { } } if (nextcellitem.Tag.ToString() == bottomstructboxtag) { nextcellitem.Height = 0; nextcellitem.Depth = 0; //nextcellitem.Background = Brushes.BurlyWood; cellheight += nextcellitem.TotalHeight; } break; } case VerticalAlignment.Top: { if (prevcellitem.Tag.ToString() == topstructboxtag) { //prevcellitem.Height += TableCellGaps[a][b].Item2; //prevcellitem.Background = Brushes.Aquamarine; cellheight += prevcellitem.TotalHeight; if (prevcellitem.Height > (currowcolitem.Height / 2)) { } } if (nextcellitem.Tag.ToString() == bottomstructboxtag) { nextcellitem.Height += 2 * TableCellGaps[rows][columns].Item2; //nextcellitem.Background = Brushes.BurlyWood; cellheight += nextcellitem.TotalHeight; } break; } default: break; } if (prevrowcolitem is StrutBox && prevrowcolitem.Tag.ToString() == leftstructboxtag) { prevrowcolitem.Shift += TableCellGaps[rows][columns].Item2; } if (nextrowcolitem is StrutBox && nextrowcolitem.Tag.ToString() == rightstructboxtag) { nextrowcolitem.Shift += TableCellGaps[rows][columns].Item2; } //currowcolitem.Shift -= TableCellGaps[a][b].Item2; ; } } //currowcolitem.Height = cellheight; columns++; } } tablerowitem.Width = rowwidth; columns = 0; rows++; } } double sigmaTotalHeight = 0; double adjustedwidth = 0; foreach (var item in resultBox.Children) { sigmaTotalHeight += item.TotalHeight; if (item.TotalWidth > adjustedwidth) { adjustedwidth = item.TotalWidth; } } double adjustedTotalHeight = RowsMaxCellHeight.Sum() + (RowCount * CellBottomTopPadding); resultBox.Depth = 0; resultBox.Height = adjustedTotalHeight > sigmaTotalHeight?adjustedTotalHeight:sigmaTotalHeight; resultBox.Width = adjustedwidth > resultBox.TotalWidth?adjustedwidth:resultBox.TotalWidth; var enviroYDiff = axis >= resultBox.TotalHeight ? -(axis - resultBox.TotalHeight) / 2: (resultBox.TotalHeight - axis) / 2; resultBox.Shift = enviroYDiff; var finalbox = new HorizontalBox(); finalbox.Add(new StrutBox(CellLeftRightPadding / 8, 0, 0, 0)); finalbox.Add(resultBox); finalbox.Add(new StrutBox(CellLeftRightPadding / 8, 0, 0, 0)); return(finalbox); }
private void InitializeComponent() { //Setup grid and layout // grid = new Grid(){ AllowPadding = true }; // form = new Form(); // this.Child = grid; // vbox = new VerticalBox(); // displayLayout = new HorizontalBox(); // messageLayout = new HorizontalBox(); // vbox.Children.Add(messageLayout); // this.Child = vbox; // messageDisplay = new MultilineEntry(); // // messageDisplay.Enabled = false; // //Setup buttons and controls // sendButton = new Button("Send"); // sendButton.Click += (object sender, EventArgs args) => // { // MessageBox.Show(String.Format("You said {0}", messageArea.Text)); // }; // messageArea = new Entry(); // //Add controls to the grid // // vbox.Children.Add(displayLayout); // displayLayout.Children.Add(messageDisplay); // messageLayout.Children.Add(messageArea); // messageLayout.Children.Add(sendButton); _hBox = new HorizontalBox() { AllowPadding = true }; _vBox = new VerticalBox() { AllowPadding = true }; this.Child = _vBox; messageDisplay = new MultilineEntry(); _vBox.Children.Add(messageDisplay, true); messageArea = new Entry(); sendButton = new Button("Send"); _vBox.Children.Add(_hBox); _hBox.Children.Add(messageArea); _hBox.Children.Add(sendButton); }
public static Box CreateBox(string symbol, double minHeight, TexEnvironment environment) { var texFont = environment.TexFont; var style = environment.Style; var charInfo = texFont.GetCharInfo(symbol, style); // Find first version of character that has at least minimum height. var metrics = charInfo.Metrics; var totalHeight = metrics.Height + metrics.Depth; while (totalHeight < minHeight && texFont.HasNextLarger(charInfo)) { charInfo = texFont.GetNextLargerCharInfo(charInfo, style); metrics = charInfo.Metrics; totalHeight = metrics.Height + metrics.Depth; } if (totalHeight >= minHeight) { // Character of sufficient height was found. return(new CharBox(environment, charInfo)); } if (texFont.IsExtensionChar(charInfo)) { var resultBox = new VerticalBox(); // Construct box from extension character. var extension = texFont.GetExtension(charInfo, style); if (extension.Top != null) { resultBox.Add(new CharBox(environment, extension.Top)); } if (extension.Middle != null) { resultBox.Add(new CharBox(environment, extension.Middle)); } if (extension.Bottom != null) { resultBox.Add(new CharBox(environment, extension.Bottom)); } // Insert repeatable part multiple times until box is high enough. var repeatBox = new CharBox(environment, extension.Repeat); do { if (extension.Top != null && extension.Bottom != null) { resultBox.Add(1, repeatBox); if (extension.Middle != null) { resultBox.Add(resultBox.Children.Count - 1, repeatBox); } } else if (extension.Bottom != null) { resultBox.Add(0, repeatBox); } else { resultBox.Add(repeatBox); } } while(resultBox.Height + resultBox.Depth < minHeight); return(resultBox); } // No extensions available, so use tallest available version of character. return(new CharBox(environment, charInfo)); }
public override Box CreateBox() { float lineHeight = lineThickness * TexContext.Scale; // Create boxes for numerator and demoninator atoms, and make them of equal width. TexContext.Environment.Push(TexUtility.GetNumeratorStyle()); var numeratorBox = numerator == null ? StrutBox.Empty : numerator.CreateBox(); TexContext.Environment.Pop(); TexContext.Environment.Push(TexUtility.GetDenominatorStyle()); var denominatorBox = denominator == null ? StrutBox.Empty : denominator.CreateBox(); TexContext.Environment.Pop(); float maxWidth = (numeratorBox.width < denominatorBox.width ? denominatorBox.width : numeratorBox.width) + TEXConfiguration.main.FractionMargin * TexContext.Scale; numeratorBox = HorizontalBox.Get(numeratorBox, maxWidth, numeratorAlignment); denominatorBox = HorizontalBox.Get(denominatorBox, maxWidth, denominatorAlignment); // Calculate preliminary shift-up and shift-down amounts. float shiftUp, shiftDown; var styleFactor = TexContext.Scale; if (TexContext.Environment.value >= TexEnvironment.Text) { styleFactor *= TEXConfiguration.main.FractionNarrowFactor; } shiftUp = TEXConfiguration.main.NumeratorShift * styleFactor; shiftDown = TEXConfiguration.main.DenominatorShift * styleFactor; // Create result box. var resultBox = VerticalBox.Get(); // add box for numerator. resultBox.Add(numeratorBox); // Calculate clearance and adjust shift amounts. //var axis = TEXConfiguration.main.AxisHeight * TexContext.Scale; // Calculate clearance amount. float clearance = lineHeight > 0 ? TEXConfiguration.main.FractionGap : TEXConfiguration.main.FractionGapNoLine; // Adjust shift amounts. var kern1 = shiftUp - numeratorBox.depth; var kern2 = shiftDown - denominatorBox.height; var delta1 = clearance - kern1; var delta2 = clearance - kern2; if (delta1 > 0) { shiftUp += delta1; kern1 += delta1; } if (delta2 > 0) { shiftDown += delta2; kern2 += delta2; } if (lineHeight > 0) { // Draw fraction line. resultBox.Add(StrutBox.Get(0, kern1, 0, 0)); resultBox.Add(HorizontalRule.Get(lineHeight, numeratorBox.width, 0)); resultBox.Add(StrutBox.Get(0, kern2, 0, 0)); } else { // Do not draw fraction line. var kern = kern1 + kern2; resultBox.Add(StrutBox.Get(0, kern, 0, 0)); } // add box for denominator. resultBox.Add(denominatorBox); // Adjust height and depth of result box. resultBox.height = shiftUp + numeratorBox.height; resultBox.depth = shiftDown + lineHeight + denominatorBox.depth; TexUtility.CentreBox(resultBox); return(resultBox); }