xtd 0.2.0
images.cpp

demonstrates the use of xtd::forms::images component.

Windows

macOS

Gnome

#include <xtd/drawing/texts>
#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/button_images>
#include <xtd/forms/choice>
#include <xtd/forms/form>
#include <xtd/forms/label>
#include <xtd/forms/picture_box>
#include <xtd/drawing/system_colors>
using namespace xtd;
using namespace xtd::drawing;
using namespace xtd::forms;
namespace example {
class form1 : public form {
public:
form1() {
text("Images example");
client_size({430, 530});
minimum_client_size(client_size());
controls().push_back_range({choice_theme, choice_context, choice_size, picture, label_picture_name, button_previous, button_next});
picture.back_color(system_colors::window());
picture.border_style(forms::border_style::fixed_3d);
picture.bounds({75, 125, 280, 280});
picture.anchor(anchor_styles::all);
choice_theme.bounds({75, 25, 280, 25});
choice_theme.items().push_back("current theme");
sort(names.begin(), names.end());
choice_theme.items().push_back_range(names);
choice_theme.selected_index(0);
choice_theme.selected_index_changed += event_handler(*this, &form1::update_form);
choice_context.bounds({75, 55, 280, 25});
choice_context.items().push_back_range(images::contexts());
choice_context.selected_index(0);
choice_context.selected_index_changed += [&] {
current_image_index = 0;
update_form();
};
choice_size.bounds({75, 85, 280, 25});
for (auto size : images::sizes())
choice_size.items().push_back({string::format("{}x{} pixels", size.width, size.height), size});
choice_size.selected_index(7);
choice_size.selected_index_changed += event_handler(*this, &form1::update_form);
label_picture_name.bounds({75, 420, 280, label_picture_name.height()});
label_picture_name.text_align(content_alignment::middle_center);
button_previous.auto_repeat(true);
button_previous.bounds({75, 460, 125, 40});
button_previous.anchor(anchor_styles::bottom | anchor_styles::left);
button_previous.enabled(false);
button_previous.image(button_images::previous());
button_previous.image_align(content_alignment::middle_left);
button_previous.text(texts::previous());
button_previous.click += [&] {
if (current_image_index > 0) --current_image_index;
update_form();
};
button_next.auto_repeat(true);
button_next.bounds({230, 460, 125, 40});
button_next.image(button_images::next());
button_next.image_align(content_alignment::middle_right);
button_next.text(texts::next());
button_next.click += [&] {
if (current_image_index < images::names(choice_context.selected_item().value()).size()) ++current_image_index;
update_form();
};
update_form();
}
private:
void update_form() {
picture.image(images::from_name(choice_theme.selected_item().value(), images::names(choice_context.selected_item().value())[current_image_index], any_cast<drawing::size>(choice_size.selected_item().tag())) != drawing::image::empty ? images::from_name(choice_theme.selected_index() == 0 ? application::style_sheet().theme().name() : choice_theme.selected_item().value(), images::names(choice_context.selected_item().value())[current_image_index], any_cast<drawing::size>(choice_size.selected_item().tag())) : images::from_name("image-missing", any_cast<drawing::size>(choice_size.selected_item().tag())));
label_picture_name.text(images::names(choice_context.selected_item().value())[current_image_index]);
button_previous.enabled(current_image_index > 0);
button_next.enabled(current_image_index < images::names(choice_context.selected_item().value()).size() - 1);
}
size_t current_image_index = 0;
choice choice_theme;
choice choice_context;
choice choice_size;
picture_box picture;
label label_picture_name;
button button_previous;
button button_next;
};
}
auto main() -> int {
application::run(example::form1 {});
}
static image empty
Represent an empty xtd::drawing::image.
Definition image.hpp:65
static xtd::drawing::color window()
Gets a xtd::drawing::color structure that is the color of the background in the client area of a wind...
static xtd::string previous()
Gets a system-defined text that has a string value of "&Previous". This field is constant.
static xtd::string next()
Gets a system-defined text that has a string value of "&Next". This field is constant.
static const xtd::forms::style_sheets::style_sheet & style_sheet() noexcept
Gets current xtd::forms::style_sheets::style_sheet style sheet.
static void run()
Begins running a standard application message loop on the current thread, without a form.
static const xtd::forms::style_sheets::style_sheet::style_sheet_names_t & style_sheet_names() noexcept
Gets the installed xtd::forms::style_sheets::style_sheet style sheet names.
static xtd::drawing::image next()
Next image object.
Definition button_images.hpp:98
static xtd::drawing::image previous()
Previous image object.
Definition button_images.hpp:132
Represents a Windows button control.
Definition button.hpp:49
Represents a choice control.
Definition choice.hpp:37
Represents a window or dialog box that makes up an application's user interface.
Definition form.hpp:54
static xtd::array< xtd::string > names() noexcept
Gets the image names.
Definition images.hpp:856
static xtd::array< xtd::string > contexts() noexcept
Gets the image contexts.
Definition images.hpp:69
static xtd::array< xtd::drawing::size > sizes() noexcept
Gets standard sizes for image.
Definition images.hpp:1258
static xtd::drawing::image from_name(const xtd::string &name)
Gets image object with specified name.
Definition images.hpp:1268
Represents a standard Windows label.
Definition label.hpp:38
Represents a standard Windows picture box.
Definition picture_box.hpp:34
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
@ center_image
The image is displayed in the center if the picture_box is larger than the image. If the image is lar...
Definition picture_box_size_mode.hpp:30
@ fixed_3d
A three-dimensional border. Same as xtd::forms::border_style::inset.
Definition border_style.hpp:58
@ bottom
Bind control edges to the bottom of its container.
Definition anchor_styles.hpp:25
@ right
Bind control edges to the right of its container.
Definition anchor_styles.hpp:29
@ left
Bind control edges to the left of its container.
Definition anchor_styles.hpp:27
@ all
All flags except none.
Definition anchor_styles.hpp:31
@ top
Bind control edges to the top of its container.
Definition anchor_styles.hpp:23
@ middle_left
Content is vertically aligned in the middle, and horizontally aligned on the left.
Definition content_alignment.hpp:29
@ middle_center
Content is vertically aligned at the middle, and horizontally aligned at the center.
Definition content_alignment.hpp:31
@ middle_right
Content is vertically aligned at the middle, and horizontally aligned on the right.
Definition content_alignment.hpp:33
The xtd::drawing namespace provides access to GDI+ basic graphics functionality. More advanced functi...
Definition actions_system_images.hpp:10
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition texts.hpp:217
Contains classes that represent ASCII and Unicode character encodings; abstract base classes for conv...
Definition basic_string_builder.hpp:16
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8