xtd 0.2.0
tool_bar.cpp

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

Windows

macOS

Gnome

#include <xtd/drawing/texts>
#include <xtd/forms/application>
#include <xtd/forms/choice>
#include <xtd/forms/form>
#include <xtd/forms/list_box>
#include <xtd/forms/progress_bar>
#include <xtd/forms/timer>
#include <xtd/forms/tool_bar>
#include <xtd/forms/tool_bar_images>
using namespace xtd;
using namespace xtd::drawing;
using namespace xtd::forms;
namespace tool_bar_example {
class form1 : public form {
public:
form1() {
text("Toolbar example");
client_size({820, 500});
controls().push_back_range({list_box1, tool_bar2, tool_bar1});
tool_bar(tool_bar1);
active_control(list_box1);
list_box1.dock(dock_style::fill);
choice1.items().push_back_range({"Item1", "Item2", "Item3", "Item4", "Item5", "Item6", "Item7", "Item8", "Item9", "Item10"});
choice1.selected_index(0);
choice1.selected_value_changed += [&] {
list_box1.items().push_back(string::format("{} selected", choice1.selected_item()));
list_box1.selected_index(list_box1.items().size() - 1);
};
progress_bar1.width(150);
progress_timer1.interval_milliseconds(50);
progress_timer1.start();
progress_timer1.tick += [&] {
progress_bar1.value(progress_bar1.value() < progress_bar1.maximum() ? progress_bar1.value() + 1 : progress_bar1.minimum());
};
tool_bar1.buttons().push_back_range({new_tool_bar_button, open_tool_bar_button, save_tool_bar_button, print_tool_bar_button, tool_bar1_separator1, cut_tool_bar_button, copy_tool_bar_button, paste_tool_bar_button, tool_bar1_separator2, choice_tool_bar_button, tool_bar1_separator3, help_tool_bar_button});
tool_bar1.button_click += {*this, &form1::on_tool_bar_button_click};
tool_bar2.dock(dock_style::bottom);
tool_bar2.show_text(true);
tool_bar2.image_list().image_size({24, 24});
tool_bar2.image_list().images().push_back_range({tool_bar_images::from_name("media-playback-start"), tool_bar_images::from_name("media-skip-backward"), tool_bar_images::from_name("media-playback-stop"), tool_bar_images::from_name("media-skip-forward"), tool_bar_images::from_name("media-record"), tool_bar_images::from_name("media-eject")});
tool_bar2.buttons().push_back_range({play_tool_bar_button, tool_bar2_separator1, skip_backward_tool_bar_button, stop_tool_bar_button, skip_forward_tool_bar_button, tool_bar2_separator2, record_tool_bar_button, tool_bar2_separator3, progress_tool_bar_button, tool_bar2_separator4, eject_tool_bar_button});
tool_bar2.button_click += {*this, &form1::on_tool_bar_button_click};
record_tool_bar_button.enabled(false);
}
private:
void on_tool_bar_button_click(object& sender, const tool_bar_button_click_event_args& e) {
if (e.button().style() == tool_bar_button_style::toggle_button)
list_box1.items().push_back(string::format("Button {} clicked, pushed = {}", e.button().text(), e.button().pushed()));
else
list_box1.items().push_back(string::format("Button {} clicked", e.button().text()));
list_box1.selected_index(list_box1.items().size() - 1);
}
void on_menu_click(object& sender, const event_args& e) {
list_box1.items().push_back(string::format("Menu item {} clicked", as<menu_item>(sender).text()));
list_box1.selected_index(list_box1.items().size() - 1);
}
list_box list_box1;
menu_item context_help_context_menu_item {"Help context", {*this, &form1::on_menu_click}};
menu_item context_help_index_menu_item {"Help index", {*this, &form1::on_menu_click}};
menu_item context_help_search_menu_item {"Help search", {*this, &form1::on_menu_click}};
menu_item context_separator_menu_item {"-"};
menu_item context_about_menu_item {texts::about(), {*this, &form1::on_menu_click}};
forms::context_menu context_menu1 {context_help_context_menu_item, context_help_index_menu_item, context_help_search_menu_item, context_separator_menu_item, context_about_menu_item};
forms::tool_bar tool_bar1;
choice choice1;
tool_bar_button choice_tool_bar_button = tool_bar_button::create_control("Items", choice1);
tool_bar_button help_tool_bar_button = tool_bar_button::create_drop_down_button(texts::help(), 7, context_menu1);
forms::tool_bar tool_bar2;
progress_bar progress_bar1;
timer progress_timer1;
tool_bar_button play_tool_bar_button = tool_bar_button::create_push_button("&Play", 0);
tool_bar_button skip_backward_tool_bar_button = tool_bar_button::create_push_button("Skip &Backward", 1);
tool_bar_button stop_tool_bar_button = tool_bar_button::create_push_button("S&top", 2);
tool_bar_button skip_forward_tool_bar_button = tool_bar_button::create_push_button("Skip &Forward", 3);
tool_bar_button record_tool_bar_button = tool_bar_button::create_push_button("&Record", 4);
tool_bar_button progress_tool_bar_button = tool_bar_button::create_control(progress_bar1);
tool_bar_button eject_tool_bar_button = tool_bar_button::create_toggle_button("&Eject", 5);
};
}
auto main() -> int {
application::run(tool_bar_example::form1 {});
}
static xtd::string help()
Gets a system-defined text that has a string value of "&Help". This field is constant.
static xtd::string new_()
Gets a system-defined text that has a string value of "&New". This field is constant.
static xtd::string print()
Gets a system-defined text that has a string value of "&Print...". This field is constant.
static xtd::string save()
Gets a system-defined text that has a string value of "&Save". This field is constant.
static xtd::string cut()
Gets a system-defined text that has a string value of "Cu&t". This field is constant.
static xtd::string copy()
Gets a system-defined text that has a string value of "&Copy". This field is constant.
static xtd::string open()
Gets a system-defined text that has a string value of "&Open...". This field is constant.
static xtd::string paste()
Gets a system-defined text that has a string value of "&Paste". This field is constant.
static xtd::string about()
Gets a system-defined text that has a string value of "&About". This field is constant.
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition event_args.hpp:18
static void run()
Begins running a standard application message loop on the current thread, without a form.
Represents a choice control.
Definition choice.hpp:37
Represents a shortcut menu.
Definition context_menu.hpp:36
Represents a window or dialog box that makes up an application's user interface.
Definition form.hpp:54
Represents an individual item that is displayed within a main_menu or context_menu.
Definition menu_item.hpp:31
Represents a Windows progress bar control.
Definition progress_bar.hpp:40
Implements a timer that raises an event at user-defined intervals. This timer is optimized for use in...
Definition timer.hpp:38
Provides data for the xtd::forms::tool_bar::button_click event.
Definition tool_bar_button_click_event_args.hpp:25
Represents a toolbar button.
Definition tool_bar_button.hpp:43
static tool_bar_button create_stretchable_separator()
A factory to create a toolbar stretchable separator.
static tool_bar_button create_push_button(const xtd::string &text)
A factory to create a toolbar button with specified text.
static tool_bar_button create_separator()
A factory to create a toolbar separator.
static tool_bar_button create_control(const xtd::string &text, const xtd::forms::control &control)
A factory to create a control toolbar button with specified text and control.
static tool_bar_button create_drop_down_button(const xtd::string &text, const xtd::forms::context_menu &drop_down_menu)
A factory to create a drop-down toolbar button with specified text and context menu.
static tool_bar_button create_toggle_button(const xtd::string &text)
A factory to create a toolbar toggle button with specified text.
static xtd::drawing::image file_new()
File new image object.
static xtd::drawing::image file_open()
File open image object.
static xtd::drawing::image edit_cut()
Edit cut image object.
static xtd::drawing::image file_save()
File save image object.
static xtd::drawing::image help()
Help about image object.
static xtd::drawing::image file_print()
File print image object.
static xtd::drawing::image edit_paste()
Edit paste image object.
static xtd::drawing::image from_name(const xtd::string &name)
Gets image object with specified name.
static xtd::drawing::image edit_copy()
Edit copy image object.
Represents a Windows toolbar.
Definition tool_bar.hpp:52
type_t as(any_object &o)
Casts a type into another type.
Definition __as_any_object.hpp:59
@ e
The E key.
Definition console_key.hpp:96
@ right
The text is aligned to the right of the toolbar button image.
Definition tool_bar_text_align.hpp:27
@ toggle_button
A toggle button that appears sunken when clicked and retains the sunken appearance until clicked agai...
Definition tool_bar_button_style.hpp:27
@ bottom
The control's bottom edge is docked to the bottom of its containing control.
Definition dock_style.hpp:29
@ fill
All the control's edges are docked to the all edges of its containing control and sized appropriately...
Definition dock_style.hpp:35
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