Improve DI, use constructor injection

This commit is contained in:
John Lewin 2018-07-12 09:22:28 -07:00
parent 7853d1b612
commit bbabf95c93
52 changed files with 244 additions and 245 deletions

View file

@ -48,9 +48,6 @@ namespace MatterHackers.MatterControl
: base("Close".Localize())
{
this.WindowTitle = "About".Localize() + " " + ApplicationController.Instance.ProductName;
var theme = ApplicationController.Instance.Theme;
this.MinimumSize = new Vector2(480 * GuiWidget.DeviceScale, 520 * GuiWidget.DeviceScale);
this.WindowSize = new Vector2(500 * GuiWidget.DeviceScale, 550 * GuiWidget.DeviceScale);

View file

@ -12,8 +12,6 @@ namespace MatterHackers.MatterControl
public CheckForUpdatesPage()
: base("Close".Localize())
{
var theme = ApplicationController.Instance.Theme;
this.WindowTitle = this.HeaderText = "Check for Update".Localize();
this.Padding = 0;
this.AnchorAll();
@ -113,7 +111,7 @@ namespace MatterHackers.MatterControl
additionalInfoContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor,
BackgroundColor = theme.Colors.SecondaryBackgroundColor,
HAnchor = HAnchor.Stretch,
Padding = new BorderDouble(left: 6, top: 6),
Visible = false

View file

@ -60,10 +60,6 @@ namespace MatterHackers.MatterControl.ContactForm
public ContactFormPage()
{
var theme = ApplicationController.Instance.Theme;
AnchorAll();
this.WindowTitle = "MatterControl : " + "Submit Feedback".Localize();
this.HeaderText = "How can we improve?".Localize();
@ -106,7 +102,7 @@ namespace MatterHackers.MatterControl.ContactForm
{
AutoExpandBoundsToText = true,
Margin = new BorderDouble(0, 5),
TextColor = ActiveTheme.Instance.PrimaryTextColor,
TextColor = theme.Colors.PrimaryTextColor,
HAnchor = HAnchor.Left
};
@ -154,7 +150,7 @@ namespace MatterHackers.MatterControl.ContactForm
labelContainer.AddChild(new TextWidget(labelText, pointSize: fontSize)
{
TextColor = ActiveTheme.Instance.PrimaryTextColor,
TextColor = theme.Colors.PrimaryTextColor,
VAnchor = VAnchor.Bottom,
HAnchor = HAnchor.Left,
Margin = new BorderDouble(bottom: 2)

View file

@ -54,6 +54,7 @@ namespace MatterHackers.MatterControl.ActionBar
protected virtual int TargetTemperature { get; }
public TemperatureWidgetBase(PrinterConfig printer, string textValue, ThemeConfig theme)
: base(theme)
{
this.printer = printer;

View file

@ -296,7 +296,7 @@ namespace MatterHackers.MatterControl
private List<SceneSelectionOperation> registeredSceneOperations;
public ThumbnailsConfig Thumbnails { get; } = new ThumbnailsConfig();
public ThumbnailsConfig Thumbnails { get; }
private void RebuildSceneOperations(ThemeConfig theme)
{
@ -670,6 +670,7 @@ namespace MatterHackers.MatterControl
{
// Initialize the AppContext theme object which will sync its content with Agg ActiveTheme changes
this.Theme = new ThemeConfig();
this.Thumbnails = new ThumbnailsConfig(this.Theme);
this.MenuTheme = new ThemeConfig();
HelpArticle helpArticle = null;
@ -1306,7 +1307,7 @@ namespace MatterHackers.MatterControl
GuiWidget.LayoutCount = 0;
using (new QuickTimer($"ReloadAll_{reloadCount++}:"))
{
MainView = new WidescreenPanel();
MainView = new WidescreenPanel(ApplicationController.Instance.Theme);
this.DoneReloadingAll?.CallEvents(null, null);
using (new QuickTimer("Time to AddMainview: "))
@ -2691,7 +2692,7 @@ namespace MatterHackers.MatterControl
UserSettings.Instance.Fields.StartCount = UserSettings.Instance.Fields.StartCount + 1;
reporter?.Invoke(0.05, "ApplicationController");
var na = ApplicationController.Instance;
var applicationController = ApplicationController.Instance;
// Accessing any property on ProfileManager will run the static constructor and spin up the ProfileManager instance
reporter?.Invoke(0.2, "ProfileManager");
@ -2700,7 +2701,7 @@ namespace MatterHackers.MatterControl
await ProfileManager.Instance.Initialize();
reporter?.Invoke(0.3, "MainView");
ApplicationController.Instance.MainView = new WidescreenPanel();
applicationController.MainView = new WidescreenPanel(applicationController.Theme);
// now that we are all set up lets load our plugins and allow them their chance to set things up
reporter?.Invoke(0.8, "Plugins");
@ -2710,14 +2711,14 @@ namespace MatterHackers.MatterControl
AppContext.Platform.ProcessCommandline();
reporter?.Invoke(0.91, "OnLoadActions");
ApplicationController.Instance.OnLoadActions();
applicationController.OnLoadActions();
UiThread.SetInterval(() =>
{
ApplicationController.Instance.ActivePrinter.Connection.OnIdle();
applicationController.ActivePrinter.Connection.OnIdle();
}, .1);
return ApplicationController.Instance.MainView;
return applicationController.MainView;
}
private static void ReportStartupProgress(double progress0To1, string section)

View file

@ -44,9 +44,20 @@ namespace MatterHackers.MatterControl
private Queue<Func<Task>> queuedThumbCallbacks = new Queue<Func<Task>>();
private AutoResetEvent thumbGenResetEvent = new AutoResetEvent(false);
private Task thumbnailGenerator = null;
private ThemeConfig theme;
public ThumbnailsConfig(ThemeConfig theme)
{
this.theme = theme;
}
public Dictionary<Type, ImageBuffer> OperationIcons { get; internal set; }
public ImageBuffer DefaultThumbnail() => AggContext.StaticData.LoadIcon("cube.png", 16, 16, ApplicationController.Instance.Theme.InvertIcons);
public ImageBuffer DefaultThumbnail() => AggContext.StaticData.LoadIcon("cube.png", 16, 16, theme.InvertIcons);
public ImageBuffer LoadCachedImage(string cacheId, int width, int height)
{
@ -95,7 +106,7 @@ namespace MatterHackers.MatterControl
public string CachePath(string cacheId)
{
return ApplicationController.CacheablePath(
Path.Combine("Thumbnails", "Content"),
Path.Combine("Thumbnails", "Content"),
$"{cacheId}.png");
}
@ -113,10 +124,6 @@ namespace MatterHackers.MatterControl
$"{libraryItem.ID}-{width}x{height}.png");
}
private AutoResetEvent thumbGenResetEvent = new AutoResetEvent(false);
private Task thumbnailGenerator = null;
internal void QueueForGeneration(Func<Task> func)
{
lock (thumbsLock)
@ -176,7 +183,6 @@ namespace MatterHackers.MatterControl
thumbnailGenerator = null;
}
private static ImageBuffer LoadImage(string filePath)
{
try

View file

@ -1,5 +1,5 @@
/*
Copyright (c) 2014, Kevin Pope
Copyright (c) 2018, Kevin Pope, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -41,8 +41,11 @@ namespace MatterHackers.MatterControl
{
public class WidescreenPanel : FlowLayoutWidget
{
public WidescreenPanel()
private ThemeConfig theme;
public WidescreenPanel(ThemeConfig theme)
{
this.theme = theme;
}
public override void Initialize()
@ -51,9 +54,7 @@ namespace MatterHackers.MatterControl
this.AnchorAll();
this.Name = "WidescreenPanel";
this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
var theme = ApplicationController.Instance.Theme;
this.BackgroundColor = theme.Colors.PrimaryBackgroundColor;
// Push TouchScreenMode into GuiWidget
GuiWidget.TouchScreenMode = UserSettings.Instance.IsTouchScreen;
@ -74,7 +75,7 @@ namespace MatterHackers.MatterControl
this.AddChild(library3DViewSplitter);
// put in the right column
var partPreviewContent = new PartPreviewContent()
var partPreviewContent = new PartPreviewContent(theme)
{
VAnchor = VAnchor.Bottom | VAnchor.Top,
HAnchor = HAnchor.Left | HAnchor.Right
@ -137,26 +138,10 @@ namespace MatterHackers.MatterControl
Selectable = false
});
row.AddChild(new TextWidget(ApplicationController.Instance.ShortProductName, textColor: ActiveTheme.Instance.PrimaryTextColor)
row.AddChild(new TextWidget(ApplicationController.Instance.ShortProductName, textColor: theme.Colors.PrimaryTextColor)
{
VAnchor = VAnchor.Center
});
}
}
public class UpdateNotificationMark : GuiWidget
{
public UpdateNotificationMark()
: base(12, 12)
{
}
public override void OnDraw(Graphics2D graphics2D)
{
graphics2D.Circle(Width / 2, Height / 2, Width / 2, Color.White);
graphics2D.Circle(Width / 2, Height / 2, Width / 2 - 1, Color.Red);
graphics2D.FillRectangle(Width / 2 - 1, Height / 2 - 3, Width / 2 + 1, Height / 2 + 3, Color.White);
base.OnDraw(graphics2D);
}
}
}

View file

@ -305,7 +305,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage
this.AddSettingsRow(updateMatterControl);
this.AddChild(new SettingsItem("Theme".Localize(), new GuiWidget(), theme));
this.AddChild(this.GetThemeControl(theme));
this.AddChild(this.GetThemeControl());
var aboutMatterControl = new SettingsItem("About".Localize() + " " + ApplicationController.Instance.ProductName, theme);
if (IntPtr.Size == 8)
@ -353,7 +353,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage
widget.Padding = widget.Padding.Clone(right: 10);
}
private FlowLayoutWidget GetThemeControl(ThemeConfig theme)
private FlowLayoutWidget GetThemeControl()
{
var container = new FlowLayoutWidget(FlowDirection.TopToBottom)
{

View file

@ -53,10 +53,10 @@ namespace MatterHackers.MatterControl.CustomWidgets
private ThemeConfig theme;
public DockingTabControl(GuiWidget widgetTodockTo, DockSide dockSide, PrinterConfig printer)
public DockingTabControl(GuiWidget widgetTodockTo, DockSide dockSide, PrinterConfig printer, ThemeConfig theme)
: base (FlowDirection.TopToBottom)
{
this.theme = ApplicationController.Instance.Theme;
this.theme = theme;
this.printer = printer;
this.widgetTodockTo = widgetTodockTo;
this.DockSide = dockSide;
@ -334,7 +334,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
});
buttonView.AfterDraw += (s, e) =>
{
e.Graphics2D.Render(rotatedLabel, ActiveTheme.Instance.PrimaryTextColor);
e.Graphics2D.Render(rotatedLabel, theme.Colors.PrimaryTextColor);
};
}
@ -370,7 +370,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
BackgroundColor = theme.TabBarBackground,
};
titleBar.AddChild(new TextWidget(title, textColor: ActiveTheme.Instance.PrimaryTextColor)
titleBar.AddChild(new TextWidget(title, textColor: theme.Colors.PrimaryTextColor)
{
Margin = new BorderDouble(left: 8),
VAnchor = VAnchor.Center

View file

@ -73,7 +73,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
Name = automationName + " Save",
};
searchPanel = new SearchInputBox()
searchPanel = new SearchInputBox(theme)
{
Visible = false,
Margin = new BorderDouble(left: 4)

View file

@ -50,11 +50,9 @@ namespace MatterHackers.MatterControl.CustomWidgets
private ImageWidget imageWidget;
private bool isDirty;
public TreeNode(bool useIcon = true)
public TreeNode(ThemeConfig theme, bool useIcon = true)
: base(FlowDirection.TopToBottom)
{
var theme = ApplicationController.Instance.Theme;
this.HAnchor = HAnchor.Fit | HAnchor.Left;
this.VAnchor = VAnchor.Fit;

View file

@ -327,7 +327,7 @@ namespace MatterHackers.MatterControl.DesignTools
}
else if (propertyValue is DirectionVector directionVector)
{
var field = new DirectionVectorField();
var field = new DirectionVectorField(theme);
field.Initialize(0);
field.SetValue(directionVector);
field.ValueChanged += (s, e) =>
@ -347,7 +347,7 @@ namespace MatterHackers.MatterControl.DesignTools
Normal = directionAxis.Normal
};
var row1 = CreateSettingsRow("Axis".Localize());
var field1 = new DirectionVectorField();
var field1 = new DirectionVectorField(theme);
field1.Initialize(0);
field1.SetValue(newDirectionVector);
row1.AddChild(field1.Content);
@ -489,14 +489,14 @@ namespace MatterHackers.MatterControl.DesignTools
var iconsAttribute = property.PropertyInfo.GetCustomAttributes(true).OfType<IconsAttribute>().FirstOrDefault();
if (iconsAttribute != null)
{
field = new IconEnumField(property, iconsAttribute)
field = new IconEnumField(property, iconsAttribute, theme)
{
InitialValue = propertyValue.ToString()
};
}
else
{
field = new EnumField(property);
field = new EnumField(property, theme);
}
field.Initialize(0);

View file

@ -47,12 +47,6 @@ namespace MatterHackers.MatterControl.PrintHistory
public int ThumbWidth { get; } = 50;
public int ThumbHeight { get; } = 50;
public HistoryListView()
: base(FlowDirection.TopToBottom)
{
this.theme = ApplicationController.Instance.Theme;
}
public HistoryListView(ThemeConfig theme)
: base(FlowDirection.TopToBottom)
{

View file

@ -104,7 +104,7 @@ namespace MatterHackers.MatterControl.Library
{
return Task.FromResult(
AggContext.StaticData.LoadIcon(
Path.Combine((width > 50 || height > 50) ? "icon_sd_card_115x115.png" : "icon_sd_card_50x50.png"),
Path.Combine((width > 50 || height > 50) ? "icon_sd_card_115x115.png" : "icon_sd_card_50x50.png"),
ApplicationController.Instance.Theme.InvertIcons));
}

View file

@ -269,7 +269,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
breadCrumbWidget = new FolderBreadCrumbWidget(libraryView, theme);
navBar.AddChild(breadCrumbWidget);
var searchPanel = new SearchInputBox()
var searchPanel = new SearchInputBox(theme)
{
Visible = false,
Margin = new BorderDouble(10, 0, 5, 0),
@ -986,7 +986,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
internal MHTextEditWidget searchInput;
public Button ResetButton { get; }
public SearchInputBox()
public SearchInputBox(ThemeConfig theme)
{
this.VAnchor = VAnchor.Center | VAnchor.Fit;
this.HAnchor = HAnchor.Stretch;
@ -999,7 +999,7 @@ namespace MatterHackers.MatterControl.PrintLibrary
};
this.AddChild(searchInput);
var resetButton = ApplicationController.Instance.Theme.CreateSmallResetButton();
var resetButton = theme.CreateSmallResetButton();
resetButton.HAnchor = HAnchor.Right | HAnchor.Fit;
resetButton.VAnchor = VAnchor.Center | VAnchor.Fit;
resetButton.Name = "Close Search";

View file

@ -65,13 +65,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
private EventHandler unregisterEvents;
private ImageBuffer bedImage;
public GCode2DWidget(PrinterConfig printer)
public GCode2DWidget(PrinterConfig printer, ThemeConfig theme)
{
this.printer = printer;
options = printer.Bed.RendererOptions;
var theme = ApplicationController.Instance.Theme;
this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
this.LocalBounds = new RectangleDouble(0, 0, 100, 100);

View file

@ -73,7 +73,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
if(item.Source is InsertionGroupObject3D insertionGroup)
{
return new TreeNode()
return new TreeNode(theme)
{
Text = "Loading".Localize(),
Tag = item.Source,
@ -82,7 +82,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
};
}
var node = new TreeNode()
var node = new TreeNode(theme)
{
Text = GetName(item),
Tag = item.Source,

View file

@ -46,11 +46,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
private ChromeTab printerTab = null;
private ChromeTabs tabControl;
public PartPreviewContent()
public PartPreviewContent(ThemeConfig theme)
: base(FlowDirection.TopToBottom)
{
var theme = ApplicationController.Instance.Theme;
this.AnchorAll();
var extensionArea = new LeftClipFlowLayoutWidget()

View file

@ -36,9 +36,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
public class PopupMenuButton : PopupButton
{
public PopupMenuButton()
private ThemeConfig theme;
public PopupMenuButton(ThemeConfig theme)
{
var theme = ApplicationController.Instance.Theme;
this.theme = theme;
this.DisabledColor = new Color(theme.Colors.SecondaryTextColor, 50);
this.HoverColor = theme.MinimalShade;
}
@ -49,7 +51,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
viewWidget.Selectable = false;
viewWidget.BackgroundColor = Color.Transparent;
this.DisabledColor = new Color(ActiveTheme.Instance.SecondaryTextColor, 50);
this.theme = theme;
this.DisabledColor = new Color(theme.Colors.SecondaryTextColor, 50);
this.HoverColor = theme.ToolbarButtonHover;
this.BackgroundColor = theme.ToolbarButtonBackground;
@ -71,8 +74,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
public Color DisabledColor { get; set; }
public Color HoverColor { get; set; } = Color.Transparent;
public Color MouseDownColor { get; set;} = Color.Transparent;
private bool _drawArrow = false;
@ -103,10 +104,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
// Draw directional arrow
graphics2D.Render(
dropArrow,
dropArrow,
LocalBounds.Right - DropArrow.ArrowHeight * 2 - 2,
LocalBounds.Center.Y + DropArrow.ArrowHeight / 2,
this.Enabled ? ActiveTheme.Instance.SecondaryTextColor : this.DisabledColor);
this.Enabled ? theme.Colors.SecondaryTextColor : this.DisabledColor);
}
}

View file

@ -93,7 +93,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
printer.ViewState.ViewModeChanged += ViewState_ViewModeChanged;
LayerScrollbar = new SliceLayerSelector(printer, sceneContext)
LayerScrollbar = new SliceLayerSelector(printer, sceneContext, theme)
{
VAnchor = VAnchor.Stretch,
HAnchor = HAnchor.Right | HAnchor.Fit,
@ -199,7 +199,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
});
// Create and append new widget
gcode2DWidget = new GCode2DWidget(printer)
gcode2DWidget = new GCode2DWidget(printer, theme)
{
Visible = (printer.ViewState.ViewMode == PartViewMode.Layers2D)
};
@ -395,14 +395,14 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
private void AddSettingsTabBar(GuiWidget parent, GuiWidget widgetTodockTo)
{
sideBar = new DockingTabControl(widgetTodockTo, DockSide.Right, ApplicationController.Instance.ActivePrinter)
sideBar = new DockingTabControl(widgetTodockTo, DockSide.Right, printer, theme)
{
Name = "DockingTabControl",
ControlIsPinned = ApplicationController.Instance.ActivePrinter.ViewState.SliceSettingsTabPinned
ControlIsPinned = printer.ViewState.SliceSettingsTabPinned
};
sideBar.PinStatusChanged += (s, e) =>
{
ApplicationController.Instance.ActivePrinter.ViewState.SliceSettingsTabPinned = sideBar.ControlIsPinned;
printer.ViewState.SliceSettingsTabPinned = sideBar.ControlIsPinned;
};
parent.AddChild(sideBar);
@ -416,9 +416,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
NamedSettingsLayers.All),
theme));
sideBar.AddPage("Controls".Localize(), new ManualPrinterControls(printer));
sideBar.AddPage("Controls".Localize(), new ManualPrinterControls(printer, theme));
sideBar.AddPage("Terminal".Localize(), new TerminalWidget(printer)
sideBar.AddPage("Terminal".Localize(), new TerminalWidget(printer, theme)
{
VAnchor = VAnchor.Stretch,
HAnchor = HAnchor.Stretch
@ -429,7 +429,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
private void ProcessOptionalTab()
{
if (ApplicationController.Instance.ActivePrinter.ViewState.ConfigurePrinterVisible)
if (printer.ViewState.ConfigurePrinterVisible)
{
sideBar.AddPage(
"Printer".Localize(),
@ -451,7 +451,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
HAnchor = HAnchor.Fit | HAnchor.Center,
VAnchor = VAnchor.Top | VAnchor.Fit,
//BackgroundColor = new Color(ActiveTheme.Instance.PrimaryBackgroundColor, 128),
//BackgroundColor = new Color(theme.Colors.PrimaryBackgroundColor, 128),
MinimumSize = new Vector2(275, 140),
Selectable = false
};
@ -491,7 +491,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
VAnchor = VAnchor.Center
});
var timeWidget = new TextWidget("", pointSize: 22, textColor: ActiveTheme.Instance.PrimaryTextColor)
var timeWidget = new TextWidget("", pointSize: 22, textColor: theme.Colors.PrimaryTextColor)
{
AutoExpandBoundsToText = true,
Margin = new BorderDouble(10, 0, 0, 0),

View file

@ -48,10 +48,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
private SolidSlider layerSlider;
private double layerInfoHalfHeight;
public SliceLayerSelector(PrinterConfig printer, BedConfig sceneContext)
public SliceLayerSelector(PrinterConfig printer, BedConfig sceneContext, ThemeConfig theme)
{
var theme = ApplicationController.Instance.Theme;
this.sceneContext = sceneContext;
this.AddChild(layerScrollbar = new LayerScrollbar(printer, sceneContext)

View file

@ -35,10 +35,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
public class GridOptionsPanel : FlowLayoutWidget, IIgnoredPopupChild
{
public GridOptionsPanel(InteractionLayer interactionLayer) : base(FlowDirection.TopToBottom)
public GridOptionsPanel(InteractionLayer interactionLayer, ThemeConfig theme)
: base(FlowDirection.TopToBottom)
{
var theme = ApplicationController.Instance.Theme;
this.HAnchor = HAnchor.MaxFitOrStretch;
this.AddChild(new TextWidget("Snap Grid".Localize())

View file

@ -284,11 +284,9 @@ namespace MatterHackers.MeshVisualizer
private BedConfig sceneContext;
private double selectionHighlightWidth = 5;
private Color debugBorderColor = Color.Green;
public MeshViewerWidget(BedConfig sceneContext, InteractionLayer interactionLayer, string startingTextMessage = "", EditorType editorType = EditorType.Part)
public MeshViewerWidget(BedConfig sceneContext, InteractionLayer interactionLayer, ThemeConfig theme, EditorType editorType = EditorType.Part)
{
this.EditorMode = editorType;
this.scene = sceneContext.Scene;
@ -296,8 +294,6 @@ namespace MatterHackers.MeshVisualizer
this.interactionLayer = interactionLayer;
this.World = interactionLayer.World;
var theme = ApplicationController.Instance.Theme;
gridColors = new GridColors()
{
Gray = theme.ResolveColor(theme.ActiveTabColor, theme.GetBorderColor((theme.Colors.IsDarkTheme ? 35 : 55))),
@ -634,7 +630,6 @@ namespace MatterHackers.MeshVisualizer
double secondsSinceSelectionChanged = (UiThread.CurrentTimerMs - lastSelectionChangedMs) / 1000.0;
if (secondsSinceSelectionChanged < .5)
{
//var accentColor = ApplicationController.Instance.Theme.Colors.PrimaryAccentColor;
var accentColor = Color.LightGray;
if (secondsSinceSelectionChanged < .25)
{

View file

@ -48,6 +48,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
private SettingsContext settingsContext;
public PrintPopupMenu(PrinterConfig printer, ThemeConfig theme)
: base(theme)
{
this.printer = printer;
this.DrawArrow = true;

View file

@ -201,7 +201,8 @@ namespace MatterHackers.MatterControl.ActionBar
private static void RunTroubleShooting()
{
DialogWindow.Show<SetupWizardTroubleshooting>();
DialogWindow.Show(
new SetupWizardTroubleshooting(ApplicationController.Instance.ActivePrinter));
}
private void SetChildVisible(GuiWidget visibleChild, bool enabled)

View file

@ -112,7 +112,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
viewControls3D.TransformStateChanged += ViewControls3D_TransformStateChanged;
// MeshViewer
meshViewerWidget = new MeshViewerWidget(sceneContext, this.InteractionLayer, editorType: editorType);
meshViewerWidget = new MeshViewerWidget(sceneContext, this.InteractionLayer, theme, editorType: editorType);
meshViewerWidget.AnchorAll();
this.AddChild(meshViewerWidget);
@ -1265,7 +1265,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
this.ShowBedViewOptions(popupMenu);
popupMenu.AddChild(new GridOptionsPanel(this.InteractionLayer));
popupMenu.AddChild(new GridOptionsPanel(this.InteractionLayer, theme));
return popupMenu;
}

View file

@ -139,7 +139,7 @@ namespace MatterHackers.MatterControl.PrinterControls
var editButton = new IconButton(AggContext.StaticData.LoadIcon("icon_edit.png", 16, 16, theme.InvertIcons), theme);
editButton.Click += (s, e) =>
{
DialogWindow.Show(new EditLevelingSettingsPage(printer));
DialogWindow.Show(new EditLevelingSettingsPage(printer, theme));
};
return new SectionWidget(

View file

@ -39,10 +39,8 @@ namespace MatterHackers.MatterControl
{
public class EditLevelingSettingsPage : DialogPage
{
public EditLevelingSettingsPage(PrinterConfig printer)
public EditLevelingSettingsPage(PrinterConfig printer, ThemeConfig theme)
{
var theme = ApplicationController.Instance.Theme;
this.WindowTitle = "Leveling Settings".Localize();
this.HeaderText = "Sampled Positions".Localize();

View file

@ -44,8 +44,6 @@ namespace MatterHackers.MatterControl
public MacroDetailPage(GCodeMacro gcodeMacro, PrinterSettings printerSettings)
{
var theme = ApplicationController.Instance.Theme;
// Form validation fields
MHTextEditWidget macroNameInput;
MHTextEditWidget macroCommandInput;

View file

@ -61,10 +61,9 @@ namespace MatterHackers.MatterControl
private PrinterConfig printer;
private FlowLayoutWidget column;
public ManualPrinterControls(PrinterConfig printer)
public ManualPrinterControls(PrinterConfig printer, ThemeConfig theme)
{
this.theme = ApplicationController.Instance.Theme;
this.theme = theme;
this.printer = printer;
this.ScrollArea.HAnchor |= HAnchor.Stretch;
this.AnchorAll();

View file

@ -1,5 +1,5 @@
/*
Copyright (c) 2015, Kevin Pope
Copyright (c) 2018, Kevin Pope, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -37,18 +37,15 @@ namespace MatterHackers.MatterControl
{
private List<KeyValuePair<string, string>> listSource;
public BoundDropList(string noSelectionString, int maxHeight = 0)
: base(noSelectionString, ActiveTheme.Instance.PrimaryTextColor, maxHeight: maxHeight, pointSize: ApplicationController.Instance.Theme.DefaultFontSize)
public BoundDropList(string noSelectionString, ThemeConfig theme, int maxHeight = 0)
: base(noSelectionString, theme.Colors.PrimaryTextColor, maxHeight: maxHeight, pointSize: theme.DefaultFontSize)
{
this.BorderColor = ApplicationController.Instance.Theme.GetBorderColor(75);
this.BorderColor = theme.GetBorderColor(75);
}
public List<KeyValuePair<string, string>> ListSource
{
get
{
return listSource;
}
get => listSource;
set
{
if (listSource == value)
@ -81,4 +78,3 @@ namespace MatterHackers.MatterControl
}
}
}

View file

@ -66,7 +66,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
{
this.WindowTitle = "Setup Wizard".Localize();
printerManufacturerSelector = new BoundDropList(string.Format("- {0} -", "Select Make".Localize()), maxHeight: 200)
printerManufacturerSelector = new BoundDropList(string.Format("- {0} -", "Select Make".Localize()), theme, maxHeight: 200)
{
HAnchor = HAnchor.Stretch,
Margin = elementMargin,
@ -82,7 +82,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
"Select the printer manufacturer".Localize(),
printerManufacturerSelector);
printerModelSelector = new BoundDropList(string.Format("- {0} -", "Select Model".Localize()), maxHeight: 200)
printerModelSelector = new BoundDropList(string.Format("- {0} -", "Select Model".Localize()), theme, maxHeight: 200)
{
Name = "Select Model",
HAnchor = HAnchor.Stretch,
@ -148,7 +148,7 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
{
TextWidget printerNameLabel = new TextWidget("Name".Localize() + ":", 0, 0, 12)
{
TextColor = ActiveTheme.Instance.PrimaryTextColor,
TextColor = theme.Colors.PrimaryTextColor,
HAnchor = HAnchor.Stretch,
Margin = new BorderDouble(0, 4, 0, 1)
};
@ -161,33 +161,35 @@ namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
printerNameError = new TextWidget("", 0, 0, 10)
{
TextColor = ActiveTheme.Instance.PrimaryTextColor,
TextColor = theme.Colors.PrimaryTextColor,
HAnchor = HAnchor.Stretch,
Margin = new BorderDouble(top: 3)
};
FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.TopToBottom);
container.Margin = new BorderDouble(0, 5);
var container = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
Margin = new BorderDouble(0, 5),
HAnchor = HAnchor.Stretch
};
container.AddChild(printerNameLabel);
container.AddChild(printerNameInput);
container.AddChild(printerNameError);
container.HAnchor = HAnchor.Stretch;
return container;
}
private FlowLayoutWidget CreateSelectionContainer(string labelText, string validationMessage, Agg.UI.DropDownList selector)
private FlowLayoutWidget CreateSelectionContainer(string labelText, string validationMessage, DropDownList selector)
{
var sectionLabel = new TextWidget(labelText, 0, 0, 12)
{
TextColor = ActiveTheme.Instance.PrimaryTextColor,
TextColor = theme.Colors.PrimaryTextColor,
HAnchor = HAnchor.Stretch,
Margin = elementMargin
};
var validationTextWidget = new TextWidget(validationMessage, 0, 0, 10)
{
TextColor = ActiveTheme.Instance.PrimaryAccentColor,
TextColor = theme.Colors.PrimaryAccentColor,
HAnchor = HAnchor.Stretch,
Margin = elementMargin
};

View file

@ -46,15 +46,11 @@ namespace MatterHackers.MatterControl
private TextScrollWidget textScrollWidget;
private PrinterConfig printer;
public TerminalWidget(PrinterConfig printer)
public TerminalWidget(PrinterConfig printer, ThemeConfig theme)
: base(FlowDirection.TopToBottom)
{
this.printer = printer;
var theme = ApplicationController.Instance.Theme;
this.Name = "TerminalWidget";
this.BackgroundColor = theme.TabBodyBackground;
this.Padding = new BorderDouble(5, 0);
// Header
@ -67,7 +63,7 @@ namespace MatterHackers.MatterControl
filterOutput = new CheckBox("Filter Output".Localize(), textSize: theme.DefaultFontSize)
{
TextColor = ActiveTheme.Instance.PrimaryTextColor,
TextColor = theme.Colors.PrimaryTextColor,
VAnchor = VAnchor.Bottom,
};
filterOutput.CheckedStateChanged += (s, e) =>
@ -89,7 +85,7 @@ namespace MatterHackers.MatterControl
{
Margin = new BorderDouble(left: 25),
Checked = UserSettings.Instance.Fields.GetBool(UserSettingsKey.TerminalAutoUppercase, true),
TextColor = ActiveTheme.Instance.PrimaryTextColor,
TextColor = theme.Colors.PrimaryTextColor,
VAnchor = VAnchor.Bottom
};
autoUppercase.CheckedStateChanged += (s, e) =>
@ -105,8 +101,8 @@ namespace MatterHackers.MatterControl
textScrollWidget = new TextScrollWidget(printer, printer.Connection.TerminalLog.PrinterLines)
{
BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor,
TextColor = ActiveTheme.Instance.PrimaryTextColor,
BackgroundColor = theme.Colors.SecondaryBackgroundColor,
TextColor = theme.Colors.PrimaryTextColor,
HAnchor = HAnchor.Stretch,
VAnchor = VAnchor.Stretch,
Margin = 0,

View file

@ -56,7 +56,7 @@ namespace MatterHackers.MatterControl
public AndroidConnectDevicePage()
{
TextWidget printerNameLabel = new TextWidget("Connect Your Device".Localize() + ":", 0, 0, labelFontSize)
var printerNameLabel = new TextWidget("Connect Your Device".Localize() + ":", 0, 0, labelFontSize)
{
TextColor = ActiveTheme.Instance.PrimaryTextColor,
Margin = new BorderDouble(bottom: 10)
@ -110,7 +110,8 @@ namespace MatterHackers.MatterControl
troubleshootButton = theme.CreateLightDialogButton("Troubleshoot".Localize());
troubleshootButton.Click += (s, e) => UiThread.RunOnIdle(() =>
{
DialogWindow.ChangeToPage<SetupWizardTroubleshooting>();
DialogWindow.ChangeToPage(
new SetupWizardTroubleshooting(ApplicationController.Instance.ActivePrinter));
});
retryButtonContainer = new FlowLayoutWidget()

View file

@ -46,11 +46,13 @@ namespace MatterHackers.MatterControl
private DialogWindow()
: base(500 * GuiWidget.DeviceScale, 500 * GuiWidget.DeviceScale)
{
var theme = ApplicationController.Instance.Theme;
this.AlwaysOnTopOfMain = true;
this.MinimumSize = new Vector2(200, 200);
this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
this.BackgroundColor = theme.Colors.PrimaryBackgroundColor;
var defaultPadding = ApplicationController.Instance.Theme.DefaultContainerPadding;
var defaultPadding = theme.DefaultContainerPadding;
this.Padding = new BorderDouble(defaultPadding, defaultPadding, defaultPadding, 2);
}

View file

@ -225,7 +225,7 @@ namespace MatterHackers.MatterControl
sequence.AddImage(new ImageBuffer(1, 1));
var description = new GuiWidget();
var markdownWidget = new MarkdownWidget()
var markdownWidget = new MarkdownWidget(theme)
{
BackgroundColor = theme.ResolveColor(theme.ActiveTabColor, new Color(Color.White, 20)),
Padding = new BorderDouble(left: theme.DefaultContainerPadding / 2)
@ -302,7 +302,7 @@ namespace MatterHackers.MatterControl
private TreeNode ProcessTree(HelpArticle container)
{
var treeNode = new TreeNode(false)
var treeNode = new TreeNode(theme, false)
{
Text = container.Name,
Tag = container
@ -316,7 +316,7 @@ namespace MatterHackers.MatterControl
}
else
{
treeNode.Nodes.Add(new TreeNode(false)
treeNode.Nodes.Add(new TreeNode(theme, false)
{
Text = item.Name,
Tag = item

View file

@ -30,6 +30,7 @@ namespace MatterHackers.MatterControl
// Used in Android
private System.Threading.Timer checkForPermissionTimer;
private PrinterConfig printer;
#if __ANDROID__
private static UsbManager usbManager
@ -38,9 +39,10 @@ namespace MatterHackers.MatterControl
}
#endif
public SetupWizardTroubleshooting()
public SetupWizardTroubleshooting(PrinterConfig printer)
{
this.WindowTitle = "Troubleshooting".Localize();
this.printer = printer;
RefreshStatus();
@ -51,12 +53,12 @@ namespace MatterHackers.MatterControl
this.AddPageAction(nextButton);
// Register for connection notifications
ApplicationController.Instance.ActivePrinter.Connection.CommunicationStateChanged.RegisterEvent(ConnectionStatusChanged, ref unregisterEvents);
printer.Connection.CommunicationStateChanged.RegisterEvent(ConnectionStatusChanged, ref unregisterEvents);
}
public void ConnectionStatusChanged(object test, EventArgs args)
{
if(ApplicationController.Instance.ActivePrinter.Connection.CommunicationState == CommunicationStates.Connected && connectToPrinterRow != null)
if(printer.Connection.CommunicationState == CommunicationStates.Connected && connectToPrinterRow != null)
{
connectToPrinterRow.SetSuccessful();
nextButton.Visible = true;
@ -92,9 +94,11 @@ namespace MatterHackers.MatterControl
contentRow.CloseAllChildren();
// Regen and refresh the troubleshooting criteria
TextWidget printerNameLabel = new TextWidget(string.Format ("{0}:", "Connection Troubleshooting".Localize()), 0, 0, labelFontSize);
printerNameLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
printerNameLabel.Margin = new BorderDouble(bottom: 10);
var printerNameLabel = new TextWidget(string.Format("{0}:", "Connection Troubleshooting".Localize()), 0, 0, labelFontSize)
{
TextColor = theme.Colors.PrimaryTextColor,
Margin = new BorderDouble(bottom: 10)
};
#if __ANDROID__
IUsbSerialPort serialPort = FrostedSerialPort.LoadSerialDriver(null);
@ -181,19 +185,22 @@ namespace MatterHackers.MatterControl
"Connect".Localize(),
"Click the 'Connect' button to retry the original connection attempt".Localize(),
false,
() => ApplicationController.Instance.ActivePrinter.Connection.Connect());
() => printer.Connection.Connect(),
theme);
contentRow.AddChild(connectToPrinterRow);
if (CriteriaRow.ActiveErrorItem != null) {
FlowLayoutWidget errorText = new FlowLayoutWidget () {
var errorText = new FlowLayoutWidget () {
Padding = new BorderDouble (0, 15)
};
errorText.AddChild(new TextWidget(CriteriaRow.ActiveErrorItem.ErrorText) {
TextColor = ActiveTheme.Instance.PrimaryAccentColor
});
errorText.AddChild(
new TextWidget(CriteriaRow.ActiveErrorItem.ErrorText)
{
TextColor = theme.Colors.PrimaryAccentColor
});
contentRow.AddChild(errorText);
}
@ -213,7 +220,7 @@ namespace MatterHackers.MatterControl
private static Color disabledBackColor = new Color(0.22, 0.22, 0.22);
private static Color toggleColor = new Color(Color.Gray.red + 2, Color.Gray.green + 2, Color.Gray.blue + 2);
public CriteriaRow (string itemText, string fixitText, string errorText, bool succeeded, Action fixAction)
public CriteriaRow (string itemText, string fixitText, string errorText, bool succeeded, Action fixAction, ThemeConfig theme)
: base(FlowDirection.LeftToRight)
{
HAnchor = HAnchor.Stretch;
@ -242,7 +249,7 @@ namespace MatterHackers.MatterControl
AddSuccessIcon();
} else {
// Add Fix button
var button = ApplicationController.Instance.Theme.CreateDialogButton(fixitText);
var button = theme.CreateDialogButton(fixitText);
button.VAnchor = VAnchor.Center;
button.Padding = new BorderDouble(3, 8);
button.Click += (s, e) => fixAction?.Invoke();

View file

@ -140,7 +140,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
},
presetsContext.LayerType);
return new SliceSettingsWidget(printer, settingsContext, ApplicationController.Instance.Theme)
return new SliceSettingsWidget(printer, settingsContext, theme)
{
ShowControlBar = false
};

View file

@ -202,7 +202,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
this.TabBar.Padding = this.TabBar.Margin.Clone(right: theme.ToolbarPadding.Right);
searchPanel = new SearchInputBox()
searchPanel = new SearchInputBox(theme)
{
Visible = false,
BackgroundColor = theme.TabBarBackground,
@ -788,7 +788,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
break;
case SliceSettingData.DataEditTypes.LIST:
uiField = new ListField()
uiField = new ListField(theme)
{
ListItems = settingData.ListValues.Split(',').ToList()
};
@ -808,7 +808,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
break;
#if !__ANDROID__
case SliceSettingData.DataEditTypes.IP_LIST:
uiField = new IpAddessField(printer);
uiField = new IpAddessField(printer, theme);
break;
#endif
@ -857,7 +857,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
if (settingData.QuickMenuSettings.Count > 0
&& settingData.SlicerConfigName == "baud_rate")
{
var dropMenu = new DropMenuWrappedField(uiField, settingData, theme.Colors.PrimaryTextColor);
var dropMenu = new DropMenuWrappedField(uiField, settingData, theme.Colors.PrimaryTextColor, theme);
dropMenu.Initialize(tabIndexForItem);
settingsRow.AddContent(dropMenu.Content);

View file

@ -38,11 +38,15 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public class DirectionVectorField : UIField
{
private DropDownList dropDownList;
private ThemeConfig theme;
public DirectionVectorField(ThemeConfig theme)
{
this.theme = theme;
}
public override void Initialize(int tabIndex)
{
var theme = ApplicationController.Instance.Theme;
dropDownList = new DropDownList("Name".Localize(), theme.Colors.PrimaryTextColor, Direction.Down, pointSize: theme.DefaultFontSize)
{
BorderColor = theme.GetBorderColor(75)

View file

@ -37,13 +37,15 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
{
private UIField uiField;
private Color textColor;
private ThemeConfig theme;
private SliceSettingData settingData;
public DropMenuWrappedField(UIField uiField, SliceSettingData settingData, Color textColor)
public DropMenuWrappedField(UIField uiField, SliceSettingData settingData, Color textColor, ThemeConfig theme)
{
this.settingData = settingData;
this.uiField = uiField;
this.textColor = textColor;
this.theme = theme;
}
public void SetValue(string newValue, bool userInitiated)
@ -60,7 +62,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public void Initialize(int tabIndex)
{
var totalContent = new FlowLayoutWidget();
var theme = ApplicationController.Instance.Theme;
var selectableOptions = new DropDownList("Custom", textColor, maxHeight: 200, pointSize: theme.DefaultFontSize)
{

View file

@ -38,17 +38,17 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public class EnumField : UIField
{
private EditableProperty property;
private ThemeConfig theme;
private DropDownList dropDownList;
public EnumField(EditableProperty property)
public EnumField(EditableProperty property, ThemeConfig theme)
{
this.property = property;
this.theme = theme;
}
public override void Initialize(int tabIndex)
{
var theme = ApplicationController.Instance.Theme;
// Enum keyed on name to friendly name
var enumItems = Enum.GetNames(property.PropertyType).Select(enumName =>
{

View file

@ -43,11 +43,13 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
{
private EditableProperty property;
private IconsAttribute iconsAttribute;
private ThemeConfig theme;
public IconEnumField(EditableProperty property, IconsAttribute iconsAttribute)
public IconEnumField(EditableProperty property, IconsAttribute iconsAttribute, ThemeConfig theme)
{
this.property = property;
this.iconsAttribute = iconsAttribute;
this.theme = theme;
}
// TODO: Violates UIField norms but consistent with past behavior - state is only correct at construction time, often reconstructed
@ -55,8 +57,6 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public override void Initialize(int tabIndex)
{
var theme = ApplicationController.Instance.Theme;
// Enum keyed on name to friendly name
var enumItems = Enum.GetNames(property.PropertyType).Select(enumName =>
{

View file

@ -20,18 +20,18 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
private IconButton refreshButton;
private PrinterConfig printer;
private ThemeConfig theme;
public IpAddessField(PrinterConfig printer)
public IpAddessField(PrinterConfig printer, ThemeConfig theme)
{
this.printer = printer;
this.theme = theme;
}
public override void Initialize(int tabIndex)
{
EventHandler unregisterEvents = null;
var theme = ApplicationController.Instance.Theme;
base.Initialize(tabIndex);
bool canChangeComPort = !printer.Connection.IsConnected && printer.Connection.CommunicationState != CommunicationStates.AttemptingToConnect;
//This setting defaults to Manual
@ -72,7 +72,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
var widget = new FlowLayoutWidget();
widget.AddChild(dropdownList);
refreshButton = new IconButton(AggContext.StaticData.LoadIcon("fa-refresh_14.png", theme.InvertIcons), ApplicationController.Instance.Theme)
refreshButton = new IconButton(AggContext.StaticData.LoadIcon("fa-refresh_14.png", theme.InvertIcons), theme)
{
Margin = new BorderDouble(left: 5)
};

View file

@ -38,12 +38,17 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
public class ListField : UIField
{
private DropDownList dropdownList;
private ThemeConfig theme;
public List<string> ListItems { get; set; }
public ListField(ThemeConfig theme)
{
this.theme = theme;
}
public override void Initialize(int tabIndex)
{
var theme = ApplicationController.Instance.Theme;
dropdownList = new DropDownList("None".Localize(), theme.Colors.PrimaryTextColor, maxHeight: 200, pointSize: theme.DefaultFontSize)
{
ToolTipText = this.HelpText,

View file

@ -23,8 +23,9 @@ namespace MatterControl.Tests.MatterControl
BoundDropList dropList;
var theme = new ThemeConfig();
// Whitelist on non-OEM builds should contain all printers
dropList = new BoundDropList("Test");
dropList = new BoundDropList("Test", theme);
dropList.ListSource = allManufacturers;
Assert.Greater(dropList.MenuItems.Count, 20);
@ -32,14 +33,14 @@ namespace MatterControl.Tests.MatterControl
OemSettings.Instance.SetManufacturers(allManufacturers, whitelist);
dropList = new BoundDropList("Test");
dropList = new BoundDropList("Test", theme);
dropList.ListSource = OemSettings.Instance.AllOems;
Assert.AreEqual(1, dropList.MenuItems.Count);
whitelist.Add("Airwolf 3D");
OemSettings.Instance.SetManufacturers(allManufacturers, whitelist);
dropList = new BoundDropList("Test");
dropList = new BoundDropList("Test", theme);
dropList.ListSource = OemSettings.Instance.AllOems;
Assert.AreEqual(2, dropList.MenuItems.Count);

View file

@ -11,25 +11,34 @@ namespace Markdig.Renderers.Agg
{
public class CodeBlockX : FlowLeftRightWithWrapping
{
public CodeBlockX()
private ThemeConfig theme;
public CodeBlockX(ThemeConfig theme)
{
var theme = ApplicationController.Instance.Theme;
HAnchor = HAnchor.Stretch;
VAnchor = VAnchor.Fit;
Margin = 12;
Padding = 6;
BackgroundColor = theme.MinimalShade;
this.theme = theme;
this.HAnchor = HAnchor.Stretch;
this.VAnchor = VAnchor.Fit;
this.Margin = 12;
this.Padding = 6;
this.BackgroundColor = theme.MinimalShade;
}
}
public class AggCodeBlockRenderer : AggObjectRenderer<CodeBlock>
{
private ThemeConfig theme;
public AggCodeBlockRenderer(ThemeConfig theme)
{
this.theme = theme;
}
protected override void Write(AggRenderer renderer, CodeBlock obj)
{
//var paragraph = new Paragraph();
//paragraph.SetResourceReference(FrameworkContentElement.StyleProperty, Styles.CodeBlockStyleKey);
renderer.Push(new CodeBlockX());
renderer.Push(new CodeBlockX(theme));
renderer.WriteLeafRawLines(obj);
renderer.Pop();
}

View file

@ -1,21 +1,17 @@
// Copyright (c) 2016-2017 Nicolas Musset. All rights reserved.
// This file is licensed under the MIT license.
// This file is licensed under the MIT license.
// See the LICENSE.md file in the project root for more information.
using Markdig.Syntax;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.MatterControl;
namespace Markdig.Renderers.Agg
{
public class HeadingRowX : FlowLeftRightWithWrapping
{
public override HAnchor HAnchor { get => base.HAnchor; set => base.HAnchor = value; }
public HeadingRowX()
{
var theme = ApplicationController.Instance.Theme;
this.VAnchor = VAnchor.Fit;
this.HAnchor = HAnchor.Stretch;
this.Margin = new BorderDouble(0, 4, 0, 12);
@ -34,30 +30,30 @@ namespace Markdig.Renderers.Agg
}
public class AggHeadingRenderer : AggObjectRenderer<HeadingBlock>
{
protected override void Write(AggRenderer renderer, HeadingBlock obj)
{
//var paragraph = new Paragraph();
//ComponentResourceKey styleKey = null;
{
protected override void Write(AggRenderer renderer, HeadingBlock obj)
{
//var paragraph = new Paragraph();
//ComponentResourceKey styleKey = null;
//switch (obj.Level)
//{
// case 1: styleKey = Styles.Heading1StyleKey; break;
// case 2: styleKey = Styles.Heading2StyleKey; break;
// case 3: styleKey = Styles.Heading3StyleKey; break;
// case 4: styleKey = Styles.Heading4StyleKey; break;
// case 5: styleKey = Styles.Heading5StyleKey; break;
// case 6: styleKey = Styles.Heading6StyleKey; break;
//}
//switch (obj.Level)
//{
// case 1: styleKey = Styles.Heading1StyleKey; break;
// case 2: styleKey = Styles.Heading2StyleKey; break;
// case 3: styleKey = Styles.Heading3StyleKey; break;
// case 4: styleKey = Styles.Heading4StyleKey; break;
// case 5: styleKey = Styles.Heading5StyleKey; break;
// case 6: styleKey = Styles.Heading6StyleKey; break;
//}
//if (styleKey != null)
//{
// paragraph.SetResourceReference(FrameworkContentElement.StyleProperty, styleKey);
//}
//if (styleKey != null)
//{
// paragraph.SetResourceReference(FrameworkContentElement.StyleProperty, styleKey);
//}
renderer.Push(new HeadingRowX()); // paragraph);
renderer.WriteLeafInline(obj);
renderer.Pop();
}
}
renderer.WriteLeafInline(obj);
renderer.Pop();
}
}
}

View file

@ -15,8 +15,6 @@ namespace Markdig.Renderers.Agg
public ListX()
: base(FlowDirection.TopToBottom)
{
var theme = ApplicationController.Instance.Theme;
this.VAnchor = VAnchor.Fit;
this.HAnchor = HAnchor.Stretch;
}
@ -36,10 +34,8 @@ namespace Markdig.Renderers.Agg
public class ListItemX : FlowLayoutWidget
{
private FlowLayoutWidget content;
public ListItemX()
public ListItemX(ThemeConfig theme)
{
var theme = ApplicationController.Instance.Theme;
this.VAnchor = VAnchor.Fit;
this.HAnchor = HAnchor.Stretch;
@ -64,6 +60,13 @@ namespace Markdig.Renderers.Agg
public class AggListRenderer : AggObjectRenderer<ListBlock>
{
private ThemeConfig theme;
public AggListRenderer(ThemeConfig theme)
{
this.theme = theme;
}
protected override void Write(AggRenderer renderer, ListBlock listBlock)
{
//var list = new List();
@ -86,7 +89,7 @@ namespace Markdig.Renderers.Agg
foreach (var item in listBlock)
{
renderer.Push(new ListItemX());
renderer.Push(new ListItemX(theme));
renderer.WriteChildren(item as ListItemBlock);
renderer.Pop();
}

View file

@ -18,8 +18,8 @@ namespace Markdig.Renderers
{
public class TextWordX : TextWidget
{
public TextWordX()
: base("", pointSize: 10, textColor: ApplicationController.Instance.Theme.Colors.PrimaryTextColor)
public TextWordX(ThemeConfig theme)
: base("", pointSize: 10, textColor: theme.Colors.PrimaryTextColor)
{
this.AutoExpandBoundsToText = true;
}
@ -49,12 +49,18 @@ namespace Markdig.Renderers
{
private readonly Stack<GuiWidget> stack = new Stack<GuiWidget>();
private char[] buffer;
private ThemeConfig theme;
public GuiWidget RootWidget { get; }
public Uri BaseUri { get; set; }
public List<MarkdownDocumentLink> ChildLinks { get; internal set; }
public AggRenderer(ThemeConfig theme)
{
this.theme = theme;
}
public AggRenderer(GuiWidget rootWidget)
{
buffer = new char[1024];
@ -63,8 +69,8 @@ namespace Markdig.Renderers
stack.Push(rootWidget);
// Default block renderers
ObjectRenderers.Add(new AggCodeBlockRenderer());
ObjectRenderers.Add(new AggListRenderer());
ObjectRenderers.Add(new AggCodeBlockRenderer(theme));
ObjectRenderers.Add(new AggListRenderer(theme));
ObjectRenderers.Add(new AggHeadingRenderer());
ObjectRenderers.Add(new AggParagraphRenderer());
ObjectRenderers.Add(new AggQuoteBlockRenderer());
@ -174,16 +180,21 @@ namespace Markdig.Renderers
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void WriteText(string text)
{
// TODO: Is this debugging? Debug.WriteLine()?
var words = text.Split(' ');
bool first = true;
foreach (var word in words)
{
if(!first)
{
WriteInline(new TextSpaceX { Text = " " });
}
WriteInline(new TextWordX { Text = word });
WriteInline(new TextWordX (theme)
{
Text = word
});
first = false;
}
}
@ -191,7 +202,9 @@ namespace Markdig.Renderers
internal void WriteText(string text, int offset, int length)
{
if (text == null)
{
return;
}
if (offset == 0 && text.Length == length)
{

View file

@ -39,6 +39,7 @@ namespace Markdig.Agg
this.WindowTitle = this.HeaderText = "Markdown Tests";
contentRow.AddChild(
new MarkdownWidget(
theme,
new Uri("https://raw.githubusercontent.com/lunet-io/markdig/master/readme.md")));
}
}

View file

@ -43,20 +43,22 @@ namespace Markdig.Agg
private FlowLayoutWidget contentPanel;
private AggMarkdownDocument markdownDocument;
private ThemeConfig theme;
public MarkdownWidget(Uri contentUri, bool scrollContent = true)
: this(scrollContent)
public MarkdownWidget(ThemeConfig theme, Uri contentUri, bool scrollContent = true)
: this(theme, scrollContent)
{
markdownDocument.BaseUri = contentUri;
this.LoadUri(contentUri);
}
public MarkdownWidget(bool scrollContent = true)
public MarkdownWidget(ThemeConfig theme, bool scrollContent = true)
: base(scrollContent)
{
markdownDocument = new AggMarkdownDocument();
this.theme = theme;
this.HAnchor = HAnchor.Stretch;
this.ScrollArea.HAnchor = HAnchor.Stretch;
@ -114,8 +116,6 @@ namespace Markdig.Agg
this.Width = 10;
this.ScrollPositionFromTop = Vector2.Zero;
var theme = ApplicationController.Instance.Theme;
// Add header/edit button for HelpArticle pages
if (sourceArticle != null)
{