Skip to content

Commit

Permalink
Fix for applying updates of strong-override skin elements.
Browse files Browse the repository at this point in the history
- Always InvalidateLayout when a strong-override change. Having different layout properties is what they are for.

- Fixed regression caused by 07d5889. I had completely forgot the need
  to update skin states after any change that may resolve conditions differently, and also that updating skin states
  are different from updating widget states.
  • Loading branch information
fruxo committed May 29, 2014
1 parent 7394f38 commit 09d5196
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 16 deletions.
9 changes: 9 additions & 0 deletions src/tb/tb_editfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,13 @@ void TBEditField::SetVirtualWidth(int virtual_width)

void TBEditField::SetMultiline(bool multiline)
{
if (multiline == GetMultiline())
return;
UpdateScrollbarVisibility(multiline);
m_style_edit.SetMultiline(multiline);
SetWrapping(multiline);
InvalidateSkinStates();
TBWidget::Invalidate();
}

void TBEditField::SetStyling(bool styling)
Expand All @@ -120,7 +124,11 @@ void TBEditField::SetStyling(bool styling)

void TBEditField::SetReadOnly(bool readonly)
{
if (readonly == GetReadOnly())
return;
m_style_edit.SetReadOnly(readonly);
InvalidateSkinStates();
TBWidget::Invalidate();
}

void TBEditField::SetWrapping(bool wrapping)
Expand All @@ -141,6 +149,7 @@ void TBEditField::SetEditType(EDIT_TYPE type)
return;
m_edit_type = type;
m_style_edit.SetPassword(type == EDIT_TYPE_PASSWORD);
InvalidateSkinStates();
TBWidget::Invalidate();
}

Expand Down
1 change: 1 addition & 0 deletions src/tb/tb_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void TBLayout::SetAxis(AXIS axis)
return;
m_axis = axis;
InvalidateLayout(INVALIDATE_LAYOUT_RECURSIVE);
InvalidateSkinStates();
}

void TBLayout::SetSpacing(int spacing)
Expand Down
8 changes: 0 additions & 8 deletions src/tb/tb_style_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1987,29 +1987,21 @@ void TBStyleEdit::SetAlign(TB_TEXT_ALIGN align)

void TBStyleEdit::SetMultiline(bool multiline)
{
if (packed.multiline_on == multiline)
return;
packed.multiline_on = multiline;
}

void TBStyleEdit::SetStyling(bool styling)
{
if (packed.styling_on == styling)
return;
packed.styling_on = styling;
}

void TBStyleEdit::SetReadOnly(bool readonly)
{
if (packed.read_only == readonly)
return;
packed.read_only = readonly;
}

void TBStyleEdit::SetSelection(bool selection)
{
if (packed.selection_on == selection)
return;
packed.selection_on = selection;
}

Expand Down
1 change: 1 addition & 0 deletions src/tb/tb_toggle_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ void TBToggleContainer::SetValue(int value)
return;
m_value = value;
UpdateInternal();
InvalidateSkinStates();
}

void TBToggleContainer::UpdateInternal()
Expand Down
39 changes: 35 additions & 4 deletions src/tb/tb_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ void TBWidget::Invalidate()
void TBWidget::InvalidateStates()
{
update_widget_states = true;
InvalidateSkinStates();
}

void TBWidget::InvalidateSkinStates()
{
update_skin_states = true;
}

Expand Down Expand Up @@ -175,12 +180,19 @@ int TBWidget::GetValueByID(const TBID &id)
return 0;
}

void TBWidget::SetID(const TBID &id)
{
m_id = id;
InvalidateSkinStates();
}

void TBWidget::SetStateRaw(WIDGET_STATE state)
{
if (m_state == state)
return;
m_state = state;
Invalidate();
InvalidateSkinStates();
}

void TBWidget::SetState(WIDGET_STATE state, bool on)
Expand Down Expand Up @@ -307,6 +319,7 @@ void TBWidget::AddChildRelative(TBWidget *child, WIDGET_Z_REL z, TBWidget *refer
}
InvalidateLayout(INVALIDATE_LAYOUT_RECURSIVE);
Invalidate();
InvalidateSkinStates();
}

void TBWidget::RemoveChild(TBWidget *child, WIDGET_INVOKE_INFO info)
Expand All @@ -330,6 +343,7 @@ void TBWidget::RemoveChild(TBWidget *child, WIDGET_INVOKE_INFO info)

InvalidateLayout(INVALIDATE_LAYOUT_RECURSIVE);
Invalidate();
InvalidateSkinStates();
}

void TBWidget::DeleteAllChildren()
Expand Down Expand Up @@ -375,6 +389,7 @@ void TBWidget::SetSkinBg(const TBID &skin_bg, WIDGET_INVOKE_INFO info)
m_skin_bg_expected = skin_bg;

Invalidate();
InvalidateSkinStates();
InvalidateLayout(INVALIDATE_LAYOUT_RECURSIVE);

if (info == WIDGET_INVOKE_INFO_NORMAL)
Expand Down Expand Up @@ -529,9 +544,17 @@ bool TBWidget::SetFocus(WIDGET_FOCUS_REASON reason, WIDGET_INVOKE_INFO info)
return true;
}

if (focused_widget)
{
focused_widget->Invalidate();
focused_widget->InvalidateSkinStates();
}

TBWidgetSafePointer old_focus(focused_widget);
focused_widget = this;

Invalidate();
InvalidateSkinStates();

