mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-30 09:47:58 +01:00
Added horizontal scrollbar, fixed tests
This commit is contained in:
@@ -346,7 +346,6 @@ namespace Terminal.Gui {
|
||||
/// </summary>
|
||||
public int ContentHeight => BuildLineMap().Count();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns the string representation of model objects hosted in the tree. Default implementation is to call <see cref="object.ToString"/>
|
||||
/// </summary>
|
||||
@@ -523,6 +522,32 @@ namespace Terminal.Gui {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the maximum width line in the tree including prefix and expansion symbols
|
||||
/// </summary>
|
||||
/// <param name="visible">True to consider only rows currently visible (based on window bounds and <see cref="ScrollOffsetVertical"/>. False to calculate the width of every exposed branch in the tree</param>
|
||||
/// <returns></returns>
|
||||
public int GetContentWidth(bool visible){
|
||||
|
||||
var map = BuildLineMap();
|
||||
|
||||
if(map.Length == 0)
|
||||
return 0;
|
||||
|
||||
if(visible){
|
||||
|
||||
//Somehow we managed to scroll off the end of the control
|
||||
if(ScrollOffsetVertical > map.Length)
|
||||
return 0;
|
||||
|
||||
return map.Skip(ScrollOffsetVertical).Take(Bounds.Height).Max(b=>b.GetWidth(Driver));
|
||||
}
|
||||
else{
|
||||
|
||||
return map.Max(b=>b.GetWidth(Driver));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates all currently visible/expanded branches (including leafs) and outputs them by index from the top of the screen
|
||||
/// </summary>
|
||||
@@ -898,6 +923,18 @@ namespace Terminal.Gui {
|
||||
this.ChildBranches = children.ToDictionary(k=>k,val=>new Branch<T>(tree,this,val));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the width of the line including prefix and the results of <see cref="TreeView{T}.AspectGetter"/> (the line body).
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual int GetWidth (ConsoleDriver driver)
|
||||
{
|
||||
return
|
||||
GetLinePrefix(driver).Sum(Rune.ColumnWidth) +
|
||||
Rune.ColumnWidth(GetExpandableSymbol(driver)) +
|
||||
(tree.AspectGetter(Model) ?? "").Length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders the current <see cref="Model"/> on the specified line <paramref name="y"/>
|
||||
/// </summary>
|
||||
@@ -1210,6 +1247,7 @@ namespace Terminal.Gui {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -92,20 +92,20 @@ namespace UICatalog.Scenarios {
|
||||
}
|
||||
treeViewFiles.SetNeedsDisplay ();
|
||||
};
|
||||
/*
|
||||
|
||||
_scrollBar.OtherScrollBarView.ChangedPosition += () => {
|
||||
_listView.LeftItem = _scrollBar.OtherScrollBarView.Position;
|
||||
if (_listView.LeftItem != _scrollBar.OtherScrollBarView.Position) {
|
||||
_scrollBar.OtherScrollBarView.Position = _listView.LeftItem;
|
||||
treeViewFiles.ScrollOffsetHorizontal = _scrollBar.OtherScrollBarView.Position;
|
||||
if (treeViewFiles.ScrollOffsetHorizontal != _scrollBar.OtherScrollBarView.Position) {
|
||||
_scrollBar.OtherScrollBarView.Position = treeViewFiles.ScrollOffsetHorizontal;
|
||||
}
|
||||
_listView.SetNeedsDisplay ();
|
||||
};*/
|
||||
treeViewFiles.SetNeedsDisplay ();
|
||||
};
|
||||
|
||||
treeViewFiles.DrawContent += (e) => {
|
||||
_scrollBar.Size = treeViewFiles.ContentHeight;
|
||||
_scrollBar.Position = treeViewFiles.ScrollOffsetVertical;
|
||||
// _scrollBar.OtherScrollBarView.Size = _listView.Maxlength - 1;
|
||||
// _scrollBar.OtherScrollBarView.Position = _listView.LeftItem;
|
||||
_scrollBar.OtherScrollBarView.Size = treeViewFiles.GetContentWidth(true);
|
||||
_scrollBar.OtherScrollBarView.Position = treeViewFiles.ScrollOffsetHorizontal;
|
||||
_scrollBar.Refresh ();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -89,13 +89,13 @@ namespace UnitTests {
|
||||
{
|
||||
var tree = CreateTree();
|
||||
|
||||
Assert.Equal(0,tree.ScrollOffset);
|
||||
Assert.Equal(0,tree.ScrollOffsetVertical);
|
||||
|
||||
tree.ScrollOffset = -100;
|
||||
Assert.Equal(0,tree.ScrollOffset);
|
||||
tree.ScrollOffsetVertical = -100;
|
||||
Assert.Equal(0,tree.ScrollOffsetVertical);
|
||||
|
||||
tree.ScrollOffset = 10;
|
||||
Assert.Equal(10,tree.ScrollOffset);
|
||||
tree.ScrollOffsetVertical = 10;
|
||||
Assert.Equal(10,tree.ScrollOffsetVertical);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user