Skip to content

Commit

Permalink
* Code cleanup, docs were moved to separate directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
elw00d committed Sep 22, 2014
1 parent a279dc8 commit 0712fc2
Show file tree
Hide file tree
Showing 13 changed files with 587 additions and 589 deletions.
1 change: 0 additions & 1 deletion Binding/roadmap.txt

This file was deleted.

5 changes: 0 additions & 5 deletions ConsoleFramework/ConsoleFramework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,6 @@
<Compile Include="Xaml\ConvertMarkupExtension.cs" />
<Compile Include="Xaml\NotBooleanConverter.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Controls\LayoutSystem.txt" />
<Content Include="Events\Focus.txt" />
<Content Include="readme.txt" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Binding\Binding.csproj">
<Project>{E1CD529B-E3F1-4660-AA4F-1670E0992553}</Project>
Expand Down
44 changes: 20 additions & 24 deletions ConsoleFramework/Controls/ComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public ComboBox( ) : this(true) {
}

/// <summary>
/// Создаёт экземпляр комбобокса
/// Creates combobox instance.
/// </summary>
/// <param name="shadow">Отображать ли тень</param>
/// <param name="shadow">Display shadow or not</param>
public ComboBox( bool shadow ) {
this.shadow = shadow;
Focusable = true;
Expand All @@ -38,9 +38,9 @@ public ComboBox( bool shadow ) {
private class PopupWindow : Window
{
public int IndexSelected;
private bool shadow;
private ListBox listbox;
private ScrollViewer scrollViewer;
private readonly bool shadow;
private readonly ListBox listbox;
private readonly ScrollViewer scrollViewer;

public PopupWindow( IEnumerable< string > items,
int selectedItemIndex, bool shadow,
Expand All @@ -61,19 +61,15 @@ public PopupWindow( IEnumerable< string > items,
scrollViewer.Content = listbox;
Content = scrollViewer;

// todo : продумать более удобное API для взаимодействия с ScrollViewer
// todo : вынести этот код в ScrollableListBox
listbox.SelectedItemIndexChanged += ListboxOnSelectedItemIndexChanged;

// if click on the transparent header, close the popup
// If click on the transparent header, close the popup
AddHandler( MouseDownEvent, new MouseButtonEventHandler(( sender, args ) => {
if ( !scrollViewer.RenderSlotRect.Contains( args.GetPosition( this ) ) ) {
Close();
args.Handled = true;
}
}));

// if listbox item has been selected
// If listbox item has been selected
EventManager.AddHandler( listbox, MouseUpEvent, new MouseButtonEventHandler(
( sender, args ) => {
IndexSelected = listbox.SelectedItemIndex;
Expand All @@ -89,7 +85,7 @@ public PopupWindow( IEnumerable< string > items,
// todo : cleanup event handlers after popup closing
}

private void ListboxOnSelectedItemIndexChanged( object sender, EventArgs e ) {
private void initListBoxScrollingPos( ) {
int itemIndex = listbox.SelectedItemIndex;
int firstVisibleItemIndex = scrollViewer.DeltaY;
int lastVisibleItemIndex = firstVisibleItemIndex + scrollViewer.ActualHeight -
Expand Down Expand Up @@ -118,12 +114,12 @@ private void OnActivated( object sender, EventArgs eventArgs ) {
public override void Render(RenderingBuffer buffer)
{
Attr borderAttrs = Colors.Blend(Color.Black, Color.DarkCyan);
// устанавливаем прозрачными первую строку и первый столбец
// для столбца дополнительно включена прозрачность для событий мыши

// background
// Background
buffer.FillRectangle(1, 1, this.ActualWidth - 1, this.ActualHeight - 1, ' ', borderAttrs);

// First row and first column are transparent
// Column is also transparent for mouse events
buffer.SetOpacityRect( 0,0,ActualWidth, 1, 2 );
buffer.SetOpacityRect( 0, 1, 1, ActualHeight-1, 6 );
if ( shadow ) {
Expand All @@ -141,11 +137,11 @@ protected override Size MeasureOverride(Size availableSize)
{
if (Content == null) return new Size(0, 0);
if ( shadow ) {
// 1 строку и 1 столбец оставляем для прозрачного пространства, остальное занимает ListBox
// 1 row and 1 column - reserved for transparent space, remaining - for ListBox
Content.Measure( new Size( availableSize.Width - 2, availableSize.Height - 2 ) );
return new Size( Content.DesiredSize.Width + 2, Content.DesiredSize.Height + 2 );
} else {
// 1 строку и 1 столбец оставляем для прозрачного пространства, остальное занимает ListBox
// 1 row and 1 column - reserved for transparent space, remaining - for ListBox
Content.Measure(new Size(availableSize.Width - 1, availableSize.Height - 1));
return new Size(Content.DesiredSize.Width + 1, Content.DesiredSize.Height + 1);
}
Expand All @@ -160,11 +156,11 @@ protected override Size ArrangeOverride(Size finalSize) {
Content.Arrange(new Rect(new Point(1, 1),
new Size(finalSize.Width - 1, finalSize.Height - 1)));
}
// При инициализации нужно установить корректные смещения scroll viewer для текущего
// выбранного элемента. Но так как работа scroll viewer зависит от установленных
// значений ActualWidth / ActualHeight, то это нужно выполнить после выполнения
// этапа размещения (arrangement)
ListboxOnSelectedItemIndexChanged(this, EventArgs.Empty);

// When initializing we need to correctly assign offsets to ScrollViewer for
// currently selected item. Because ScrollViewer depends of ActualWidth / ActualHeight
// of Content, we need to do this after arrangement has finished.
initListBoxScrollingPos( );
}
return finalSize;
}
Expand Down Expand Up @@ -197,7 +193,7 @@ private void openPopup( ) {
popup.Width = shadow ? ActualWidth+1 : ActualWidth;
if (Items.Count != 0)
popup.Height = (ShownItemsCount != null ? ShownItemsCount.Value : Items.Count)
+ (shadow ? 2 : 1); // 1 строка для прозначного "заголовка"
+ (shadow ? 2 : 1); // 1 row for transparent "header"
else popup.Height = shadow ? 3 : 2;
WindowsHost windowsHost = VisualTreeHelper.FindClosestParent< WindowsHost >( this );
windowsHost.ShowModal(popup, true);
Expand Down Expand Up @@ -247,7 +243,7 @@ public int SelectedItemIndex {
protected override Size MeasureOverride(Size availableSize) {
if (Items.Count == 0) return EMPTY_SIZE;
int maxLen = Items.Max(s => s.Length);
// 1 пиксель слева от надписи, 1 справа, потом стрелка и ещё 1 пустой пиксель
// 1 pixel from left, 1 from right, then arrow and 1 more empty pixel
Size size = new Size(Math.Min(maxLen + 4, availableSize.Width), 1);
return size;
}
Expand Down
10 changes: 9 additions & 1 deletion Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,15 @@ private static void Main(string[] args) {
scrollViewer.VerticalAlignment = VerticalAlignment.Stretch;
scrollViewer.HorizontalScrollEnabled = false;

groupBox.Content = scrollViewer;
//groupBox.Content = scrollViewer;

ComboBox combo = new ComboBox();
combo.ShownItemsCount = 10;
for ( int i = 0; i < 30; i++ ) {
combo.Items.Add(string.Format("Длинный элемент {0}", i));
}
groupBox.Content = combo;

groupBox.HorizontalAlignment = HorizontalAlignment.Stretch;

windowsHost.Show(new Window() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 0712fc2

Please sign in to comment.