add new inputbox::boolean

other fixes for width of inputbox's elements
This commit is contained in:
Jinhao 2017-07-20 23:46:20 +08:00
parent d53254b89a
commit 0cfd06b23f
2 changed files with 129 additions and 22 deletions

View File

@ -109,6 +109,24 @@ namespace nana
virtual unsigned fixed_pixels() const;
};
public:
class boolean
: public abstract_content
{
struct implement;
public:
boolean(::std::string label, bool initial_value);
~boolean();
bool value() const;
private:
//Implementation of abstract_content
const ::std::string& label() const override;
window create(window, unsigned label_px) override;
unsigned fixed_pixels() const override;
private:
std::unique_ptr<implement> impl_;
};
class integer
: public abstract_content
{
@ -122,6 +140,7 @@ namespace nana
//Implementation of abstract_content
const ::std::string& label() const override;
window create(window, unsigned label_px) override;
unsigned fixed_pixels() const override;
private:
std::unique_ptr<implement> impl_;
};
@ -139,6 +158,7 @@ namespace nana
//Implementation of abstract_content
const ::std::string& label() const override;
window create(window, unsigned label_px) override;
unsigned fixed_pixels() const override;
private:
std::unique_ptr<implement> impl_;
};
@ -166,6 +186,7 @@ namespace nana
//Implementation of abstract_content
const ::std::string& label() const override;
window create(window, unsigned label_px) override;
unsigned fixed_pixels() const override;
private:
std::unique_ptr<implement> impl_;
};

View File

