Merge branch 'hotfix-1.5.3' into develop

This commit is contained in:
Jinhao 2017-07-26 02:41:50 +08:00
commit 446fb1fc47
5 changed files with 64 additions and 30 deletions

View File

@ -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);

View File

@ -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<std::string()> generator = {});

View File

@ -520,7 +520,7 @@ namespace nana
if (each_height[i] > 27)
px = each_height[i];
ss_content << "<weight=" << px << " margin=[3] input_" << i << ">";
ss_content << "<weight=" << (px + 3) << " margin=[3] input_" << i << ">";
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<int>(label_px + 10), (static_cast<int>(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<int>(label_px + 10), (static_cast<int>(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<int>(label_px + 10), (static_cast<int>(arg.height) - 25) / 2, value_px, 24 });
else
impl->textbox.size({arg.width - label_px - 10, 24});
impl->textbox.move({ static_cast<int>(label_px + 10), (static_cast<int>(arg.height) - 25) / 2, arg.width - label_px - 10, 24 });
});
auto & wdg = (value_px ? static_cast<widget&>(impl->combox) : static_cast<widget&>(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<int>(label_px + 10), (static_cast<int>(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<int>(arg.width - 60), 0, 60, arg.height});
rectangle rt{ static_cast<int>(label_px)+10, (static_cast<int>(arg.height) - 25), arg.width - label_px - 75, 24};
impl->path_edit.move(rt);
rt.x = static_cast<int>(arg.width - 60);
rt.width = 60;
impl->browse.move(rt);
});
impl->path_edit.events().destroy.connect_unignorable([impl](const arg_destroy&)
@ -1282,6 +1288,8 @@ namespace nana
std::vector<unsigned> 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);
@ -1289,14 +1297,16 @@ 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 < 150)
// fixed_px = 150;
//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);

View File

@ -497,6 +497,7 @@ namespace nana{ namespace widgets
undoable<command> undo; //undo command
renderers customized_renderers;
std::vector<upoint> text_position; //positions of text since last rendering.
int text_position_origin{ -1 }; //origin when last text_exposed
skeletons::textbase<wchar_t> 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);
@ -3354,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<int>(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);
};

View File

@ -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<std::string()> generator)