public override void Render(CellContext context, StateType state, double cellWidth, double cellHeight, CellPosition position) { CellPosition editPos = ParentColumn.ParentListView.EditedCell; if (editPos == position) { entry.SizeRequest(); entry.SizeAllocate(context.Area); if (restartEdit) { entry.SelectRegion(0, -1); entry.HasFocus = true; entry.GrabFocus(); restartEdit = false; } entry.Show(); } else { string cellText = ObjectToString(boundObject); if (string.IsNullOrEmpty(cellText)) { return; } PangoStyle style = parentColumn.ParentListView.QueryCellStyle(state, position); context.Layout.Width = (int)((cellWidth - hPadding * 2) * Pango.Scale.PangoScale); context.Layout.Ellipsize = EllipsizeMode; context.Layout.Alignment = alignment; context.Layout.SetMarkup(style.GetMarkup(cellText)); int text_width; int text_height; context.Layout.GetPixelSize(out text_width, out text_height); context.Context.MoveTo(hPadding, ((int)cellHeight - text_height) / 2); Cairo.Color color = context.Theme.Colors.GetWidgetColor( context.TextAsForeground ? GtkColorClass.Foreground : GtkColorClass.Text, state); color.A = context.Sensitive ? 1.0 : 0.3; context.Context.Color = color; context.Context.ShowLayout(context.Layout); } }
private void SetupPangoLayout(string text, ObjectFont font, StringTrimming trimming, double?width) { PangoStyle style = new PangoStyle { ExactSize = font.Size, FontFamily = DataHelper.GetPreferredFont(text) ?? (font.NameSpecified ? font.Name : DataHelper.DefaultDocumentsFont) }; if (font.Italic) { style.Italic = true; } if (font.Bold) { style.Bold = true; } if (font.Underline) { style.Underline = true; } if (font.StrikeThrought) { style.Strikethrough = true; } pangoLayout.SetMarkup(style.GetMarkup(text)); pangoLayout.Ellipsize = EllipsizeMode.None; pangoLayout.Wrap = WrapMode.Word; if (width != null) { pangoLayout.Width = (int)(width * Scale.PangoScale); } else { pangoLayout.Width = -1; if (trimming != StringTrimming.None) { pangoLayout.Ellipsize = EllipsizeMode.End; } } }
public override void Render(CellContext context, StateType state, double cellWidth, double cellHeight, CellPosition position) { PangoStyle style = parentColumn.ParentListView.QueryCellStyle(state, position); context.Layout.Width = (int)((cellWidth - hPadding * 2) * Pango.Scale.PangoScale); context.Layout.Ellipsize = EllipsizeMode; context.Layout.Alignment = alignment; context.Layout.SetMarkup(style.GetMarkup((firstRow + position.Row).ToString())); int text_width; int text_height; context.Layout.GetPixelSize(out text_width, out text_height); context.Context.MoveTo(hPadding, ((int)cellHeight - text_height) / 2); Cairo.Color color = context.Theme.Colors.GetWidgetColor( context.TextAsForeground ? GtkColorClass.Foreground : GtkColorClass.Text, state); color.A = context.Sensitive ? 1.0 : 0.3; context.Context.Color = color; context.Context.ShowLayout(context.Layout); }
public override void Render(CellContext context, StateType state, double cellWidth, double cellHeight, CellPosition position) { Context cairo = context.Context; double x = 1.5; double y = 1.5; double r = 1; cellWidth -= 3; cellHeight -= 3; // Draw backgound fill LinearGradient bgPattern = new LinearGradient(0, 0, 0, cellHeight); bgPattern.AddColorStop(0.0, new Color(219 / 255d, 219 / 255d, 219 / 255d)); bgPattern.AddColorStop(0.2, new Color(233 / 255d, 233 / 255d, 233 / 255d)); bgPattern.AddColorStop(0.2, new Color(221 / 255d, 221 / 255d, 221 / 255d)); bgPattern.AddColorStop(0.3, new Color(221 / 255d, 221 / 255d, 221 / 255d)); bgPattern.AddColorStop(0.3, new Color(218 / 255d, 218 / 255d, 218 / 255d)); bgPattern.AddColorStop(0.4, new Color(218 / 255d, 218 / 255d, 218 / 255d)); bgPattern.AddColorStop(0.8, new Color(250 / 255d, 250 / 255d, 250 / 255d)); bgPattern.AddColorStop(1.0, new Color(221 / 255d, 221 / 255d, 221 / 255d)); cairo.Pattern = bgPattern; cairo.RoundedRectangle(x - 0.5, y - 0.5, cellWidth + 1, cellHeight + 1, r); cairo.Fill(); // Draw frame cairo.LineWidth = 1; cairo.Color = new Color(181 / 255d, 181 / 255d, 181 / 255d); cairo.MoveTo(x + r, y); cairo.Arc(x + cellWidth - r, y + r, r, Math.PI * 1.5, Math.PI * 2); cairo.Stroke(); cairo.Color = new Color(215 / 255d, 215 / 255d, 215 / 255d); cairo.MoveTo(x + cellWidth, y + r); cairo.Arc(x + cellWidth - r, y + cellHeight - r, r, 0, Math.PI * 0.5); cairo.Stroke(); cairo.Color = new Color(181 / 255d, 181 / 255d, 181 / 255d); cairo.MoveTo(x + cellWidth - r, y + cellHeight); cairo.Arc(x + r, y + cellHeight - r, r, Math.PI * 0.5, Math.PI); cairo.Stroke(); cairo.Color = new Color(215 / 255d, 215 / 255d, 215 / 255d); cairo.MoveTo(x, y + cellHeight - r); cairo.Arc(x + r, y + r, r, Math.PI, Math.PI * 1.5); cairo.Stroke(); // Draw progress fill double progressWidth = (cellWidth - 1) * Math.Max(Math.Min(double.IsNaN(progressValue) ? 0 : progressValue, 1), 0); LinearGradient fillPattern = new LinearGradient(0, 0, 0, cellHeight); fillPattern.AddColorStop(0.0, new Color(128 / 255d, 168 / 255d, 121 / 255d)); fillPattern.AddColorStop(0.1, new Color(128 / 255d, 168 / 255d, 121 / 255d)); fillPattern.AddColorStop(0.2, new Color(146 / 255d, 186 / 255d, 229 / 255d)); fillPattern.AddColorStop(0.4, new Color(83 / 255d, 149 / 255d, 223 / 255d)); fillPattern.AddColorStop(0.5, new Color(66 / 255d, 143 / 255d, 231 / 255d)); fillPattern.AddColorStop(0.8, new Color(119 / 255d, 201 / 255d, 255 / 255d)); fillPattern.AddColorStop(1.0, new Color(125 / 255d, 191 / 255d, 255 / 255d)); cairo.Pattern = fillPattern; cairo.Rectangle(x + 0.5, y - 0.5, progressWidth, cellHeight); cairo.Fill(); cairo.MoveTo(x + 0.5, y); cairo.LineTo(x + progressWidth, y); cairo.Color = new Color(53 / 255d, 100 / 255d, 191 / 255d); cairo.Stroke(); // Draw text PangoStyle style = parentColumn.ParentListView.QueryCellStyle(state, position); const double hPadding = 4; context.Layout.Width = (int)((cellWidth - hPadding * 2) * Pango.Scale.PangoScale); context.Layout.Ellipsize = EllipsizeMode.End; context.Layout.Alignment = Alignment.Center; context.Layout.SetMarkup(style.GetMarkup(ObjectToString(boundObject))); int text_width; int text_height; context.Layout.GetPixelSize(out text_width, out text_height); cairo.MoveTo(x + hPadding, y + ((int)cellHeight - text_height) / 2); Color color = context.Theme.Colors.GetWidgetColor( context.TextAsForeground ? GtkColorClass.Foreground : GtkColorClass.Text, StateType.Normal); color.A = context.Sensitive ? 1.0 : 0.3; cairo.Color = color; cairo.ShowLayout(context.Layout); }