@ -14,6 +14,7 @@
#include <nana/gui/widgets/label.hpp>
#include <nana/gui/widgets/button.hpp>
#include <nana/gui/widgets/spinbox.hpp>
#include <nana/gui/widgets/checkbox.hpp>
#include <nana/gui/widgets/combox.hpp>
#include <nana/gui/widgets/textbox.hpp>
#include <nana/gui/widgets/panel.hpp>
@ -526,8 +527,8 @@ namespace nana
ss_content << "><margin=[15] weight=38<><buttons arrange=80 gap=10 weight=170>>>";
if (desc_extent.width < 170)
desc_extent.width = 170;
if (desc_extent.width < 200)
desc_extent.width = 200;
//Make sure the complete display of input extent
if (desc_extent.width < fixed_pixels)
@ -653,6 +654,70 @@ namespace nana
return 0;
}
//class boolean
struct inputbox::boolean::implement
{
bool value;
::std::string empty_label_text;
::std::string label_text;
::nana::panel<false> dock;
::nana::checkbox checkbox;
};
inputbox::boolean::boolean(::std::string label, bool initial_value)
: impl_(new implement)
{
impl_->value = initial_value;
impl_->label_text = std::move(label);
impl_->empty_label_text = " ";
}
inputbox::boolean::~boolean()
{}
bool inputbox::boolean::value() const
{
return (impl_->checkbox.empty() ? impl_->value : impl_->checkbox.checked());
}
//Implementation of abstract_content
const ::std::string& inputbox::boolean::label() const
{
return impl_->empty_label_text;
}
window inputbox::boolean::create(window owner, unsigned label_px)
{
auto impl = impl_.get();
impl->dock.create(owner);
paint::graphics graph{ ::nana::size{ 10, 10 } };
auto value_px = graph.text_extent_size(impl->label_text).width + 20;
impl->checkbox.create(impl->dock, rectangle{ (std::max)(static_cast<int>(label_px) - 18, 0), 0, value_px, 0 });
impl->checkbox.check(impl->value);
impl->checkbox.caption(impl->label_text);
impl->dock.events().resized.connect_unignorable([impl, value_px](const ::nana::arg_resized&)
{
impl->checkbox.size({ value_px, 24 });
});
impl->checkbox.events().destroy.connect_unignorable([impl](const arg_destroy&)
{
impl->value = impl->checkbox.checked();
});
return impl->dock;
}
unsigned inputbox::boolean::fixed_pixels() const
{
paint::graphics graph{ ::nana::size{ 10, 10 } };
return graph.text_extent_size(impl_->label_text).width;
}
//class integer
struct inputbox::integer::implement
{
@ -705,10 +770,7 @@ namespace nana
impl->label.caption(impl->label_text);
impl->label.format(true);
//get the longest value
int longest = (std::abs(static_cast<int>(impl->begin < 0 ? impl->begin * 10 : impl->begin)) < std::abs(static_cast<int>(impl->last < 0 ? impl->last * 10 : impl->last)) ? impl->last : impl->begin);
paint::graphics graph{ ::nana::size{ 10, 10 } };
auto value_px = graph.text_extent_size(std::to_wstring(longest)).width + 34;
auto const value_px = fixed_pixels();
impl->spinbox.create(impl->dock, rectangle{ static_cast<int>(label_px + 10), 0, value_px, 0 });
impl->spinbox.range(impl->begin, impl->last, impl->step);
@ -728,6 +790,14 @@ namespace nana
return impl->dock;
}
unsigned inputbox::integer::fixed_pixels() const
{
//get the longest value
int longest = (std::abs(static_cast<int>(impl_->begin < 0 ? impl_->begin * 10 : impl_->begin)) < std::abs(static_cast<int>(impl_->last < 0 ? impl_->last * 10 : impl_->last)) ? impl_->last : impl_->begin);
paint::graphics graph{ ::nana::size{ 10, 10 } };
return graph.text_extent_size(std::to_wstring(longest)).width + 34;
}
//end class integer
@ -783,10 +853,7 @@ namespace nana
impl->label.caption(impl->label_text);
impl->label.format(true);
//get the longest value
auto longest = (std::abs(static_cast<int>(impl->begin < 0 ? impl->begin * 10 : impl->begin)) < std::abs(static_cast<int>(impl->last < 0 ? impl->last * 10 : impl->last)) ? impl->last : impl->begin);
paint::graphics graph{ ::nana::size{ 10, 10 } };
auto value_px = graph.text_extent_size(std::to_wstring(longest)).width + 34;
auto value_px = fixed_pixels();
impl->spinbox.create(impl->dock, rectangle{ static_cast<int>(label_px + 10), 0, value_px, 0 });
impl->spinbox.range(impl->begin, impl->last, impl->step);
@ -806,6 +873,14 @@ namespace nana
return impl->dock;
}
unsigned inputbox::real::fixed_pixels() const
{
//get the longest value
auto longest = (std::abs(static_cast<int>(impl_->begin < 0 ? impl_->begin * 10 : impl_->begin)) < std::abs(static_cast<int>(impl_->last < 0 ? impl_->last * 10 : impl_->last)) ? impl_->last : impl_->begin);
paint::graphics graph{ ::nana::size{ 10, 10 } };
return graph.text_extent_size(std::to_wstring(longest)).width + 34;
}
//end class real
@ -887,7 +962,7 @@ namespace nana
impl->label.caption(impl->label_text);
impl->label.format(true);
unsigned value_px = 0;
unsigned const value_px = fixed_pixels();
if (impl->options.empty())
{
impl->textbox.create(impl->dock, rectangle{ static_cast<int>(label_px + 10), 0, 0, 0 });
@ -898,16 +973,6 @@ namespace nana
}
else
{
//get the longest value
paint::graphics graph{ ::nana::size{ 10, 10 } };
for (auto & s : impl->options)
{
auto px = graph.text_extent_size(s).width;
if (px > value_px)
value_px = px;
}
value_px += 34;
impl->combox.create(impl->dock, rectangle{ static_cast<int>(label_px + 10), 0, value_px, 0 });
for (auto & s : impl->options)
@ -919,7 +984,7 @@ namespace nana
impl->dock.events().resized.connect_unignorable([impl, label_px, value_px](const ::nana::arg_resized& arg)
{
impl->label.size({ label_px, arg.height });
if (value_px)
if (impl->textbox.empty())
impl->combox.size({ value_px, 24 });
else
impl->textbox.size({arg.width - label_px - 10, 24});
@ -932,6 +997,24 @@ namespace nana
});
return impl->dock;
}
unsigned inputbox::text::fixed_pixels() const
{
if (impl_->options.empty())
return 0;
paint::graphics graph{ ::nana::size{ 10, 10 } };
unsigned long_px = 0;
//get the longest value
for (auto & s : impl_->options)
{
auto px = graph.text_extent_size(s).width;
if (px > long_px)
long_px = px;
}
return long_px + 34;
}
//end class text
@ -1212,6 +1295,9 @@ namespace nana
each_pixels.push_back(px.height);
}
//if (fixed_px < 150)
// fixed_px = 150;
inputbox_window input_wd(owner_, images_, valid_areas_, description_, title_, contents.size(), label_px + 10 + fixed_px, each_pixels);
std::vector<window> inputs;