Skip to content

Commit

Permalink
refactor: rrenaming + updated text wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikaLos committed Dec 19, 2024
1 parent aee067a commit fb883f9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
11 changes: 6 additions & 5 deletions GsaGH/Helpers/GH/Legend/ContourLegend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public int BitmapWidth {
public int ActualBitmapWidth => (int)(BitmapWidth * _configuration.Scale);
private int _leftBitmapEdge;
private int _actualTextHeight;
private static readonly Font _systemFont = SystemFonts.DefaultFont;
internal bool IsInvalidConfiguration = false; //only for tests

public ContourLegend(ContourLegendConfiguration configuration, int bitmapInitialWidth = 15) {
Expand Down Expand Up @@ -102,7 +103,7 @@ private void DrawValues(IGH_PreviewArgs args) {
private void DrawBottomText(IGH_PreviewArgs args, string bottomText) {
const int BottomOffset = 145;
const int ExtraOffset = 10;
int textMaxWidth = _configuration.ActualWidth - GetScaledValue(ExtraOffset);
int textMaxWidth = _configuration.ActualWidth + GetScaledValue(ExtraOffset);
int topPosition = GetScaledValue(BottomOffset);

string wrappedText = WrapText(bottomText, textMaxWidth);
Expand All @@ -111,7 +112,7 @@ private void DrawBottomText(IGH_PreviewArgs args, string bottomText) {
}

private void InitializeDimensions(int viewportEdge) {
_actualTextHeight = GetScaledSystemFont().Height;
_actualTextHeight = (int)GetScaledSystemFont().Size;
_leftBitmapEdge = viewportEdge - _configuration.ActualWidth;
Bitmap = new Bitmap(ActualBitmapWidth, _configuration.ActualHeight);
}
Expand All @@ -125,9 +126,9 @@ private int GetScaledValue(int value) {
}

private Font GetScaledSystemFont() {
Font systemFont = SystemFonts.DefaultFont;
float fontSize = (float)(systemFont.Size * _configuration.Scale);
return new Font(systemFont.FontFamily, fontSize);
int defaultTextSize = 12;
float fontSize = (float)(defaultTextSize * _configuration.Scale);
return new Font(_systemFont.FontFamily, fontSize);
}
}
}
2 changes: 1 addition & 1 deletion GsaGH/Helpers/GH/Legend/LegendMenuBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ToolStripMenuItem CreateLegendToolStripMenuItem(
ImageScaling = ToolStripItemImageScaling.SizeToFit,
};

var menuControl = new GH_MenuCustomControl(legendScaleMenuItem.DropDown, legendScaleTextBox.Control, true, 200);
_ = new GH_MenuCustomControl(legendScaleMenuItem.DropDown, legendScaleTextBox.Control, true, 200);

legendScaleMenuItem.DropDownItems[1].MouseUp += (s, e) => {
UpdateLegendScale(component, updateUI, setLegendScaleDelegate);
Expand Down
4 changes: 3 additions & 1 deletion GsaGH/Helpers/GH/TextWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ private static string[] GetTextToWrap(string text, out List<string> lines) {
}

private static float CalculateTextWidth(string text, Font font) {
return _graphics.MeasureString(text, font).Width;
int dpi = 96;
var newFont = new Font(font.FontFamily, font.Size / (_graphics.DpiX / dpi));
return _graphics.MeasureString(text, newFont).Width;
}
}
}

0 comments on commit fb883f9

Please sign in to comment.