xtd 0.2.0
Loading...
Searching...
No Matches
xtd::forms::control::control_collection Class Reference
Inheritance diagram for xtd::forms::control::control_collection:
xtd::forms::layout::arranged_element_collection< control_ref > xtd::object

Definition

Represents a collection of controls.

Public Aliases

using base = xtd::forms::layout::arranged_element_collection< control_ref >
 Represents the base type of the collection.
 

Public Constructors

 control_collection (const allocator_type &allocator=allocator_type())
 Creates a new object xtd::forms::control::control_collection with specified allocator (optional).
 
 control_collection (bool clone_and_keep_controls, const allocator_type &allocator=allocator_type())
 Creates a new object xtd::forms::control::control_collection with specified clone_and_keep_controls, and allocator (optional).
 

Operators

std::optional< value_type > operator[] (const xtd::ustring &name) const
 Gets the first xtd::forms::control::control_collection in the list with the specified name.
 
std::optional< value_type > operator[] (const xtd::ustring &name)
 Gets the first xtd::forms::control::control_collection in the list with the specified name.
 

Public Methods

template<typename control_t , typename ... args_t>
control_t & emplace (const_iterator pos, args_t &&...args)
 Creates and inserts specified control at specified position.
 
template<typename control_t , typename ... args_t>
control_t & emplace_at (size_t index, args_t &&...args)
 Creates and inserts specified control at specified position.
 
template<typename control_t , typename ... args_t>
control_t & emplace_back (args_t &&...args)
 Creates and adds a control to the end.
 
iterator insert (const_iterator pos, const value_type &value) override
 Inserts specified element at specified position.
 
void insert_at (size_t index, const value_type &value) override
 Inserts specified element at specified index.
 
void push_back (const value_type &value) override
 Adds an element to the end.
 
template<typename control_t >
iterator insert (const_iterator pos, control_t &value)
 
template<typename control_t >
void insert_at (size_t index, control_t &value)
 
template<typename control_t >
void push_back (control_t &value)
 

Protected Methods

void on_item_removed (size_t index, control_ref &item) override
 Raises the xtd::forms::layout::arranged_element_collection::item_removed event.
 

Additional Inherited Members

- Public Types inherited from xtd::forms::layout::arranged_element_collection< control_ref >
using allocator_type = std::allocator< value_type >
 Represents the allocator type of the collection.
 
using size_type = std::size_t
 Represents the size type of the collection.
 
using difference_type = std::ptrdiff_t
 Represents the pointer difference type of the collection.
 
using reference = value_type &
 Represents the value type reference of the collection.
 
using const_reference = const value_type &
 Represents the value type const reference the collection.
 
using pointer = typename std::allocator_traits< allocator_type >::pointer
 Represents the value type pointer of the collection.
 
using const_pointer = typename std::allocator_traits< allocator_type >::const_pointer
 Represents the value type const pointer of the collection.
 
using iterator = typename std::vector< value_type >::iterator
 Represents the iterator type of the collection.
 
using const_iterator = typename std::vector< value_type >::const_iterator
 Represents the const iterator type of the collection.
 
using reverse_iterator = typename std::vector< value_type >::reverse_iterator
 Represents the reverse iterator type of the collection.
 
using const_reverse_iterator = typename std::vector< value_type >::const_reverse_iterator
 Represents the const reverse iterator type of the collection.
 
- Public Attributes inherited from xtd::forms::layout::arranged_element_collection< control_ref >
event< arranged_element_collection, delegate< void(size_t, control_ref &item)> > item_added
 Occurs when an item is added to the collection.
 
event< arranged_element_collection, delegate< void(size_t, control_ref &item)> > item_updated
 Occurs when an item is updated in the collection.
 
event< arranged_element_collection, delegate< void(size_t, control_ref &item)> > item_removed
 Occurs when an item is removed from the collection.
 
- Static Public Attributes inherited from xtd::forms::layout::arranged_element_collection< control_ref >
static const size_t npos
 This is a special value equal to the maximum value representable by the type size_t.
 
- Public Member Functions inherited from xtd::forms::layout::arranged_element_collection< control_ref >
 arranged_element_collection (const allocator_type &allocator=allocator_type())
 Creates a new object xtd::forms::layout::arranged_element_collection with specified allocator (optional).
 
 arranged_element_collection (const std::initializer_list< control_ref > &il)
 Creates a new object xtd::diagnostics::trace_listener_collection with specified initializer list.
 
allocator_type get_allocator () const noexcept
 Returns the associated allocator.
 
reference at (size_type pos)
 Access specified element with bounds checking.
 
const_reference at (size_type pos) const
 Access specified element with bounds checking.
 
reference front ()
 Access the first element.
 
const_reference front () const
 Access the first element.
 
reference back ()
 Access the last element.
 
const_reference back () const
 Access the last element.
 
pointer data ()
 Direct access to the underlying array.
 
const_pointer data () const
 Direct access to the underlying array.
 
iterator begin () noexcept
 Returns an iterator to the beginning.
 
const_iterator begin () const noexcept
 Returns an iterator to the beginning.
 
const_iterator cbegin () const noexcept
 Returns an iterator to the beginning.
 
iterator end () noexcept
 Returns an iterator to the end.
 
const_iterator end () const noexcept
 Returns an iterator to the end.
 
const_iterator cend () const noexcept
 Returns an iterator to the end.
 
reverse_iterator rbegin () noexcept
 Returns a reverse iterator to the end.
 
const_reverse_iterator rbegin () const noexcept
 Returns a reverse iterator to the end.
 
const_reverse_iterator crbegin () const noexcept
 Returns a reverse iterator to the end.
 
reverse_iterator rend () noexcept
 Returns a reverse iterator to the end.
 
const_reverse_iterator rend () const noexcept
 Returns a reverse iterator to the end.
 
const_reverse_iterator crend () const noexcept
 Returns a reverse iterator to the end.
 
bool empty () const noexcept
 Checks whether the container is empty.
 
size_type size () const noexcept
 Returns the number of elements.
 
size_type max_size () const noexcept
 Returns the maximum possible number of elements.
 
void reserve (size_type size)
 Reserves storage.
 
size_type capacity () const noexcept
 Returns the number of elements that can be held in currently allocated storage.
 
void shrink_to_fit ()
 Reduces memory usage by freeing unused memory.
 
virtual bool sorted () const noexcept
 Checks whether the container is sorted.
 
virtual void sorted (bool value)
 Sets the container is sorted.
 
virtual void clear () noexcept
 clears the contents.
 
virtual iterator insert (const_iterator pos, const value_type &&value)
 Inserts specified element at specified position.
 
void emplace (const_iterator pos, args_t &&... args)
 Inserts specified element at specified position.
 
void emplace_back (args_t &&... args)
 Adds an element to the end.
 
virtual iterator erase (iterator pos)
 Erases element at specified position.
 
virtual iterator erase (const_iterator pos)
 Erases element at specified position.
 
virtual iterator erase (iterator first, iterator last)
 Erases elements at specified range.
 
virtual iterator erase (const_iterator first, const_iterator last)
 Erases elements at specified range.
 
virtual void erase_at (size_t index)
 Erases element at specified index.
 
virtual void pop_back ()
 Removes the last element of the container.
 
virtual void push_back (value_type &&item)
 Adds an element to the end.
 
virtual void push_back_range (const arranged_element_collection &collection)
 Adds elements to the end.
 
virtual void push_back_range (const std::vector< value_type > &collection)
 Adds elements to the end.
 
virtual void push_back_range (const std::initializer_list< value_type > &collection)
 Adds elements to the end.
 
void push_back_range (collection_t &&collection)
 Adds elements to the end.
 
void push_back_range (iterator_t begin, iterator_t end)
 Adds elements to the end.
 
virtual void sort ()
 Sorts the content.
 
std::vector< control_refto_array () const noexcept
 Gets an array with the elements of the container.
 
std::vector< control_refto_vector () const noexcept
 Gets an array with the elements of the container.
 
reference operator[] (size_type pos)
 Access specified element.
 
const_reference operator[] (size_type pos) const
 Access specified element.
 
virtual void on_item_added (size_t index, control_ref &item)
 Raises the xtd::forms::layout::arranged_element_collection::item_added event.
 
virtual void on_item_updated (size_t index, control_ref &item)
 Raises the xtd::forms::layout::arranged_element_collection::item_updated event.
 
- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<typename object_t >
std::unique_ptr< object_t > memberwise_clone () const noexcept
 Creates a shallow copy of the current object.
 
virtual xtd::ustring to_string () const noexcept
 Returns a sxd::ustring that represents the current object.
 
- Static Public Member Functions inherited from xtd::object
static bool equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
static bool reference_equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 

Member Typedef Documentation

◆ base

Constructor & Destructor Documentation

◆ control_collection() [1/2]

xtd::forms::control::control_collection::control_collection ( const allocator_type allocator = allocator_type())
explicit

Creates a new object xtd::forms::control::control_collection with specified allocator (optional).

Parameters
allocatorThe allocator associate to the collection (optional).
Remarks
If allocator not specified, the std::allocator<value_type> is used.

◆ control_collection() [2/2]

xtd::forms::control::control_collection::control_collection ( bool  clone_and_keep_controls,
const allocator_type allocator = allocator_type() 
)
explicit

Creates a new object xtd::forms::control::control_collection with specified clone_and_keep_controls, and allocator (optional).

Parameters
clone_and_keep_controlsIf true the collection clone and keep controls; otherwise none.
allocatorThe allocator associate to the collection (optional).
Remarks
If allocator not specified, the std::allocator<value_type> is used.
Warning
Internal use only

Member Function Documentation

◆ emplace()

template<typename control_t , typename ... args_t>
control_t & xtd::forms::control::control_collection::emplace ( const_iterator  pos,
args_t &&...  args 
)
inline

Creates and inserts specified control at specified position.

Parameters
posThe iterator before which the content will be inserted. pos may be the xtd::forms::control::control_collection::end iterator.
argsThe arguments to forward to the create method of the control
Returns
A reference to the created control.
Remarks
The control will be destroyed automatically when the control no longer has a parent.
For creation and insertion, this method uses the xtd::forms::control::create methods of the various controls.
Examples
The folowing example demonstartes the use of xtd::forms::control::control_collection::emplace, xtd::forms::control::control_collection::emplace_at and xtd::forms::control::control_collection::emplace_back methods.
#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/form>
#include <xtd/forms/label>
using namespace xtd::drawing;
using namespace xtd::forms;
auto main()->int {
auto button1_clicked = 0, button2_clicked = 0;
auto form1 = xtd::forms::form::create("Emplace example");
form1.controls().emplace<xtd::forms::button>(form1.controls().begin(), "Button 1", point{50, 50}).click += [&] {
form1.controls()["label1"].value().get().text(xtd::ustring::format("Button 1 clicked {} times", ++button1_clicked));
};
form1.controls().emplace_at<xtd::forms::button>(1, "Button 2", point {50, 100}, size {200, 75}).auto_repeat(true).click += [&] {
form1.controls()["label2"].value().get().text(xtd::ustring::format("Button 2 clicked {} times", ++button2_clicked));
};
form1.controls().emplace<xtd::forms::label>(form1.controls().end(), "Button 1 clicked 0 times", point {50, 200}, size {200, 23}, "label1");
form1.controls().emplace_back<xtd::forms::label>("Button 2 clicked 0 times", point {50, 230}, size {200, 23}, "label2");
}
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition point.h:54
Stores an ordered pair of integers, which specify a height and width.
Definition size.h:31
static void run()
Begins running a standard application message loop on the current thread, without a form.
Represents a Windows button control.
Definition button.h:47
control_t & emplace_back(args_t &&...args)
Creates and adds a control to the end.
Definition control.h:245
event< control, event_handler > click
Occurs when the xtd::forms::control is clicked.
Definition control.h:1471
virtual control_collection & controls() noexcept
Gets the collection of controls contained within the control.
static form create()
A factory to create an xtd::forms::form.
Represents a standard Windows label.
Definition label.h:36
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition ustring.h:1131
size_t size
Represents a size of any object in bytes.
Definition types.h:197
The xtd::drawing namespace provides access to GDI+ basic graphics functionality. More advanced functi...
Definition actions_system_images.h:11
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition xtd_about_box.h:12

◆ emplace_at()

template<typename control_t , typename ... args_t>
control_t & xtd::forms::control::control_collection::emplace_at ( size_t  index,
args_t &&...  args 
)
inline

Creates and inserts specified control at specified position.

Parameters
indexThe index before which the content will be inserted.
argsThe arguments to forward to the create method of the control
Returns
A reference to the created control.
Remarks
The control will be destroyed automatically when the control no longer has a parent.
For creation and insertion, this method uses the xtd::forms::control::create methods of the various controls.
Examples
The folowing example demonstartes the use of xtd::forms::control::control_collection::emplace, xtd::forms::control::control_collection::emplace_at and xtd::forms::control::control_collection::emplace_back methods.
#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/form>
#include <xtd/forms/label>
using namespace xtd::drawing;
using namespace xtd::forms;
auto main()->int {
auto button1_clicked = 0, button2_clicked = 0;
auto form1 = xtd::forms::form::create("Emplace example");
form1.controls().emplace<xtd::forms::button>(form1.controls().begin(), "Button 1", point{50, 50}).click += [&] {
form1.controls()["label1"].value().get().text(xtd::ustring::format("Button 1 clicked {} times", ++button1_clicked));
};
form1.controls().emplace_at<xtd::forms::button>(1, "Button 2", point {50, 100}, size {200, 75}).auto_repeat(true).click += [&] {
form1.controls()["label2"].value().get().text(xtd::ustring::format("Button 2 clicked {} times", ++button2_clicked));
};
form1.controls().emplace<xtd::forms::label>(form1.controls().end(), "Button 1 clicked 0 times", point {50, 200}, size {200, 23}, "label1");
form1.controls().emplace_back<xtd::forms::label>("Button 2 clicked 0 times", point {50, 230}, size {200, 23}, "label2");
}

◆ emplace_back()

template<typename control_t , typename ... args_t>
control_t & xtd::forms::control::control_collection::emplace_back ( args_t &&...  args)
inline

Creates and adds a control to the end.

Parameters
argsThe arguments to forward to the create method of the control
Returns
A reference to the created control.
Remarks
The control will be destroyed automatically when the control no longer has a parent.
For creation and insertion, this method uses the xtd::forms::control::create methods of the various controls.
Examples
The folowing example demonstartes the use of xtd::forms::control::control_collection::emplace, xtd::forms::control::control_collection::emplace_at and xtd::forms::control::control_collection::emplace_back methods.
#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/form>
#include <xtd/forms/label>
using namespace xtd::drawing;
using namespace xtd::forms;
auto main()->int {
auto button1_clicked = 0, button2_clicked = 0;
auto form1 = xtd::forms::form::create("Emplace example");
form1.controls().emplace<xtd::forms::button>(form1.controls().begin(), "Button 1", point{50, 50}).click += [&] {
form1.controls()["label1"].value().get().text(xtd::ustring::format("Button 1 clicked {} times", ++button1_clicked));
};
form1.controls().emplace_at<xtd::forms::button>(1, "Button 2", point {50, 100}, size {200, 75}).auto_repeat(true).click += [&] {
form1.controls()["label2"].value().get().text(xtd::ustring::format("Button 2 clicked {} times", ++button2_clicked));
};
form1.controls().emplace<xtd::forms::label>(form1.controls().end(), "Button 1 clicked 0 times", point {50, 200}, size {200, 23}, "label1");
form1.controls().emplace_back<xtd::forms::label>("Button 2 clicked 0 times", point {50, 230}, size {200, 23}, "label2");
}

◆ insert()

iterator xtd::forms::control::control_collection::insert ( const_iterator  pos,
const value_type &  value 
)
overridevirtual

Inserts specified element at specified position.

Parameters
posThe iterator before which the content will be inserted. pos may be the arranged_element_collection::end iterator.
valueThe element to insert.

Reimplemented from xtd::forms::layout::arranged_element_collection< control_ref >.

◆ insert_at()

void xtd::forms::control::control_collection::insert_at ( size_t  index,
const value_type &  value 
)
overridevirtual

Inserts specified element at specified index.

Parameters
indexThe index before which the content will be inserted.
valueThe element to insert.

Reimplemented from xtd::forms::layout::arranged_element_collection< control_ref >.

◆ on_item_removed()

void xtd::forms::control::control_collection::on_item_removed ( size_t  index,
control_ref item 
)
inlineoverrideprotectedvirtual

Raises the xtd::forms::layout::arranged_element_collection::item_removed event.

Parameters
indexThe index of the item.
itemThe item removed.

Reimplemented from xtd::forms::layout::arranged_element_collection< control_ref >.

◆ operator[]() [1/2]

std::optional< value_type > xtd::forms::control::control_collection::operator[] ( const xtd::ustring name)

Gets the first xtd::forms::control::control_collection in the list with the specified name.

Parameters
nameThe name of the xtd::forms::control to get from the list.
Returns
The first xtd::forms::control in the list with the given Name. This item returns optional with no value if no xtd::forms::control with the given name can be found.
Remarks
The operator [] property is case-sensitive when searching for names. That is, if two controls exist with the names "Lname" and "lname", operator [] property will find only the xtd::forms::control with the xtd::forms::control::name() that you specify, not both.

◆ operator[]() [2/2]

std::optional< value_type > xtd::forms::control::control_collection::operator[] ( const xtd::ustring name) const

Gets the first xtd::forms::control::control_collection in the list with the specified name.

Parameters
nameThe name of the xtd::forms::control to get from the list.
Returns
The first xtd::forms::control in the list with the given Name. This item returns optional with no value if no xtd::forms::control with the given name can be found.
Remarks
The operator [] property is case-sensitive when searching for names. That is, if two controls exist with the names "Lname" and "lname", operator [] property will find only the xtd::forms::control with the xtd::forms::control::name() that you specify, not both.

◆ push_back()

void xtd::forms::control::control_collection::push_back ( const value_type &  item)
overridevirtual

Adds an element to the end.

Parameters
itemThe element to add.

Reimplemented from xtd::forms::layout::arranged_element_collection< control_ref >.


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