private void AddContentItem(FeedSectionData content) { switch (content.content_type) { case "headline": { break; // use the Golden Ratio to calculate an attractive size relative to the banner var image = new ImageBuffer(1520, (int)(170 / 1.618)); var imageWidget = new ResponsiveImageWidget(image) { Margin = new BorderDouble(5), Cursor = Cursors.Hand }; var graphics2D = image.NewGraphics2D(); image.SetRecieveBlender(new BlenderPreMultBGRA()); graphics2D.Clear(theme.AccentMimimalOverlay); // use the Golden Ratio to calculate an attractive size for the text relative to the text banner var pixelsPerPoint = 96.0 / 72.0; var goalPointSize = image.Height / pixelsPerPoint / 1.618; var printer = new TypeFacePrinter(content.text, goalPointSize); graphics2D.DrawString(content.text, image.Width / 2, image.Height / 2 + printer.TypeFaceStyle.EmSizeInPixels / 2, goalPointSize, Justification.Center, Baseline.BoundsTop, theme.TextColor); if (content.link != null) { imageWidget.Cursor = Cursors.Hand; imageWidget.Click += (s, e) => { if (e.Button == MouseButtons.Left) { ApplicationController.Instance.LaunchBrowser(content.link); } }; } this.AddChild(imageWidget); } break; case "banner_rotate": // TODO: make this make a carousel rather than add the first item and rotate between all the items var rand = new Random(); AddContentItem(content.banner_list[rand.Next(content.banner_list.Count)]); break; case "banner_image": { // Our banners seem to end with something like "=w1520-h170" // if present use that to get the right width and height int expectedWidth = 1520; GCodeFile.GetFirstNumberAfter("=w", content.image_url, ref expectedWidth); int expectedHeight = 170; GCodeFile.GetFirstNumberAfter("-h", content.image_url, ref expectedHeight); if ((content.theme_filter == "dark" && theme.IsDarkTheme) || (content.theme_filter == "light" && !theme.IsDarkTheme) || (content.theme_filter == "all")) { var image = new ImageBuffer(expectedWidth, expectedHeight); var imageWidget = new ResponsiveImageWidget(image) { Margin = new BorderDouble(5), Cursor = Cursors.Hand }; if (content.link != null) { imageWidget.Cursor = Cursors.Hand; imageWidget.Click += (s, e) => { if (e.Button == MouseButtons.Left) { ApplicationController.Instance.LaunchBrowser(content.link); } }; } imageWidget.Load += (s, e) => WebCache.RetrieveImageAsync(image, content.image_url, false, new BlenderPreMultBGRA()); this.AddChild(imageWidget); } } break; case "article_group": case "product_group": if (currentContentContainer == null) { currentContentContainer = new FlowLeftRightWithWrapping(); this.AddChild(currentContentContainer); } currentContentContainer.AddChild(new ExploreSection(content, theme)); break; } }
public ProductItem(FeedItemData item, ThemeConfig theme) : base(FlowDirection.TopToBottom) { this.Padding = ItemSpacing; this.item = item; this.theme = theme; var image = new ImageBuffer(IconSize, IconSize); image.SetRecieveBlender(new BlenderPreMultBGRA()); BackgroundRadius = 5 * GuiWidget.DeviceScale; if (item.widget_url != null) { var whiteBackground = new GuiWidget(IconSize, IconSize) { // these images expect to be on white so change the background to white BackgroundColor = Color.White, BackgroundRadius = 5 * GuiWidget.DeviceScale, Margin = new BorderDouble(3, 0, 3, 3), Selectable = false }; this.AddChild(whiteBackground); var imageWidget = new ImageWidget(image) { Selectable = false, VAnchor = VAnchor.Center, }; Load += (s, e) => WebCache.RetrieveImageAsync(image, item.widget_url, true); whiteBackground.AddChild(imageWidget); } var titleText = new FlowLeftRightWithWrapping() { Selectable = false, VAnchor = VAnchor.Fit, HAnchor = HAnchor.Stretch, Margin = new BorderDouble(3, 3, 3, 9), Center = true }; titleText.AddText(item.title, textColor: theme.TextColor, pointSize: theme.FontSize14); this.AddChild(titleText); var descriptionText = new FlowLeftRightWithWrapping() { Selectable = false, VAnchor = VAnchor.Fit, HAnchor = HAnchor.Stretch, Margin = 3, Center = true }; descriptionText.AddText(item.subtitle, textColor: theme.TextColor.WithAlpha(.7), pointSize: theme.FontSize8); this.AddChild(descriptionText); this.Cursor = Cursors.Hand; this.VAnchor = VAnchor.Fit | VAnchor.Top; }