From 0cfd06b23f02b238df920fe01a701fec1fcffe3e Mon Sep 17 00:00:00 2001 From: Jinhao Date: Thu, 20 Jul 2017 23:46:20 +0800 Subject: [PATCH] add new inputbox::boolean other fixes for width of inputbox's elements --- include/nana/gui/msgbox.hpp | 21 ++++++ source/gui/msgbox.cpp | 130 ++++++++++++++++++++++++++++++------ 2 files changed, 129 insertions(+), 22 deletions(-) diff --git a/include/nana/gui/msgbox.hpp b/include/nana/gui/msgbox.hpp index e23c043e..a53e2264 100644 --- a/include/nana/gui/msgbox.hpp +++ b/include/nana/gui/msgbox.hpp @@ -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 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 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 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 impl_; }; diff --git a/source/gui/msgbox.cpp b/source/gui/msgbox.cpp index d6620c7a..1034585b 100644 --- a/source/gui/msgbox.cpp +++ b/source/gui/msgbox.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -526,8 +527,8 @@ namespace nana ss_content << ">>>"; - 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 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(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(impl->begin < 0 ? impl->begin * 10 : impl->begin)) < std::abs(static_cast(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(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(impl_->begin < 0 ? impl_->begin * 10 : impl_->begin)) < std::abs(static_cast(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(impl->begin < 0 ? impl->begin * 10 : impl->begin)) < std::abs(static_cast(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(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(impl_->begin < 0 ? impl_->begin * 10 : impl_->begin)) < std::abs(static_cast(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(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(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 inputs;