xtd 0.2.0
Loading...
Searching...
No Matches
css_reader.cpp

Shows how to use xtd::web::css:css_reader class.

#include <xtd/web/css/css_reader>
#include <xtd/console>
using namespace xtd;
using namespace xtd::web::css;
void write_selectors(const selector_map& selectors) {
for (auto [name, contents] : selectors) {
console::write_line("{} {{", name);
for (auto [key, value] : contents.properties())
xtd::console::write_line(" {}: {};", key, value);
console::write_line("}");
}
}
auto main()->int {
auto reader = css_reader {".user_box {\n"
" display: none;\n"
" position: fixed;\n"
" z-index: 100;\n"
" width: 100%;\n"
" height: 100%;\n"
" left: 300;\n"
" top: 200;\n"
" background: #4080FA;\n"
" filter: alpha(opacity=40);\n"
" opacity: 0.4;\n"
"}"};
console::write_line("Write all selectors and all properties :");
console::write_line("----------------------------------------");
write_selectors(reader.selectors());
console::write_line();
console::write_line("Get specific properties :");
console::write_line("-------------------------");
console::write_line("filter = {}", reader.selectors().at(".user_box").properties().at("filter"));
console::write_line("opacity = {}", reader.selectors().at(".user_box").properties().at("opacity").to_single());
console::write_line("z-index = {}", reader.selectors().at(".user_box").properties().at("z-index").to<int>());
}
// This code can produces the following output :
//
// Write all selectors and all properties :
// ----------------------------------------
// .user_box {
// background: #4080FA;
// display: none;
// filter: alpha(opacity=40);
// height: 100%;
// left: 300;
// opacity: 0.4;
// position: fixed;
// top: 200;
// width: 100%;
// z-index: 100;
// }
//
// Get specific properties :
// -------------------------
// filter = alpha(opacity=40)
// opaicty = 0.4
// z-index = 100
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
Definition css_reader.h:16
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
std::map< xtd::ustring, xtd::web::css::selector > selector_map
Represents the map of a selector name - selector pair.
Definition selector_map.h:13