timage: allowed use of width/height keys for specific image size

This commit is contained in:
Charles Dang 2016-08-14 23:43:50 +11:00
parent 336bcda82a
commit 05340bb81f
4 changed files with 43 additions and 2 deletions

View file

@ -1477,6 +1477,16 @@
min="0"
max="-1"
super="generic/widget_instance"
[key]
name="width"
type="unsigned"
default=0
[/key]
[key]
name="height"
type="unsigned"
default=0
[/key]
[/tag]
[tag]
name="instance"

View file

@ -24,6 +24,8 @@
[image]
name = "(text)"
w = "(width)"
h = "(height)"
[/image]
[/draw]

View file

@ -49,6 +49,9 @@ tpoint timage::calculate_best_size() const
const tpoint maximum = get_config_maximum_size();
tpoint result = tpoint(image->w, image->h);
if(best_size_ != tpoint(0, 0)) {
result = best_size_;
}
if(minimum.x > 0 && result.x < minimum.x) {
DBG_GUI_L << LOG_HEADER << " increase width to minimum.\n";
@ -162,7 +165,10 @@ timage_definition::tresolution::tresolution(const config& cfg)
namespace implementation
{
tbuilder_image::tbuilder_image(const config& cfg) : tbuilder_control(cfg)
tbuilder_image::tbuilder_image(const config& cfg)
: tbuilder_control(cfg)
, width(cfg["width"])
, height(cfg["height"])
{
}
@ -172,6 +178,15 @@ twidget* tbuilder_image::build() const
init_control(widget);
const game_logic::map_formula_callable& size = get_screen_size_variables();
const unsigned w = width(size);
const unsigned h = height(size);
if(w || h) {
widget->set_best_size(tpoint(w, h));
}
DBG_GUI_G << "Window builder: placed image '" << id << "' with definition '"
<< definition << "'.\n";

View file

@ -29,7 +29,7 @@ namespace gui2
class timage : public tcontrol
{
public:
timage() : tcontrol(COUNT)
timage() : tcontrol(COUNT), best_size_(0, 0)
{
}
@ -61,6 +61,11 @@ public:
virtual bool can_mouse_focus() const override { return !tooltip().empty(); }
void set_best_size(const tpoint& best_size)
{
best_size_ = best_size;
}
/***** ***** ***** ***** layout functions ***** ***** ***** *****/
private:
@ -93,6 +98,9 @@ private:
COUNT
};
/** When we're used as a fixed size item, this holds the best size. */
tpoint best_size_;
/** See @ref tcontrol::get_control_type. */
virtual const std::string& get_control_type() const override;
};
@ -120,6 +128,12 @@ struct tbuilder_image : public tbuilder_control
using tbuilder_control::build;
/** The width of the widget. */
tformula<unsigned> width;
/** The height of the widget. */
tformula<unsigned> height;
twidget* build() const;
};