Drag[en]gine Script Module DragonScript  1.23
Dragengine.Gui.TogglePresentModel Class Reference

ToggleModel synchronized against a ListModel containing an object. More...

Inheritance diagram for Dragengine.Gui.TogglePresentModel:
Dragengine.Gui.DefaultToggleModel Dragengine.Gui.ListModelListener Dragengine.Gui.ToggleModel

Public Member Functions

void contentChanged (ListModel listModel, int fromIndex, int toIndex)
 Content of the model changed. More...
 
void elementsAdded (ListModel listModel, int fromIndex, int toIndex)
 Elements have been added. More...
 
void elementsRemoved (ListModel listModel, int fromIndex, int toIndex)
 Elements have been removed. More...
 
TogglePresentModel new (ListModel listModel, Object trackPresence)
 Create toggle model synchronized against presence of object in list model. More...
 
void selectionChanged (ListModel listModel)
 Selection in the model changed. More...
 
- Public Member Functions inherited from Dragengine.Gui.DefaultToggleModel
void addListener (ToggleModelListener listener)
 Add listener. More...
 
bool getToggled ()
 Get toggled state. More...
 
DefaultToggleModel new ()
 Create toggle model with false toggled state. More...
 
DefaultToggleModel new (bool toggled)
 Create toggle model. More...
 
void removeListener (ToggleModelListener listener)
 Remove listener. More...
 
void setToggled (bool toggled)
 Set toggled state. More...
 

Protected Member Functions

void updateToggleModel (ListModel listModel)
 Update toggle model. More...
 

Detailed Description

ToggleModel synchronized against a ListModel containing an object.

Synchronizes toggle state of a ToggleModel with the presence of an object in a ListModel. Typically the object to check presence for is an Enumeration. This allows to use a ListModel to store boolean game states that can be activated or deactivated. Each game state is represented by a constant from an enumeration list. Changeing game states modifies the enumerations present in the list. This class tracks a specific enumeration constants and uses it to toggle a ToggleModel. This way ToggleModel supporting widgets can easily track a ListModel to build UIs in a simple and understandable way.

An example use looks like this:

// Enumeration representing game states. Multiple enums are possible.
enum GameStates
state1
state2
state3
end
// List model storing activate states
modelStates = DefaultListModel.new()
// set up UI
ui.addWidget(Panel.new(FlowLayout.new(LayoutAxis.y), block Panel p
DisplayImage image
p.addWidget(image = DisplayImage.new(Image.new("/content/ui/state1.png")))
WModifierVisibility.new(TogglePresentModel.new(modelStates, GameStates.state1), image)
p.addWidget(image = DisplayImage.new(Image.new("/content/ui/state2.png")))
WModifierVisibility.new(TogglePresentModel.new(modelStates, GameStates.state2), image)
p.addWidget(image = DisplayImage.new(Image.new("/content/ui/state3.png")))
WModifierVisibility.new(TogglePresentModel.new(modelStates, GameStates.state3), image)
end))
// Now the game states can be toggle causing the UI to adjust automatically
modelStates.add(GameStates.state1) // => image 1 becomes visible
modelStates.add(GameStates.state3) // => image 3 becomes visible
...
modelStates.remove(GameStates.state3) // => image 3 becomes invisible

Member Function Documentation

◆ contentChanged()

void Dragengine.Gui.TogglePresentModel.contentChanged ( ListModel  listModel,
int  fromIndex,
int  toIndex 
)

Content of the model changed.

Implements Dragengine.Gui.ListModelListener.

◆ elementsAdded()

void Dragengine.Gui.TogglePresentModel.elementsAdded ( ListModel  listModel,
int  fromIndex,
int  toIndex 
)

Elements have been added.

Implements Dragengine.Gui.ListModelListener.

◆ elementsRemoved()

void Dragengine.Gui.TogglePresentModel.elementsRemoved ( ListModel  listModel,
int  fromIndex,
int  toIndex 
)

Elements have been removed.

Implements Dragengine.Gui.ListModelListener.

◆ new()

TogglePresentModel Dragengine.Gui.TogglePresentModel.new ( ListModel  listModel,
Object  trackPresence 
)

Create toggle model synchronized against presence of object in list model.

◆ selectionChanged()

void Dragengine.Gui.TogglePresentModel.selectionChanged ( ListModel  listModel)

Selection in the model changed.

Implements Dragengine.Gui.ListModelListener.

◆ updateToggleModel()

void Dragengine.Gui.TogglePresentModel.updateToggleModel ( ListModel  listModel)
protected

Update toggle model.


The documentation for this class was generated from the following file: