[longomatch] Adjust labels width to the longuest name
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Adjust labels width to the longuest name
- Date: Tue, 28 Oct 2014 09:50:47 +0000 (UTC)
commit 500abeb7d2d52479f6ee76f93c6fd6aeea7307ef
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Tue Oct 21 23:50:24 2014 +0200
Adjust labels width to the longuest name
LongoMatch.Drawing/CanvasObjects/LabelObject.cs | 46 +++++++++++++++++-----
LongoMatch.Drawing/Widgets/TimelineLabels.cs | 10 ++++-
LongoMatch.GUI/Gui/Component/Timeline.cs | 3 +
3 files changed, 47 insertions(+), 12 deletions(-)
---
diff --git a/LongoMatch.Drawing/CanvasObjects/LabelObject.cs b/LongoMatch.Drawing/CanvasObjects/LabelObject.cs
index 729b398..2589181 100644
--- a/LongoMatch.Drawing/CanvasObjects/LabelObject.cs
+++ b/LongoMatch.Drawing/CanvasObjects/LabelObject.cs
@@ -24,12 +24,12 @@ namespace LongoMatch.Drawing.CanvasObjects
{
public class LabelObject: CanvasObject, ICanvasObject
{
- double width;
+ int DEFAULT_FONT_SIZE = 12;
public LabelObject (double width, double height, double offsetY)
{
- this.Height = height;
- this.width = width;
+ Height = height;
+ Width = width;
OffsetY = offsetY;
Color = Color.Red1;
}
@@ -44,11 +44,26 @@ namespace LongoMatch.Drawing.CanvasObjects
set;
}
+ public double Width {
+ get;
+ set;
+ }
+
public double Height {
get;
set;
}
+ public double RequiredWidth {
+ get {
+ int width, height;
+ Config.DrawingToolkit.MeasureText (
+ Name, out width, out height, "Ubuntu",
+ DEFAULT_FONT_SIZE, FontWeight.Normal);
+ return TextOffset + width;
+ }
+ }
+
public double Scroll {
get;
set;
@@ -64,36 +79,45 @@ namespace LongoMatch.Drawing.CanvasObjects
get;
}
+ double RectSize {
+ get {
+ return Height - StyleConf.TimelineLabelVSpacing * 2;
+ }
+ }
+
+ double TextOffset {
+ get {
+ return StyleConf.TimelineLabelHSpacing * 2 + RectSize;
+ }
+ }
+
public override void Draw (IDrawingToolkit tk, Area area)
{
- double hs, vs, to, rectSize;
+ double hs, vs;
double y;
hs = StyleConf.TimelineLabelHSpacing;
vs = StyleConf.TimelineLabelVSpacing;
- rectSize = Height - vs * 2;
- to = hs + rectSize + hs;
-
y = OffsetY - Math.Floor (Scroll);
tk.Begin ();
tk.FillColor = BackgroundColor;
tk.StrokeColor = BackgroundColor;
tk.LineWidth = 0;
- tk.DrawRectangle (new Point (0, y), width, Height);
+ tk.DrawRectangle (new Point (0, y), Width, Height);
/* Draw a rectangle with the category color */
tk.FillColor = Color;
tk.StrokeColor = Color;
- tk.DrawRectangle (new Point (hs, y + vs), rectSize, rectSize);
+ tk.DrawRectangle (new Point (hs, y + vs), RectSize, RectSize);
/* Draw category name */
tk.FontSlant = FontSlant.Normal;
tk.FontWeight = FontWeight.Bold;
- tk.FontSize = 12;
+ tk.FontSize = DEFAULT_FONT_SIZE;
tk.FillColor = Config.Style.PaletteWidgets;
tk.FontAlignment = FontAlignment.Left;
tk.StrokeColor = Config.Style.PaletteWidgets;
- tk.DrawText (new Point (to, y), width - to, Height, Name);
+ tk.DrawText (new Point (TextOffset, y), Width - TextOffset, Height, Name);
tk.End ();
}
}
diff --git a/LongoMatch.Drawing/Widgets/TimelineLabels.cs b/LongoMatch.Drawing/Widgets/TimelineLabels.cs
index 6170185..bcf4642 100644
--- a/LongoMatch.Drawing/Widgets/TimelineLabels.cs
+++ b/LongoMatch.Drawing/Widgets/TimelineLabels.cs
@@ -16,6 +16,7 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
//
using System;
+using System.Linq;
using System.Collections.Generic;
using LongoMatch.Core.Store;
using LongoMatch.Core.Interfaces.Drawing;
@@ -67,7 +68,8 @@ namespace LongoMatch.Drawing.Widgets
{
LabelObject l;
int i = 0, w, h;
-
+ double requiredWidth;
+
w = StyleConf.TimelineLabelsWidth;
h = StyleConf.TimelineCategoryHeight;
widget.Width = w;
@@ -89,6 +91,12 @@ namespace LongoMatch.Drawing.Widgets
AddLabel (l, eventType);
i++;
}
+
+ requiredWidth = labelToObject.Keys.Max (la => la.RequiredWidth);
+ foreach (LabelObject lo in labelToObject.Keys) {
+ lo.Width = requiredWidth;
+ }
+ widget.Width = requiredWidth;
}
void UpdateVisibleCategories ()
diff --git a/LongoMatch.GUI/Gui/Component/Timeline.cs b/LongoMatch.GUI/Gui/Component/Timeline.cs
index e84678b..bd1c1ae 100644
--- a/LongoMatch.GUI/Gui/Component/Timeline.cs
+++ b/LongoMatch.GUI/Gui/Component/Timeline.cs
@@ -59,6 +59,9 @@ namespace LongoMatch.Gui.Component
focusscale.ValueChanged += HandleValueChanged;
timerulearea.HeightRequest = LongoMatch.Drawing.Constants.TIMERULE_HEIGHT;
leftbox.WidthRequest = StyleConf.TimelineLabelsWidth;
+ labelsarea.SizeRequested += (o, args) => {
+ leftbox.WidthRequest = args.Requisition.Width;
+ };
hbox1.HeightRequest = LongoMatch.Drawing.Constants.TIMERULE_HEIGHT;
scrolledwindow1.Vadjustment.ValueChanged += HandleScrollEvent;
scrolledwindow1.Hadjustment.ValueChanged += HandleScrollEvent;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]