User avatar
digimbyte
Topic Author
Posts: 47
Joined: 14 Nov 2017, 21:42

Some questions with working with Noesis [Unity]

29 Jan 2019, 06:06

I have had the last few weeks messing with Noesis GUI and have learned many things along the way
and while I have learned several aspects of creating a GUI and working with XAML
I am left with some questions that don't really get explained in the documentation

I am using Unity 2018
I am building Xaml by code because working with blend hasn't been useful or intuitive

my first question is
how would I best update the GUI? removing or adding elements on demand or public calls?
say if a user logs into the online profile, could I tag elements for a name and find it later?
or can I navigate the tree and delete the element despite its original reference in a separate function?
for example;
Root = (Noesis.Grid)GetComponent<NoesisView>().view.Content;
public void UpdateGUI(){
Root.Children.Add(Login())
}
private DockPanel Login(){
_result = new Noesis.Grid();
return _result;
}
also, I have been having trouble with margins cropping content, I assume this is mostly on my fault for not working with Visual Blender.
I haven't found a way to use padding on panels, or what panels support padding, however, I would find it useful if I could see the grid lines
but I haven't found how to create them programmatically as of yet
<Grid Background="Gray" ShowGridLines="True">

Tags:
 
User avatar
sfernandez
Site Admin
Posts: 1628
Joined: 22 Dec 2011, 19:20

Re: Some questions with working with Noesis [Unity]

30 Jan 2019, 11:50

how would I best update the GUI? removing or adding elements on demand or public calls?
NoesisGUI offers (almost) the same API as WPF (Windows Presentation Foundation), that includes a lot of controls with its own ways of dealing with content depending on the exposed functionality. To get a basic understanding on the different UI elements and how to work with them you can read Layout and Panels tutorial. All the properties you can set in xaml are the same ones you can set in code, so for example:
<Expander Header="Some Header" Content="Some Content"/>
Is the same as:
Expander expander = new Expander();
expander.Header = "Some Header";
expander.Content = "Some Content";
But take into account that both Header and Content allow you to set any element, not only strings, so you can add there other controls and build the UI you need.
say if a user logs into the online profile, could I tag elements for a name and find it later?
If you can't keep references to the elements, you can register them by name. This is possible because all UI trees have a NameScope object in the root where you can store named references.
In xaml this is done using the x:Name property, but in code you have to manually call RegisterName (and UnregisterName when removed):
<<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <StackPanel x:Name="panel">
        <TextBlock Text="Hello World!"/>
        <Button x:Name="btn" Content="Button"/>
    </StackPanel>
</Grid>
StackPanel stackPanel = new StackPanel();
m_root.Children.Add(stackPanel);
m_root.RegisterName("panel", stackPanel);

TextBlock textBlock = new TextBlock { Text = "Hello World!" };
stackPanel.Children.Add(textBlock);

Button button = new Button { Content = "Button" };
stackPanel.Children.Add(button);
stackPanel.RegisterName("btn", button);
// ...
StackPanel panel = (StackPanel)m_root.FindName("panel");
Button btn = (Button)m_root.FindName("btn");
panel.Children.Remove(btn);
panel.UnregisterName("btn");
I have been having trouble with margins cropping content
As I said above each element and control exposes different properties depending on what they do and how they layout content.
Margin property is defined in FrameworkElement, so all derived classes can use it.
Padding property is defined in Border and Control, so all derived classes can use it. A Panel (like Grid, StackPanel, Canvas...) inherit from FrameworkElement, so they cannot use the Padding property. You have to use margin in children to achieve what you want.
I would find it useful if I could see the grid lines but I haven't found how to create them programmatically as of yet
ShowGridLines property is not implemented but you can just see how a Grid is organized by adding a colored Rectangle in each cell:
<Grid>
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="3*"/>
    <ColumnDefinition Width="8*"/>
    <ColumnDefinition Width="Auto"/>
  </Grid.ColumnDefinitions>
  <Rectangle Grid.Column="0" Fill="Red"/>
  <Rectangle Grid.Column="1" Fill="Green"/>
  <Rectangle Grid.Column="2" Fill="Blue"/>
  <!-- ... rest of elements -->
</Grid>
I hope this helps.
 
User avatar
digimbyte
Topic Author
Posts: 47
Joined: 14 Nov 2017, 21:42

Re: Some questions with working with Noesis [Unity]

30 Jan 2019, 23:20

Thanks for the response! this answers a lot of the questions I've been looking for

Who is online

Users browsing this forum: No registered users and 2 guests