Spawn Menu at Position
Posted: 23 Feb 2019, 12:12
Hello, I've been getting along with my GUI project for a while but I have come across a minor annoyance when dealing with relative and absolute positions of elements
in this case, I have a button that needs to spawn a menu "below" it. I am looking at spawning a Grid at that buttons position with the height of the button as an offset.
unfortunately, when trying to find the screen position I keep getting insane numbers such as -666 and 2280 for my margins and Noesis crashes because it doesn't like these numbers
I think its a failure on my part when dealing with relative vs spacial and screen resolution vs real resolution
below is some code where I have decided to stop and ask for help
Ideally, I'd like for it to be a grid if that's any consequence
in this case, I have a button that needs to spawn a menu "below" it. I am looking at spawning a Grid at that buttons position with the height of the button as an offset.
unfortunately, when trying to find the screen position I keep getting insane numbers such as -666 and 2280 for my margins and Noesis crashes because it doesn't like these numbers
I think its a failure on my part when dealing with relative vs spacial and screen resolution vs real resolution
below is some code where I have decided to stop and ask for help
Ideally, I'd like for it to be a grid if that's any consequence
Code: Select all
public void Menu(object sender, RoutedEventArgs e)
{
Point _Position = ((Noesis.Button)sender).PointFromScreen(new Point(0f, 0f));
Vector2 _size = new Vector2(
((Noesis.Button)sender).Width,
((Noesis.Button)sender).Height
);
Noesis.Grid _panel = new Noesis.Grid
{
Margin = Thickness.Parse("" + _Position.X + _size.x + "," + _Position.Y + _size.y + "0,0"),
MinWidth = 150,
MaxWidth = 250,
MinHeight = 12
};
ColumnDefinition Options = new ColumnDefinition { Width = Noesis.GridLength.Auto, MaxWidth = 250 };
ColumnDefinition Scroll = new ColumnDefinition { Width = Noesis.GridLength.Parse("12") };
_panel.ColumnDefinitions.Add(Options);
_panel.ColumnDefinitions.Add(Scroll);