graphic ACTIVE "dark_grey_sunken";
};
- special "text"
+ part "text"
{
align 0.5 0.5;
fill 0.0 0.0;
margin { left 2; };
};
- special "text"
+ part "text"
{
align 0.0 0.5;
fill 0.0 0.0;
margin { left 3; };
};
- special "text"
+ part "text"
{
align 0.0 0.5;
fill 0.0 0.0;
{
font_color 0.0 0.0 0.0;
- special "text"
+ part "text"
{
align 0.5 0.5;
fill 0.0 0.0;
graphic NORMAL "white_sunken";
};
- special "text"
+ part "text"
{
align 0.0 0.5;
fill 0.0 0.0;
margin { left 3; right 3; top 3; bottom 3; };
};
- special "cursor"
+ part "cursor"
{
graphic FOCUS "entry_cursor";
align 0.0 0.0;
graphic NORMAL "dark_grey_sunken_shallow";
};
- special "slider"
+ part "slider"
{
graphic NORMAL "hthumb";
graphic HOVER "hthumb_light";
graphic NORMAL "dark_grey_sunken_shallow";
};
- special "slider"
+ part "slider"
{
graphic NORMAL "vthumb";
graphic HOVER "vthumb_light";
margin { right 12; };
};
- special "slider"
+ part "slider"
{
size 12 12;
fill 0.0 1.0;
//margin { right 1; top 1; bottom 1; };
};
- special "selection"
+ part "selection"
{
graphic NORMAL "blue_flat";
margin { left 3; right 14; top 3; bottom 3; };
};
- special "items"
+ part "items"
{
margin { left 3; right 14; top 3; bottom 3; };
};
margin { right 3; };
};
- special "text"
+ part "text"
{
fill 0.0 0.0;
align 0.0 0.5;
margin { left 4; };
};
- special "list";
+ part "list";
};
graphic "grey_beveled"
graphic NORMAL "grey_beveled";
};
- special "children";
+ part "children";
};
style "root"
{
- special "children";
+ part "children";
};
const Style &stl = list.get_style();
const GL::Font &font = *stl.get_font();
unsigned h = min(max(n_items, 1U), 10U)*static_cast<unsigned>((font.get_ascent()-font.get_descent())*font.get_default_size());
- for(std::list<Part>::const_iterator i=stl.get_parts().begin(); i!=stl.get_parts().end(); ++i)
- if(i->get_name()=="items")
- {
- const Sides &margin = i->get_margin();
- h += margin.top+margin.bottom;
- }
+ if(const Part *items_part = stl.get_part("items"))
+ {
+ const Sides &margin = items_part->get_margin();
+ h += margin.top+margin.bottom;
+ }
list.set_geometry(Geometry(0, -h, geom.w, h));
}
void Entry::on_style_change()
{
- text_part = 0;
- for(list<Part>::const_iterator i=style->get_parts().begin(); i!=style->get_parts().end(); ++i)
- if(i->get_name()=="text")
- text_part = &*i;
+ text_part = style->get_part("text");
text.set_style(style);
reposition_slider();
if(!slider)
return;
- for(list<Part>::const_iterator i=style->get_parts().begin(); i!=style->get_parts().end(); ++i)
- if(i->get_name()=="slider")
- {
- Geometry sgeom = i->get_geometry();
- i->get_alignment().apply(sgeom, geom, i->get_margin());
- slider->set_geometry(sgeom);
- }
+ if(const Part *slider_part = style->get_part("slider"))
+ {
+ Geometry sgeom = slider_part->get_geometry();
+ slider_part->get_alignment().apply(sgeom, geom, slider_part->get_margin());
+ slider->set_geometry(sgeom);
+ }
}
void Entry::slider_value_changed(double value)
void HSlider::on_style_change()
{
- for(PartSeq::const_iterator i=style->get_parts().begin(); i!=style->get_parts().end(); ++i)
- if(i->get_name()=="slider")
- slider_size = i->get_geometry().w;
+ if(const Part *slider_part = style->get_part("slider"))
+ slider_size = slider_part->get_geometry().w;
on_geometry_change();
}
void Label::autosize()
{
- const list<Part> &parts = style->get_parts();
- const Part *text_part = 0;
- for(list<Part>::const_iterator i=parts.begin(); (!text_part && i!=parts.end()); ++i)
- if(i->get_name()=="text")
- text_part = &*i;
-
geom.h = text.get_height();
geom.w = text.get_width();
- if(text_part)
+ if(const Part *text_part = style->get_part("text"))
{
const Sides &margin = text_part->get_margin();
geom.w += margin.left+margin.right;
{
reposition_slider();
- items_part = 0;
- for(list<Part>::const_iterator i=style->get_parts().begin(); i!=style->get_parts().end(); ++i)
- if(i->get_name()=="items")
- items_part = &*i;
+ items_part = style->get_part("items");
const GL::Font &font = *style->get_font();
row_height = static_cast<unsigned>((font.get_ascent()-font.get_descent())*font.get_default_size());
void List::reposition_slider()
{
- for(list<Part>::const_iterator i=style->get_parts().begin(); i!=style->get_parts().end(); ++i)
- if(i->get_name()=="slider")
- {
- Geometry sgeom = i->get_geometry();
- i->get_alignment().apply(sgeom, geom, i->get_margin());
- slider.set_geometry(sgeom);
- }
+ if(const Part *slider_part = style->get_part("slider"))
+ {
+ Geometry sgeom = slider_part->get_geometry();
+ slider_part->get_alignment().apply(sgeom, geom, slider_part->get_margin());
+ slider.set_geometry(sgeom);
+ }
}
void List::recalculate_parameters()
font(&r.get_default_font())
{ }
+const Part *Style::get_part(const string &name) const
+{
+ for(PartSeq::const_iterator i=parts.begin(); i!=parts.end(); ++i)
+ if(i->get_name()==name)
+ return &*i;
+
+ return 0;
+}
+
Style::Loader::Loader(Style &s, Resources &r):
style(s),
{
add("font", &Style::font);
add("font_color", &Loader::font_color);
- add("part", &Loader::part);
- add("special", &Loader::special);
+ add("part", static_cast<void (Loader::*)()>(&Loader::part));
+ add("part", static_cast<void (Loader::*)(const std::string &)>(&Loader::part));
+ // Deprecated alias
+ add("special", static_cast<void (Loader::*)(const std::string &)>(&Loader::part));
}
void Style::Loader::font_color(float r, float g, float b)
void Style::Loader::part()
{
- Part p((string()));
- load_sub(p, res);
- style.parts.push_back(p);
+ part(string());
}
-void Style::Loader::special(const string &n)
+void Style::Loader::part(const string &n)
{
Part p(n);
load_sub(p, res);
void font(const std::string &);
void font_color(float, float, float);
void part();
- void special(const std::string &);
+ void part(const std::string &);
};
private:
const GL::Font *get_font() const { return font; }
const GL::Color &get_font_color() const { return font_color; }
const PartSeq &get_parts() const { return parts; }
+ const Part *get_part(const std::string &) const;
};
} // namespace GLtk
void VSlider::on_style_change()
{
- for(PartSeq::const_iterator i=style->get_parts().begin(); i!=style->get_parts().end(); ++i)
- if(i->get_name()=="slider")
- slider_size = i->get_geometry().h;
+ if(const Part *slider_part = style->get_part("slider"))
+ slider_size = slider_part->get_geometry().h;
on_geometry_change();
}