Jypeli  9
The simple game programming library
StringListWidget.cs
Siirry tämän tiedoston dokumentaatioon.
1 #region MIT License
2 /*
3  * Copyright (c) 2009-2011 University of Jyväskylä, Department of Mathematical
4  * Information Technology.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #endregion
25 
26 /*
27  * Authors: Tomi Karppinen, Tero Jäntti
28  */
29 
30 using System;
31 using Microsoft.Xna.Framework;
32 using System.Text;
33 using Microsoft.Xna.Framework.Graphics;
34 
35 namespace Jypeli
36 {
40  public class StringListWidget : ListWidget<string, Label>
41  {
45 
49  public Font Font
50  {
51  get { return _font; }
52  set
53  {
54  _font = value;
55  for ( int i = 0; i < Content.ItemCount; i++ )
56  Content[i].Font = value;
57  }
58  }
59 
64  {
65  get { return _textColor; }
66  set
67  {
68  _textColor = value;
69  for ( int i = 0; i < Content.ItemCount; i++ )
70  Content[i].TextColor = value;
71  }
72  }
73 
78  {
79  get { return _hAlignment; }
80  set
81  {
82  _hAlignment = value;
83  for ( int i = 0; i < Content.ItemCount; i++ )
84  Content[i].HorizontalAlignment = value;
85  }
86  }
87 
91  public string Text
92  {
93  get
94  {
95  StringBuilder result = new StringBuilder();
96 
97  foreach ( var item in Items )
98  {
99  result.Append( item ).Append( "\n" );
100  }
101 
102  return result.RemoveLast( 2 ).ToString();
103  }
104  set
105  {
106  if ( Width == 0 )
107  throw new InvalidOperationException( "You must set the list width before assigning text!" );
108 
109  SpriteFont xnaFont = this.Font.XnaFont;
110  Vector2 textDims = xnaFont.MeasureString( value );
111  double softWidth = 4 * Font.CharacterWidth < Width ? Width - 4 * Font.CharacterWidth : Width;
112  string wrapped = Font.WrapText( value, softWidth, Width );
113 
114  StringList newList = new StringList( wrapped.Split( '\n' ) );
115  this.Bind( newList );
116  }
117  }
118 
125  : base( list )
126  {
127  }
128 
133  : base( new StringList() )
134  {
135  SizingByLayout = false;
136  }
137 
138  internal protected override Label CreateWidget( string item )
139  {
140  return new Label( item )
141  {
142  HorizontalSizing = Sizing.Expanding,
143  Font = Font,
145  SizeMode = TextSizeMode.None,
148  };
149  }
150  }
151 }
Jypeli.StringListWidget.Text
string? Text
Kaikki listan alkiot rivinvaihdoilla erotettuna.
Definition: StringListWidget.cs:92
Jypeli.Font.CharacterWidth
double CharacterWidth
Merkin leveys.
Definition: Font.cs:98
Jypeli.Color.Black
static readonly Color Black
Musta.
Definition: Color.cs:503
Jypeli.StringListWidget.CreateWidget
override Label CreateWidget(string item)
Definition: StringListWidget.cs:138
Microsoft.Xna
Definition: JypeliContentManager.cs:6
Jypeli.StringListWidget
Käyttöliittymäkomponentti, joka näyttää listan merkkijonoja.
Definition: StringListWidget.cs:41
Jypeli
Definition: Automobile.cs:5
Jypeli.TextSizeMode
TextSizeMode
Definition: Label.cs:38
Jypeli.StringListWidget.StringListWidget
StringListWidget()
Luo uuden (tyhjän) merkkijonolistakomponentin.
Definition: StringListWidget.cs:132
Jypeli.Font.Default
static readonly Font Default
Oletusfontti.
Definition: Font.cs:30
Microsoft
Definition: JypeliContentManager.cs:6
Microsoft.Xna.Framework
Definition: JypeliContentManager.cs:6
Jypeli.StringListWidget._textColor
Color _textColor
Definition: StringListWidget.cs:43
Jypeli.Label
Tekstikenttä.
Definition: Label.cs:66
Jypeli.Font.XnaFont
SpriteFont XnaFont
Definition: Font.cs:90
Jypeli.StringList
Järjestetty lista merkkijonoja.
Definition: StringList.cs:11
Jypeli.StringListWidget.ItemAligment
HorizontalAlignment ItemAligment
Listan alkioiden sijoitus vaakasuunnassa.
Definition: StringListWidget.cs:78
Jypeli.StringListWidget._font
Font _font
Definition: StringListWidget.cs:42
Jypeli.ListWidget
Listakomponentti. Voidaan liittää listaan, joka toteuttaa INotifyList-rajapinnan. Tällöin listaan teh...
Definition: ListWidget.cs:155
Jypeli.Color.Transparent
static readonly Color Transparent
Läpinäkyvä väri.
Definition: Color.cs:878
Jypeli.HorizontalAlignment
HorizontalAlignment
Asemointi vaakasuunnassa.
Definition: View.cs:441
Jypeli.ListWidget< string, Label >::Bind
void Bind(INotifyList< T > list)
Sitoo olemassaolevan listan tähän näyttöön. Kun listaa muutetaan, näytetyt arvot päivittyvät automaat...
Definition: ListWidget.cs:304
Jypeli.ListWidget< string, Label >::Items
INotifyList< T > Items
Listan alkiot.
Definition: ListWidget.cs:173
Jypeli.StringListWidget.Font
Font Font
Tekstifontti.
Definition: StringListWidget.cs:50
Jypeli.StringListWidget._hAlignment
HorizontalAlignment _hAlignment
Definition: StringListWidget.cs:44
Jypeli.StringListWidget.StringListWidget
StringListWidget(StringList list)
Luo uuden (tyhjän) merkkijonolistakomponentin, joka on sidottu olemassaolevaan listaan.
Definition: StringListWidget.cs:124
Jypeli.Color
Väri.
Definition: Color.cs:13
Jypeli.StringListWidget.TextColor
Color TextColor
Tekstin väri.
Definition: StringListWidget.cs:64
Jypeli.Font.WrapText
string WrapText(string text, double softLineWidth, double hardLineWidth)
Rivittää tekstin.
Definition: Font.cs:302
System
Definition: CFFauxAttributes.cs:29
Jypeli.Font
Fontti.
Definition: Font.cs:23
Jypeli.ListWidget< string, Label >::Content
ScrollableList< O > Content
Definition: ListWidget.cs:167
Jypeli.Sizing
Sizing
Olion koon asettaminen asettelijan sisällä.
Definition: ILayout.cs:39