Page 2 of 5

Re: A few questions about some features

Posted: 03 Feb 2015, 15:50
by ZanAlex
That's great!
Also, I noticed some of the showcases are only available as UnityPackage, having them as native C++ application would be great. I'm especially thinking about the drag'n drop sample.

Re: A few questions about some features

Posted: 05 Feb 2015, 11:10
by ZanAlex
Hi,

I'm still diving into NoesisGui and the way it can be extended is still a bit fuzzy in my mind. I think I get the idea of creating a UserControl by aggregating existing controls. Commands and Converters seem quite clear as well, but I'm not sure I understand correctly the ideas behind CustomControl and Code-behind. Would you mind giving me some hints on my current use-case?

I'd like to have several drop-down menus (like ComboBox-es, with several selectable entries in them). I'd like to be able to reorganize their order in the bar and the order of the entries in their menu, all of this by drag'n drop. The ComboBox's button should be togglable and customizable (meaning not just Text) as well. My first idea would be that a CustomControl should extend ItemsControl for the "Reorderable collection of items" thing and combined with a "Reorganize" command.
Does it sound reasonnable? Some indication about that particular problem would be very valuable to me, so that I can get familiar with the API. Or maybe I missed an applicable example in the showcases.

Thanks.

Re: A few questions about some features

Posted: 09 Feb 2015, 13:31
by sfernandez
Custom controls are perfect for what you try to accomplish, that is, extending the functionality of an already existing control. Another feature of custom controls is that it allows you to skin the same control with different templates, obtaining very different looks for the same control (UserControls in the other hand, have the appearance predefined by the associated xaml).

As explained in the the Custom Controls tutorial you have to take care of the following aspects:
  • Override the DefaultStyleKey property.
  • Create a default style that can be assigned when no other implicit/explicit style can be found.
  • Define the set of PART elements that you need to found in the template in order to correctly implement the control logic. These are elements in the template named as "PART_<something>" that you look for in the OnTemplateChanged() function. For example, the Slider control does something like this:
    void Slider::OnTemplateChanged(FrameworkTemplate* oldTemplate, FrameworkElement* oldRoot,
        FrameworkTemplate* newTemplate, FrameworkElement* newRoot)
    {
        ParentClass::OnTemplateChanged(oldTemplate, oldRoot, newTemplate, newRoot);
    
        if (newRoot != 0)
        {
            mTrack.Reset(NsStaticCast<Track*>(GetTemplateChild("PART_Track")));
        }
    } 

Re: A few questions about some features

Posted: 11 Feb 2015, 09:28
by ZanAlex
Thank you for your answers, I had missed that last point.

I'm still implementing that feature by deriving ItemsControl. Its default template is a Grid with a fixed number of rows/columns.
So far, here is what I'm trying to do:
  • Override ItemsControl::OnItemAdded so that I can plug a callback to several events (MouseButtonDown, MouseEnter...)
  • Override FrameworkElement::OnTemplateChanged to get my underlying container (a Grid) and fill it with the content of my Control's ItemCollection (Grid::SetColumn/SetRow).
I think it is partially working, I've printed some logs showing that the Grid has the correct size and each element in the grid seems to be correctly placed (according to Grid::GetColumn/GetRow), but none of it is actually showing on screen (in the XamlPlayer). An idea of what could be wrong?

Thank you again for your help, my learning of the API is made far easier thanks to you.

EDIT: By investigating the NoesisStyle file in the Sdk, I've found the IsItemsHost property, I think I have some other matters to investigate.

Re: A few questions about some features

Posted: 13 Feb 2015, 17:00
by ZanAlex
So, I managed to get the drag'n drop behaviour I wanted and it's working fairly good.

Now, I'm trying to extend ContentControl to get a more customizable drop-down menu. My goal is to be able to specify the content (what appears in the Popup when clicking the button), and the header as well. The content of the Popup is directly the content of ContentControl and it's working.

What I could not get so far is the customizable header. I've done quite the same thing as in ContentControl class: a DependencyProperty and a couple of accessors/mutators (operating a BaseComponent, like in ContentControl). It's not working as expected, did I forget a thing? I basically did the same for opening/closing the Popup and it worked just fine.

MenuAnchor class extracts:
Noesis::Core::BaseComponent* GetHeaderContent() const;
void SetHeaderContent(Noesis::Core::BaseComponent* content);
data->RegisterProperty<Noesis::Core::BaseComponent*>(
    HeaderContentProperty, "HeaderContent", 
    Noesis::Gui::FrameworkPropertyMetadata::Create(
        (Noesis::Core::BaseComponent*)(nullptr), 
        Noesis::Gui::FrameworkOptions::FrameworkOptions_None));
ControlTemplate:
<ControlTemplate x:Key="MenuAnchorTemplate" TargetType="{x:Type MenuAnchor}">
[...]
    <StackPanel Orientation="Horizontal">
        <ContentControl Content="{Binding HeaderContent, RelativeSource={RelativeSource TemplatedParent}}"/>
					
        <ToggleButton
            Content="X"
            IsChecked="{Binding IsMenuOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"/>
    </StackPanel>		
[...]	
</ControlTemplate>
Usage:
<MenuAnchor>
    <MenuAnchor.HeaderContent>
        <TextBlock Text="Header" />
    </MenuAnchor.HeaderContent>
    <TextBlock Text="Item_0" VerticalAlignment="Center"/>
</MenuAnchor>

Re: A few questions about some features

