-1

I use Terminal.Gui library: https://github.com/migueldeicaza/gui.cs
Is it possible to convert Dim to int? For example:

Window win = new Window("name") { 
  X = 0,
  Y = 0,
  Width = Dim.Fill(),
  Height = Dim.Fill()
};

int width = (int)win.Width; //There is "Cannot convert type Gui.Terminal.Dim to int" exception actually
JPBlanc
  • 70,406
  • 17
  • 130
  • 175
Stami
  • 43
  • 5
  • [See for yourself](https://github.com/migueldeicaza/gui.cs/blob/cfa00142f9e15a45c80082059c9b73cc542c13ae/Terminal.Gui/Core/PosDim.cs). You could try fetching [Bounds](https://github.com/migueldeicaza/gui.cs/blob/cfa00142f9e15a45c80082059c9b73cc542c13ae/Terminal.Gui/Core/View.cs#L431), however... – canton7 Nov 23 '20 at 16:12
  • I don't know the framework, but wouldn't it be win.Bounds.Size.Width? Edit:@Canton7 beat me to it. – Palle Due Nov 23 '20 at 16:16
  • canton7 and Palle Due Thenks! It's help for me! – Stami Nov 23 '20 at 16:37
  • What is `Dim` ? – JAlex Nov 23 '20 at 17:29
  • A `Dim` can be either a percentage, an absolute value or a *margin* - DimFill has no actual size, just a margin. It doesn't make sense to convert it to an `int`. A `Dim()` was built to *specify screen-relative dimensions*, not retrieve absolute ones. What are you trying to do? If you want to have `Dim` calculate the actual size of a Window, it won't work, simply because a `DimFill` doesn't contain any size – Panagiotis Kanavos Nov 23 '20 at 18:46
  • In your case, your code specified a Window as large as the console screen, whatever that is. If the screen is resized, the window is resized as well. `Dim.Fill()` specifies a margin of 0. You already know that. So what `int` do you expect to get from `Dim`? The `0` you specified? You already know that. Or the current size of the window? `Dim` doesn't hold that – Panagiotis Kanavos Nov 23 '20 at 18:50

1 Answers1

0

I am not familiar with the framework, but a quick peek at the definition of the Dim object shows that there are no methods that return an int (except GetHashCode) and as you have seen the object is not able to be casted to an int. So there is not a method for converting a Dim to an int.

bisen2
  • 486
  • 1
  • 4
  • 10