Fix dropdown lists. Visual tweaks.
This commit is contained in:
@@ -152,25 +152,23 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
public static void ShowDropDown<T>(Widget w, IEnumerable<T> ts, Func<T, int, LabelWidget> ft)
|
public static void ShowDropDown<T>(Widget w, IEnumerable<T> ts, Func<T, int, LabelWidget> ft)
|
||||||
{
|
{
|
||||||
var dropDown = new ScrollPanelWidget
|
var dropDown = new ScrollPanelWidget()
|
||||||
{
|
{
|
||||||
Bounds = new Rectangle(w.RenderOrigin.X, w.RenderOrigin.Y + w.Bounds.Height, w.Bounds.Width, 100),
|
Bounds = new Rectangle(w.RenderOrigin.X, w.RenderOrigin.Y + w.Bounds.Height, w.Bounds.Width, 100),
|
||||||
Visible = true,
|
Visible = true,
|
||||||
ClickThrough = false,
|
ClickThrough = false,
|
||||||
OnMouseUp = mi => true,
|
OnMouseUp = mi => true,
|
||||||
|
ItemSpacing = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
var y = 0;
|
|
||||||
List<LabelWidget> items = new List<LabelWidget>();
|
List<LabelWidget> items = new List<LabelWidget>();
|
||||||
List<Widget> dismissAfter = new List<Widget>();
|
List<Widget> dismissAfter = new List<Widget>();
|
||||||
foreach (var t in ts)
|
foreach (var t in ts)
|
||||||
{
|
{
|
||||||
var ww = ft(t, dropDown.Bounds.Width);
|
var ww = ft(t, dropDown.Bounds.Width - dropDown.ScrollbarWidth);
|
||||||
dismissAfter.Add(ww);
|
dismissAfter.Add(ww);
|
||||||
ww.ClickThrough = false;
|
ww.ClickThrough = false;
|
||||||
ww.IsVisible = () => true;
|
ww.IsVisible = () => true;
|
||||||
ww.Bounds = new Rectangle(1, y, ww.Bounds.Width, ww.Bounds.Height);
|
|
||||||
|
|
||||||
ww.OnMouseMove = mi =>
|
ww.OnMouseMove = mi =>
|
||||||
{
|
{
|
||||||
items.Do(lw =>
|
items.Do(lw =>
|
||||||
@@ -181,12 +179,9 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
dropDown.AddChild(ww);
|
dropDown.AddChild(ww);
|
||||||
items.Add(ww);
|
items.Add(ww);
|
||||||
|
|
||||||
y += ww.Bounds.Height;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dropDown.ContentHeight = y;
|
dropDown.Bounds.Height = Math.Min(150, dropDown.ContentHeight);
|
||||||
dropDown.Bounds.Height = y + 2;
|
|
||||||
ShowDropPanel(w, dropDown, dismissAfter, () => true);
|
ShowDropPanel(w, dropDown, dismissAfter, () => true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ namespace OpenRA.Widgets
|
|||||||
{
|
{
|
||||||
public class ScrollPanelWidget : Widget
|
public class ScrollPanelWidget : Widget
|
||||||
{
|
{
|
||||||
public readonly string Background = "dialog3";
|
public string Background = "dialog3";
|
||||||
public readonly int ScrollbarWidth = 24;
|
public int ScrollbarWidth = 24;
|
||||||
public readonly float ScrollVelocity = 4f;
|
public float ScrollVelocity = 4f;
|
||||||
public readonly int ItemSpacing = 2;
|
public int ItemSpacing = 2;
|
||||||
|
|
||||||
public int ContentHeight = 0;
|
public int ContentHeight = 0;
|
||||||
float ListOffset = 0;
|
float ListOffset = 0;
|
||||||
@@ -66,6 +66,8 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
var thumbHeight = ContentHeight == 0 ? 0 : (int)(ScrollbarHeight*Math.Min(RenderBounds.Height*1f/ContentHeight, 1f));
|
var thumbHeight = ContentHeight == 0 ? 0 : (int)(ScrollbarHeight*Math.Min(RenderBounds.Height*1f/ContentHeight, 1f));
|
||||||
var thumbOrigin = RenderBounds.Y + ScrollbarWidth + (int)((ScrollbarHeight - thumbHeight)*(-1f*ListOffset/(ContentHeight - RenderBounds.Height)));
|
var thumbOrigin = RenderBounds.Y + ScrollbarWidth + (int)((ScrollbarHeight - thumbHeight)*(-1f*ListOffset/(ContentHeight - RenderBounds.Height)));
|
||||||
|
if (thumbHeight == ScrollbarHeight)
|
||||||
|
thumbHeight = 0;
|
||||||
|
|
||||||
backgroundRect = new Rectangle(RenderBounds.X, RenderBounds.Y, RenderBounds.Width - ScrollbarWidth, RenderBounds.Height);
|
backgroundRect = new Rectangle(RenderBounds.X, RenderBounds.Y, RenderBounds.Width - ScrollbarWidth, RenderBounds.Height);
|
||||||
upButtonRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Y, ScrollbarWidth, ScrollbarWidth);
|
upButtonRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Y, ScrollbarWidth, ScrollbarWidth);
|
||||||
@@ -73,8 +75,8 @@ namespace OpenRA.Widgets
|
|||||||
scrollbarRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Y + ScrollbarWidth, ScrollbarWidth, ScrollbarHeight);
|
scrollbarRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, RenderBounds.Y + ScrollbarWidth, ScrollbarWidth, ScrollbarHeight);
|
||||||
thumbRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, thumbOrigin, ScrollbarWidth, thumbHeight);
|
thumbRect = new Rectangle(RenderBounds.Right - ScrollbarWidth, thumbOrigin, ScrollbarWidth, thumbHeight);
|
||||||
|
|
||||||
string upButtonBg = UpPressed ? "dialog3" : "dialog2";
|
string upButtonBg = UpPressed || thumbHeight == 0 ? "dialog3" : "dialog2";
|
||||||
string downButtonBg = DownPressed ? "dialog3" : "dialog2";
|
string downButtonBg = DownPressed || thumbHeight == 0 ? "dialog3" : "dialog2";
|
||||||
string scrollbarBg = "dialog3";
|
string scrollbarBg = "dialog3";
|
||||||
string thumbBg = "dialog2";
|
string thumbBg = "dialog2";
|
||||||
|
|
||||||
@@ -86,8 +88,8 @@ namespace OpenRA.Widgets
|
|||||||
if (thumbHeight > 0)
|
if (thumbHeight > 0)
|
||||||
WidgetUtils.DrawPanel(thumbBg, thumbRect);
|
WidgetUtils.DrawPanel(thumbBg, thumbRect);
|
||||||
|
|
||||||
var upOffset = UpPressed ? 4 : 3;
|
var upOffset = UpPressed || thumbHeight == 0 ? 4 : 3;
|
||||||
var downOffset = DownPressed ? 4 : 3;
|
var downOffset = DownPressed || thumbHeight == 0 ? 4 : 3;
|
||||||
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", "up_arrow"),
|
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", "up_arrow"),
|
||||||
new float2(upButtonRect.Left + upOffset, upButtonRect.Top + upOffset));
|
new float2(upButtonRect.Left + upOffset, upButtonRect.Top + upOffset));
|
||||||
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", "down_arrow"),
|
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", "down_arrow"),
|
||||||
|
|||||||
Reference in New Issue
Block a user