if (reason == WIDGET_FOCUS_REASON_NAVIGATION)
ScrollIntoViewRecursive();
Expand Down Expand Up @@ -1045,16 +1068,15 @@ void TBWidget::InvokeSkinUpdatesInternal(bool force_update)

// Check if the skin we get is different from what we expect. That might happen
// if the skin has some strong override dependant a condition that has changed.
// If that happens, call OnSkinChanged so the widget can react to that (possibly
// invalidating its layout).
// If that happens, call OnSkinChanged so the widget can react to that, and
// invalidate layout to apply new skin properties.
if (TBSkinElement *skin_elm = GetSkinBgElement())
{
if (skin_elm->id != m_skin_bg_expected)
{
OnSkinChanged();
m_skin_bg_expected = skin_elm->id;
// FIX: We should probably invalidate layout here automatically!
// InvalidateLayout(INVALIDATE_LAYOUT_RECURSIVE);
InvalidateLayout(INVALIDATE_LAYOUT_RECURSIVE);
}
}

Expand Down Expand Up @@ -1180,7 +1202,10 @@ bool TBWidget::InvokeEvent(TBWidgetEvent &ev)
return true; // We got removed so we actually handled this event.

if (ev.type == EVENT_TYPE_CHANGED)
{
InvalidateSkinStates();
m_connection.SyncFromWidget(this);
}

if (!this_widget.Get())
return true; // We got removed so we actually handled this event.
Expand Down Expand Up @@ -1519,13 +1544,17 @@ void TBWidget::SetHoveredWidget(TBWidget *widget, bool touch)

// We may apply hover state automatically so the widget might need to be updated.
if (TBWidget::hovered_widget)
{
TBWidget::hovered_widget->Invalidate();
TBWidget::hovered_widget->InvalidateSkinStates();
}

TBWidget::hovered_widget = widget;

if (TBWidget::hovered_widget)
{
TBWidget::hovered_widget->Invalidate();
TBWidget::hovered_widget->InvalidateSkinStates();

// Cursor based movement should set hover state automatically, but touch
// events should not (since touch doesn't really move unless pressed).
Expand Down Expand Up @@ -1556,6 +1585,7 @@ void TBWidget::SetCapturedWidget(TBWidget *widget)

// We apply pressed state automatically so the widget might need to be updated.
TBWidget::captured_widget->Invalidate();
TBWidget::captured_widget->InvalidateSkinStates();

TBWidget::captured_widget->StopLongClickTimer();
}
Expand All @@ -1571,6 +1601,7 @@ void TBWidget::SetCapturedWidget(TBWidget *widget)
if (TBWidget::captured_widget)
{
TBWidget::captured_widget->Invalidate();
TBWidget::captured_widget->InvalidateSkinStates();
TBWidget::captured_widget->OnCaptureChanged(true);
}
}
Expand Down
13 changes: 9 additions & 4 deletions src/tb/tb_widgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,18 @@ class TBWidget : public TBTypedObject, public TBLinkOf<TBWidget>
void Invalidate();

/** Call if something changes that might need other widgets to update their state.
F.ex if a action availability changes, some widget might have to become enabled/disabled,
or a skin might need to change due to different conditions.
F.ex if a action availability changes, some widget might have to become enabled/disabled.
Calling this will result in a later call to OnProcessStates().
This is done automatically for all invoked events of type:
EVENT_TYPE_CLICK, EVENT_TYPE_LONG_CLICK, EVENT_TYPE_CHANGED, EVENT_TYPE_KEYDOWN,
EVENT_TYPE_KEYUP. */
void InvalidateStates();

/** Call if something changes that might cause any skin to change due to different state
or conditions. This is called automatically from InvalidateStates(), when event
EVENT_TYPE_CHANGED is invoked, and in various other situations. */
void InvalidateSkinStates();

/** Delete the widget with the possibility for some extended life during animations.
If any widget listener responds true to OnWidgetDying it will be kept as a child and live
Expand All @@ -392,7 +397,7 @@ class TBWidget : public TBTypedObject, public TBLinkOf<TBWidget>
/** Set the id reference for this widgets. This id is 0 by default.
You can use this id to receive the widget from GetWidgetByID (or
preferable TBSafeGetByID to avoid dangerous casts). */
void SetID(const TBID &id) { m_id = id; }
void SetID(const TBID &id);
TBID &GetID() { return m_id; }

/** Set the group id reference for this widgets. This id is 0 by default.
Expand Down Expand Up @@ -883,7 +888,7 @@ class TBWidget : public TBTypedObject, public TBLinkOf<TBWidget>
Note: When invoking event EVENT_TYPE_CHANGED, this will update the value of other widgets connected
to the same group.
Note: Some event types will automatically invalidate states (See InvalidateStates())
Note: Some event types will automatically invalidate states (See InvalidateStates(), InvalidateSkinStates())
Note: Remember that this widgets may be deleted after this call! So if you really must do something after
this call and are not sure what the event will cause, use TBWidgetSafePointer to detect self deletion. */
Expand Down
3 changes: 3 additions & 0 deletions src/tb/tb_widgets_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ TBProgressSpinner::TBProgressSpinner()

void TBProgressSpinner::SetValue(int value)
{
if (value == m_value)
return;
InvalidateSkinStates();
assert(value >= 0); // If this happens, you probably have unballanced Begin/End calls.
m_value = value;
if (value > 0)
Expand Down

0 comments on commit 09d5196

Please sign in to comment.