[DEV] correct some error in the display of the Button Image

This commit is contained in:
Edouard DUPIN 2013-03-11 23:29:40 +01:00
parent d84e4b8d53
commit 09103e3073
7 changed files with 132 additions and 79 deletions

View File

@ -235,7 +235,7 @@ void ewol::Image::PrintPart(ivec2 size,
} }
void ewol::Image::SetSource(etk::UString newFile) void ewol::Image::SetSource(etk::UString newFile, int32_t size)
{ {
Clear(); Clear();
// remove old one // remove old one
@ -243,11 +243,11 @@ void ewol::Image::SetSource(etk::UString newFile)
ewol::resource::Release(m_resource); ewol::resource::Release(m_resource);
m_resource = NULL; m_resource = NULL;
} }
ivec2 size(32,32); ivec2 tmpSize(size,size);
// note that no image can be loaded... // note that no image can be loaded...
if (newFile != "") { if (newFile != "") {
// link to new One // link to new One
if (false == ewol::resource::Keep(newFile, m_resource, size)) { if (false == ewol::resource::Keep(newFile, m_resource, tmpSize)) {
EWOL_ERROR("Can not get Image resource"); EWOL_ERROR("Can not get Image resource");
} }
} }

View File

@ -122,8 +122,9 @@ namespace ewol
/** /**
* @brief Change the image Source ==> can not be done to display 2 images at the same time ... * @brief Change the image Source ==> can not be done to display 2 images at the same time ...
* @param[in] newFile New file of the Image * @param[in] newFile New file of the Image
* @param[in] size for the image when Verctorial image loading is requested
*/ */
void SetSource(etk::UString newFile); void SetSource(etk::UString newFile, int32_t size=32);
/** /**
* @brief Sometimes the user declare an image but not allocate the ressources all the time, this is to know it .. * @brief Sometimes the user declare an image but not allocate the ressources all the time, this is to know it ..
* @return the validity od the resources. * @return the validity od the resources.

View File

@ -65,18 +65,20 @@ void widget::Button::SetShaperName(etk::UString shaperName)
m_shaper.SetSource(shaperName); m_shaper.SetSource(shaperName);
} }
void widget::Button::SetImage(etk::UString imageName, draw::Color color) void widget::Button::SetImage(etk::UString imageName, draw::Color color, int32_t size)
{ {
m_imageColor = color; m_imageColor = color;
m_displayImage.SetSource(imageName); m_imageDisplaySize = size;
m_displayImage.SetSource(imageName, size);
MarkToRedraw(); MarkToRedraw();
ewol::RequestUpdateSize(); ewol::RequestUpdateSize();
} }
void widget::Button::SetImageToggle(etk::UString imageName, draw::Color color) void widget::Button::SetImageToggle(etk::UString imageName, draw::Color color, int32_t size)
{ {
m_imageColorToggle = color; m_imageColorToggle = color;
m_displayImageToggle.SetSource(imageName); m_imageDisplaySize = size;
m_displayImageToggle.SetSource(imageName, size);
MarkToRedraw(); MarkToRedraw();
ewol::RequestUpdateSize(); ewol::RequestUpdateSize();
} }
@ -86,7 +88,19 @@ bool widget::Button::CalculateMinSize(void)
{ {
vec2 padding = m_shaper.GetPadding(); vec2 padding = m_shaper.GetPadding();
m_displayText.Clear(); m_displayText.Clear();
vec3 minSize = m_displayText.CalculateSizeDecorated(m_label); if( m_label.Size()==0
&& m_labelToggle.Size()==0
&& ( true == m_displayImage.HasSources()
|| true == m_displayImageToggle.HasSources()) ) {
// special case of only one image display ==> certer it ...
m_minSize.setX(padding.x()*2 + m_imageDisplaySize);
m_minSize.setY(padding.y()*2 + m_imageDisplaySize);
} else {
vec3 minSize(0,0,0);
//faster if no text set ...
if (m_label.Size()!=0) {
minSize = m_displayText.CalculateSizeDecorated(m_label);
}
if( true == m_toggleMode if( true == m_toggleMode
&& m_labelToggle.Size()!=0) { && m_labelToggle.Size()!=0) {
m_displayText.Clear(); m_displayText.Clear();
@ -102,6 +116,8 @@ bool widget::Button::CalculateMinSize(void)
|| true == m_displayImageToggle.HasSources()) { || true == m_displayImageToggle.HasSources()) {
m_minSize.setX(m_minSize.x()+ padding.x()/2 + m_imageDisplaySize); m_minSize.setX(m_minSize.x()+ padding.x()/2 + m_imageDisplaySize);
} }
}
CheckMinSize();
MarkToRedraw(); MarkToRedraw();
return true; return true;
} }
@ -171,26 +187,20 @@ void widget::Button::OnDraw(ewol::DrawProperty& displayProp)
void widget::Button::OnRegenerateDisplay(void) void widget::Button::OnRegenerateDisplay(void)
{ {
if (true == NeedRedraw()) { if (true == NeedRedraw()) {
// clear the previous display :
vec2 padding = m_shaper.GetPadding();
// to know the size of one Line :
vec3 minSize = m_displayText.CalculateSize('A');
vec3 curentTextSize(0,0,0);
if( false == m_toggleMode
|| false == m_value
|| m_labelToggle.Size()==0) {
curentTextSize = m_displayText.CalculateSizeDecorated(m_label);
} else {
curentTextSize = m_displayText.CalculateSizeDecorated(m_labelToggle);
}
m_displayImage.Clear(); m_displayImage.Clear();
m_displayImageToggle.Clear(); m_displayImageToggle.Clear();
m_shaper.Clear(); m_shaper.Clear();
m_displayText.Clear(); m_displayText.Clear();
// know the current padding
vec2 padding = m_shaper.GetPadding();
// to know the size of one Line :
vec3 minSize = m_displayText.CalculateSize('A');
ivec2 localSize = m_minSize; ivec2 localSize = m_minSize;
vec3 sizeText(0,0,0);
vec3 tmpOrigin((m_size.x() - m_minSize.x()) / 2.0, vec3 tmpOrigin((m_size.x() - m_minSize.x()) / 2.0,
(m_size.y() - m_minSize.y()) / 2.0, (m_size.y() - m_minSize.y()) / 2.0,
0); 0);
@ -211,6 +221,35 @@ void widget::Button::OnRegenerateDisplay(void)
tmpTextOrigin += vec3(padding.x(), padding.y(), 0); tmpTextOrigin += vec3(padding.x(), padding.y(), 0);
localSize -= ivec2(2*padding.x(), 2*padding.y()); localSize -= ivec2(2*padding.x(), 2*padding.y());
if( m_label.Size()==0
&& m_labelToggle.Size()==0
&& ( true == m_displayImage.HasSources()
|| true == m_displayImageToggle.HasSources()) ) {
vec3 imagePos(tmpOrigin.x()-padding.x()/4,
tmpOrigin.y()-padding.x()/4+(m_minSize.y()-m_imageDisplaySize-2*padding.y())/2.0,
0);
vec2 imageSize(m_imageDisplaySize,
m_imageDisplaySize);
if( false==m_toggleMode
|| false==m_value) {
m_displayImage.SetPos(imagePos);
m_displayImage.SetColor(m_imageColor);
m_displayImage.Print(imageSize);
} else {
m_displayImageToggle.SetPos(imagePos);
m_displayImageToggle.SetColor(m_imageColorToggle);
m_displayImageToggle.Print(imageSize);
}
} else {
vec3 curentTextSize(0,0,0);
if( false == m_toggleMode
|| false == m_value
|| m_labelToggle.Size()==0) {
curentTextSize = m_displayText.CalculateSizeDecorated(m_label);
} else {
curentTextSize = m_displayText.CalculateSizeDecorated(m_labelToggle);
}
tmpTextOrigin.setY(tmpTextOrigin.y()+ (m_minSize.y()-2*padding.y()) - minSize.y()); tmpTextOrigin.setY(tmpTextOrigin.y()+ (m_minSize.y()-2*padding.y()) - minSize.y());
vec2 textPos(tmpTextOrigin.x(), tmpTextOrigin.y()); vec2 textPos(tmpTextOrigin.x(), tmpTextOrigin.y());
@ -259,22 +298,20 @@ void widget::Button::OnRegenerateDisplay(void)
m_displayText.PrintDecorated(m_labelToggle); m_displayText.PrintDecorated(m_labelToggle);
} }
//m_displayText.Translate(tmpOrigin); //m_displayText.Translate(tmpOrigin);
sizeText = m_displayText.CalculateSize(m_label);
if (true==m_userFill.y()) { if (true==m_userFill.y()) {
tmpOrigin.setY(padding.y()); tmpOrigin.setY(padding.y());
} }
}
// selection area : // selection area :
m_selectableAreaPos = vec2(tmpOrigin.x()-padding.x(), tmpOrigin.y()-padding.y()); m_selectableAreaPos = vec2(tmpOrigin.x()-padding.x(), tmpOrigin.y()-padding.y());
m_selectableAreaSize = localSize + vec2(2,2)*padding; m_selectableAreaSize = localSize + vec2(2,2)*padding;
m_shaper.SetOrigin(m_selectableAreaPos ); m_shaper.SetOrigin(m_selectableAreaPos );
m_shaper.SetSize(m_selectableAreaSize); m_shaper.SetSize(m_selectableAreaSize);
m_shaper.SetInsidePos(vec2(tmpTextOrigin.x(), tmpTextOrigin.y()) ); m_shaper.SetInsidePos(vec2(tmpTextOrigin.x(), tmpTextOrigin.y()) );
vec3 tmpp = m_displayText.CalculateSize(m_label); vec2 tmpp2(sizeText.x(), sizeText.y());
vec2 tmpp2(tmpp.x(), tmpp.y());
m_shaper.SetInsideSize(tmpp2); m_shaper.SetInsideSize(tmpp2);
} }
} }

View File

@ -84,13 +84,13 @@ namespace widget {
* @param[in] imageName Filename of the image. * @param[in] imageName Filename of the image.
* @param[in] color The required color for the image. * @param[in] color The required color for the image.
*/ */
void SetImage(etk::UString imageName, draw::Color color=draw::color::white); void SetImage(etk::UString imageName, draw::Color color=draw::color::white, int32_t size=32);
/** /**
* @brief Set the image when button is pressed. * @brief Set the image when button is pressed.
* @param[in] imageName Filename of the image. * @param[in] imageName Filename of the image.
* @param[in] color The required color for the image. * @param[in] color The required color for the image.
*/ */
void SetImageToggle(etk::UString imageName, draw::Color color=draw::color::white); void SetImageToggle(etk::UString imageName, draw::Color color=draw::color::white, int32_t size=32);
/** /**
* @brief Set the currentValue of the Button (pressed or not) * @brief Set the currentValue of the Button (pressed or not)
* @note Work only in toggle mode * @note Work only in toggle mode

View File

@ -227,6 +227,16 @@ void ewol::Widget::SetMinSize(float x, float y)
m_userMinSize.setValue(x, y); m_userMinSize.setValue(x, y);
} }
void ewol::Widget::CheckMinSize(void)
{
if (m_userMinSize.x() > 0) {
m_minSize.setX(etk_max(m_minSize.x(), m_userMinSize.x()));
}
if (m_userMinSize.y() > 0) {
m_minSize.setY(etk_max(m_minSize.y(), m_userMinSize.y()));
}
}
vec2 ewol::Widget::GetMinSize(void) vec2 ewol::Widget::GetMinSize(void)
{ {
if (false==IsHide()) { if (false==IsHide()) {

View File

@ -138,6 +138,11 @@ namespace ewol {
* @return the size requested * @return the size requested
*/ */
vec2 GetMinSize(void); vec2 GetMinSize(void);
/**
* @brief Check if the current min size is compatible wit hte user minimum size
* If it is not the user minimum size will overWrite the minimum size set.
*/
void CheckMinSize(void);
/** /**
* @brief User set the maximum size he want to set the display * @brief User set the maximum size he want to set the display
* @param[in] size The new maximum size requested (vec2(-1,-1) to unset) * @param[in] size The new maximum size requested (vec2(-1,-1) to unset)