Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5532: Add Binding class used to connect the Material to a UI control…
…. Introduce CheckboxBinding as first implementation to reflect all the surface flags.
- Loading branch information
1 parent
195e303
commit 81b9bcb
Showing
7 changed files
with
173 additions
and
52 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#pragma once | ||
|
||
#include "ishaders.h" | ||
#include <wx/checkbox.h> | ||
|
||
namespace ui | ||
{ | ||
|
||
template<typename Source> | ||
class Binding | ||
{ | ||
private: | ||
Source _source; | ||
|
||
public: | ||
virtual ~Binding() | ||
{} | ||
|
||
const Source& getSource() const | ||
{ | ||
return _source; | ||
} | ||
|
||
void setSource(const Source& source) | ||
{ | ||
_source = source; | ||
onSourceChanged(); | ||
} | ||
|
||
virtual void updateFromSource(const Source& source) = 0; | ||
|
||
protected: | ||
virtual void onSourceChanged() | ||
{ | ||
updateFromSource(getSource()); | ||
} | ||
}; | ||
|
||
using MaterialBinding = Binding<MaterialPtr>; | ||
|
||
class CheckBoxBinding : | ||
public MaterialBinding | ||
{ | ||
private: | ||
wxCheckBox* _checkbox; | ||
std::function<bool(const MaterialPtr&)> _loadFunc; | ||
|
||
public: | ||
CheckBoxBinding(wxCheckBox* checkbox, const std::function<bool(const MaterialPtr&)> loadFunc) : | ||
_checkbox(checkbox), | ||
_loadFunc(loadFunc) | ||
{} | ||
|
||
virtual void updateFromSource(const MaterialPtr& material) override | ||
{ | ||
if (!getSource()) | ||
{ | ||
_checkbox->SetValue(false); | ||
return; | ||
} | ||
|
||
_checkbox->SetValue(_loadFunc(getSource())); | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.