From 33c9def0277b79e8f76c996cf558f789fd556f26 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Tue, 25 Jul 2017 06:30:09 +0800 Subject: [PATCH 1/4] fix issue where very long inputbox prompt string --- source/gui/msgbox.cpp | 50 ++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/source/gui/msgbox.cpp b/source/gui/msgbox.cpp index 1034585b..a0500dc2 100644 --- a/source/gui/msgbox.cpp +++ b/source/gui/msgbox.cpp @@ -520,7 +520,7 @@ namespace nana if (each_height[i] > 27) px = each_height[i]; - ss_content << ""; + ss_content << ""; height += px + 1; } @@ -777,10 +777,10 @@ namespace nana impl->spinbox.value(std::to_string(impl->value)); - impl->dock.events().resized.connect_unignorable([impl, label_px, value_px](const ::nana::arg_resized&) + impl->dock.events().resized.connect_unignorable([impl, label_px, value_px](const ::nana::arg_resized& arg) { - impl->label.size({ label_px, 24 }); - impl->spinbox.size({ value_px, 24 }); + impl->label.size({ label_px, arg.height }); + impl->spinbox.move({static_cast(label_px + 10), (static_cast(arg.height) - 25) / 2, value_px, 24 }); }); impl->spinbox.events().destroy.connect_unignorable([impl](const arg_destroy&) @@ -860,10 +860,10 @@ namespace nana impl->spinbox.value(std::to_string(impl->value)); - impl->dock.events().resized.connect_unignorable([impl, label_px, value_px](const ::nana::arg_resized&) + impl->dock.events().resized.connect_unignorable([impl, label_px, value_px](const ::nana::arg_resized& arg) { - impl->label.size(::nana::size{ label_px, 24 }); - impl->spinbox.size(::nana::size{ value_px, 24 }); + impl->label.size({ label_px, arg.height }); + impl->spinbox.move({ static_cast(label_px + 10), (static_cast(arg.height) - 25) / 2, value_px, 24 }); }); impl->spinbox.events().destroy.connect_unignorable([impl](const arg_destroy&) @@ -985,9 +985,9 @@ namespace nana { impl->label.size({ label_px, arg.height }); if (impl->textbox.empty()) - impl->combox.size({ value_px, 24 }); + impl->combox.move({static_cast(label_px + 10), (static_cast(arg.height) - 25) / 2, value_px, 24 }); else - impl->textbox.size({arg.width - label_px - 10, 24}); + impl->textbox.move({ static_cast(label_px + 10), (static_cast(arg.height) - 25) / 2, arg.width - label_px - 10, 24 }); }); auto & wdg = (value_px ? static_cast(impl->combox) : static_cast(impl->textbox)); @@ -1111,17 +1111,18 @@ namespace nana impl->dock.events().resized.connect_unignorable([impl, label_px](const ::nana::arg_resized& arg) { impl->label.size({ label_px, arg.height }); - auto sz = impl->wdg_month.size(); - sz.height = 24; - impl->wdg_month.size(sz); - sz = impl->wdg_day.size(); - sz.height = 24; - impl->wdg_day.size(sz); + rectangle rt{static_cast(label_px + 10), (static_cast(arg.height) - 25) / 2, 94, 24}; - sz = impl->wdg_year.size(); - sz.height = 24; - impl->wdg_year.size(sz); + impl->wdg_month.move(rt); + + rt.x += 104; + rt.width = 38; + impl->wdg_day.move(rt); + + rt.x += 48; + rt.width = 50; + impl->wdg_year.move(rt); }); auto destroy_fn = [impl](const arg_destroy& arg) @@ -1235,8 +1236,13 @@ namespace nana impl->dock.events().resized.connect_unignorable([impl, label_px](const ::nana::arg_resized& arg) { impl->label.size({ label_px, arg.height }); - impl->path_edit.size({arg.width - label_px - 75, arg.height}); - impl->browse.move({static_cast(arg.width - 60), 0, 60, arg.height}); + + rectangle rt{ static_cast(label_px)+10, (static_cast(arg.height) - 25), arg.width - label_px - 75, 24}; + impl->path_edit.move(rt); + + rt.x = static_cast(arg.width - 60); + rt.width = 60; + impl->browse.move(rt); }); impl->path_edit.events().destroy.connect_unignorable([impl](const arg_destroy&) @@ -1295,8 +1301,8 @@ namespace nana each_pixels.push_back(px.height); } - //if (fixed_px < 150) - // fixed_px = 150; + if (fixed_px < 100) + fixed_px = 100; inputbox_window input_wd(owner_, images_, valid_areas_, description_, title_, contents.size(), label_px + 10 + fixed_px, each_pixels); From d5c01b3dd1cd98cb945e22b18604f2eb915fdc67 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Tue, 25 Jul 2017 06:41:32 +0800 Subject: [PATCH 2/4] adjust inputbox element width for good looking --- source/gui/msgbox.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/gui/msgbox.cpp b/source/gui/msgbox.cpp index a0500dc2..f978bf1a 100644 --- a/source/gui/msgbox.cpp +++ b/source/gui/msgbox.cpp @@ -1288,6 +1288,8 @@ namespace nana std::vector each_pixels; unsigned label_px = 0, fixed_px = 0; paint::graphics graph({ 5, 5 }); + + bool has_0_fixed_px = false; for (auto p : contents) { auto px = label::measure(graph, p->label(), 150, true, align::right, align_v::center); @@ -1295,13 +1297,15 @@ namespace nana label_px = px.width; px.width = p->fixed_pixels(); + has_0_fixed_px |= (px.width == 0); if (px.width > fixed_px) fixed_px = px.width; each_pixels.push_back(px.height); } - if (fixed_px < 100) + //Adjust the fixed_px for good looking + if (has_0_fixed_px && (fixed_px < 100)) fixed_px = 100; inputbox_window input_wd(owner_, images_, valid_areas_, description_, title_, contents.size(), label_px + 10 + fixed_px, each_pixels); From 27e1d7aff5ee26da0109d868cac63367b5601562 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Tue, 25 Jul 2017 07:57:48 +0800 Subject: [PATCH 3/4] add textbox::content_origin --- include/nana/gui/widgets/skeletons/text_editor.hpp | 1 + include/nana/gui/widgets/textbox.hpp | 2 ++ source/gui/widgets/skeletons/text_editor.cpp | 9 ++++++++- source/gui/widgets/textbox.cpp | 9 +++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/nana/gui/widgets/skeletons/text_editor.hpp b/include/nana/gui/widgets/skeletons/text_editor.hpp index 9e91712c..a2ab3ea7 100644 --- a/include/nana/gui/widgets/skeletons/text_editor.hpp +++ b/include/nana/gui/widgets/skeletons/text_editor.hpp @@ -86,6 +86,7 @@ namespace nana{ namespace widgets ~text_editor(); size caret_size() const; + const point& content_origin() const; void set_highlight(const ::std::string& name, const ::nana::color&, const ::nana::color&); void erase_highlight(const ::std::string& name); diff --git a/include/nana/gui/widgets/textbox.hpp b/include/nana/gui/widgets/textbox.hpp index ad4a1b2f..d0ac2f67 100644 --- a/include/nana/gui/widgets/textbox.hpp +++ b/include/nana/gui/widgets/textbox.hpp @@ -140,6 +140,8 @@ namespace nana colored_area_access_interface* colored_area_access(); + point content_origin() const; + /// Enables/disables the textbox to indent a line. Idents a new line when it is created by pressing enter. /// @param generator generates text for identing a line. If it is empty, textbox indents the line according to last line. textbox& indention(bool, std::function generator = {}); diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index e48498d0..2d2e17e2 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -497,6 +497,7 @@ namespace nana{ namespace widgets undoable undo; //undo command renderers customized_renderers; std::vector text_position; //positions of text since last rendering. + int text_position_origin{ -1 }; //origin when last text_exposed skeletons::textbase textbase; @@ -1083,6 +1084,11 @@ namespace nana{ namespace widgets return { 1, line_height() }; } + const point& text_editor::content_origin() const + { + return impl_->cview->origin(); + } + void text_editor::set_highlight(const std::string& name, const ::nana::color& fgcolor, const ::nana::color& bgcolor) { if (fgcolor.invisible() && bgcolor.invisible()) @@ -1982,8 +1988,9 @@ namespace nana{ namespace widgets if (text_pos.empty()) text_pos.emplace_back(upoint{}); - if (text_pos != impl_->text_position) + if ((impl_->text_position_origin != impl_->cview->origin().y) || (text_pos != impl_->text_position)) { + impl_->text_position_origin = impl_->cview->origin().y; impl_->text_position.swap(text_pos); if (event_handler_) event_handler_->text_exposed(impl_->text_position); diff --git a/source/gui/widgets/textbox.cpp b/source/gui/widgets/textbox.cpp index 3366d84b..e29b0d88 100644 --- a/source/gui/widgets/textbox.cpp +++ b/source/gui/widgets/textbox.cpp @@ -269,6 +269,15 @@ namespace drawerbase { return nullptr; } + point textbox::content_origin() const + { + auto editor = get_drawer_trigger().editor(); + if (editor) + return editor->content_origin(); + + return{}; + } + /// Enables/disables the textbox to indent a line. Idents a new line when it is created by pressing enter. /// @param generator generates text for identing a line. If it is empty, textbox indents the line according to last line. textbox& textbox::indention(bool enb, std::function generator) From 6ae4b963ee2b30e736e2f9bb6b23d829f4bddffd Mon Sep 17 00:00:00 2001 From: Jinhao Date: Wed, 26 Jul 2017 02:40:52 +0800 Subject: [PATCH 4/4] code refined --- source/gui/widgets/skeletons/text_editor.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index 2d2e17e2..452cf5fe 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -3361,32 +3361,37 @@ namespace nana{ namespace widgets line_px_( editor.line_height() ) {} - color selection_text_color(bool has_focused) const + color selection_color(bool fgcolor, bool focused) const { - return (has_focused ? editor_.scheme_->selection_text : editor_.scheme_->foreground).get_color(); + if (fgcolor) + return (focused ? editor_.scheme_->selection_text : editor_.scheme_->foreground).get_color(); + + return (focused ? editor_.scheme_->selection : editor_.scheme_->selection_unfocused).get_color(); } void write_selection(const point& text_pos, unsigned text_px, const wchar_t* text, std::size_t len, bool has_focused) { - graph_.palette(true, selection_text_color(has_focused)); + graph_.palette(true, selection_color(true, has_focused)); graph_.rectangle(::nana::rectangle{ text_pos, { text_px, line_px_ } }, true, - has_focused ? editor_.scheme_->selection.get_color() : editor_.scheme_->selection_unfocused.get_color()); + selection_color(false, has_focused)); + graph_.string(text_pos, text, len); } void rtl_string(point strpos, const wchar_t* str, std::size_t len, std::size_t str_px, unsigned glyph_front, unsigned glyph_selected, bool has_focused) { - editor_._m_draw_parse_string(parser_, true, strpos, selection_text_color(has_focused), str, len); + editor_._m_draw_parse_string(parser_, true, strpos, selection_color(true, has_focused), str, len); //Draw selected part paint::graphics graph({ glyph_selected, line_px_ }); graph.typeface(this->graph_.typeface()); - graph.rectangle(true, (has_focused ? editor_.scheme_->selection.get_color() : editor_.scheme_->selection_unfocused.get_color())); + graph.rectangle(true, selection_color(false, has_focused)); int sel_xpos = static_cast(str_px - (glyph_front + glyph_selected)); - graph.palette(true, selection_text_color(has_focused)); + graph.palette(true, selection_color(true, has_focused)); + graph.string({ -sel_xpos, 0 }, str, len); graph_.bitblt(nana::rectangle(strpos.x + sel_xpos, strpos.y, glyph_selected, line_px_), graph); };