Posted: 14 Feb 2015, 21:01
by sfernandez
Try to register the DP as a Ptr<BaseComponent> (but keep the accessors as BaseComponent*):
Noesis::Core::BaseComponent* GetHeaderContent() const
{
  return GetValue<Ptr<BaseComponent> >(HeaderContentProperty).GetPtr();
}
void SetHeaderContent(Noesis::Core::BaseComponent* content)
{
  SetValue<Ptr<BaseComponent> >(HeaderContentProperty, content);
}
//...
data->RegisterProperty<Noesis::Core::Ptr<Noesis::Core::BaseComponent> >(
    HeaderContentProperty, "HeaderContent", 
    Noesis::Gui::FrameworkPropertyMetadata::Create(
        Noesis::Core::Ptr<Noesis::Core::BaseComponent>::Null(), 
        Noesis::Gui::FrameworkOptions::FrameworkOptions_None));
And the other thing you should change is the template. The element you have to use to show content in a template is a ContentPresenter, instead of another ContentControl (which will have its own control template again):
<ControlTemplate x:Key="MenuAnchorTemplate" TargetType="{x:Type MenuAnchor}">
[...]
    <StackPanel Orientation="Horizontal">
        <ContentPresenter Content="{Binding HeaderContent, RelativeSource={RelativeSource TemplatedParent}}"/>
               
        <ToggleButton
            Content="X"
            IsChecked="{Binding IsMenuOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"/>
    </StackPanel>      
[...]   
</ControlTemplate>
Let me know if it works with this changes.

Re: A few questions about some features

Posted: 14 Feb 2015, 23:59
by jsantos
I am updating the extending tutorial to v1.2 these days. As soon as I have it I will provide you a link to our github repository.
I have updated the data in github for the following tutorials: The tutorials will be available in b9, but if you need them before that please contact me in private.

Re: A few questions about some features

Posted: 19 Feb 2015, 10:41
by ZanAlex
Hi,

Thank you for your answer.

Unfortunately it's not working with these changes either.
EDIT: Oop, my bad, it's actually working.

Also, is there a good debugging tool for Noesis? So far, I've printed some logs in a file at runtime when working with the XamlPlayer, but a quick way to know who has the mouse capture/keyboard focus at runtime would be very valuable.

Sorry for the question-storm in the topic, I'm still not familiar with several things in the framework and as a result, I get stuck regularly. I have a custom control deriving from ItemsControl with a StackPanel as ItemHost. I'd like to pass the StackPanel orientation as a property of my control. But assigning the value in the Xaml file does not make any difference, and even changing the default value does not affect the finale layout.

Get/Set signatures:
Noesis::Gui::Orientation GetOrientation() const;
void SetOrientation(Noesis::Gui::Orientation orientation);
Registry:
data->RegisterProperty<Noesis::Gui::Orientation>(
            OrientationProperty,
            "Orientation",
            Noesis::Gui::FrameworkPropertyMetadata::Create(Noesis::Gui::Orientation::Orientation_Horizontal, Noesis::Gui::FrameworkOptions::FrameworkOptions_None));
Template:
<StackPanel Orientation="{Binding Orientation, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" IsItemsHost="True" />
Usage:
<ReorderablePanel Style="{StaticResource DefaultStyleKey}" Orientation="Vertical">
I think it might have something to do with the FrameworkOptions in the registry, but I haven't find the solution yet. [/i]
EDIT: I've found what the problem was. I've put the Property in the wrong class and did not get any warning. It took me quite some time to find out, sorry about that.

Do you see what the problem is?

Re: A few questions about some features

Posted: 23 Feb 2015, 16:49
by sfernandez
Hi,

Thank you for your answer.

Unfortunately it's not working with these changes either.
EDIT: Oop, my bad, it's actually working.
Great to know it worked.
Also, is there a good debugging tool for Noesis? So far, I've printed some logs in a file at runtime when working with the XamlPlayer, but a quick way to know who has the mouse capture/keyboard focus at runtime would be very valuable.
We have a profiling tool (memory & cpu) that we are studying to make public. The tool does not provide info about the captured input element but seems a good idea to add it (as well as mouse over element and things like that).
Sorry for the question-storm in the topic, I'm still not familiar with several things in the framework and as a result, I get stuck regularly. I have a custom control deriving from ItemsControl with a StackPanel as ItemHost. I'd like to pass the StackPanel orientation as a property of my control. But assigning the value in the Xaml file does not make any difference, and even changing the default value does not affect the finale layout.

...

I think it might have something to do with the FrameworkOptions in the registry, but I haven't find the solution yet.

EDIT: I've found what the problem was. I've put the Property in the wrong class and did not get any warning. It took me quite some time to find out, sorry about that.

Do you see what the problem is?
Where did you put the property in the first place? Maybe we can improve the error/warning messages shown to the user.

Re: A few questions about some features

Posted: 23 Feb 2015, 17:13
by ZanAlex
We have a profiling tool (memory & cpu) that we are studying to make public. The tool does not provide info about the captured input element but seems a good idea to add it (as well as mouse over element and things like that).
Nice to see my feedbacks are taken into account, I really appreciate that.
Where did you put the property in the first place? Maybe we can improve the error/warning messages shown to the user.
I created two different controls and added the property in the wrong one. I got no warning when calling the property that did not exist, so it took me quite a while to figure this out.
I think a warning window in the XamlPlayer in this kind of situation would be really great, because I still get stuck for a few minutes on this kind of error even in simpler cases. Do you think it could be done?