先看ui,ui的基础控件在
ui文件夹—views-control-views项目-control文件夹
先看button
我们思考一下 一个控件需要涉及到那些东西
(1) 控件在屏幕上的位置
(2) 控件的高 ,宽
(3) 控件的容器(父控件,子控件)
(4) 控件获取焦点
(5) 如何获得这个控件(控件的 id)
(6) 控件的样式(背景色,字体,border,前景色)
这些都已经定义在view类里面了,
这些方法应该是 怎么将控件显示在屏幕上
如果在往下分析就要看
public ui::LayerDelegate,
public ui::LayerOwner,
public ui::AcceleratorTarget,
public ui::EventTarget
这几个类了
看一下view 公开的方法,这些方法 都是我们在程序里面要调用的
virtual const Widget* GetWidget() const;
virtual Widget* GetWidget();
// Adds |view| as a child of this view, optionally at |index|.
void AddChildView(View* view);
void AddChildViewAt(View* view, int index);
// Moves |view| to the specified |index|. A negative value for |index| moves
// the view at the end.
void ReorderChildView(View* view, int index);
// Removes |view| from this view. The view's parent will change to NULL.
void RemoveChildView(View* view);
// Removes all the children from this view. If |delete_children| is true,
// the views are deleted, unless marked as not parent owned.
void RemoveAllChildViews(bool delete_children);
int child_count() const { return static_cast<int>(children_.size()); }
bool has_children() const { return !children_.empty(); }
// Returns the child view at |index|.
const View* child_at(int index) const {
DCHECK_GE(index, 0);
DCHECK_LT(index, child_count());
return children_[index];
}
View* child_at(int index) {
return const_cast<View*>(const_cast<const View*>(this)->child_at(index));
}
// Returns the parent view.
const View* parent() const { return parent_; }
View* parent() { return parent_; }
// Returns true if |view| is contained within this View's hierarchy, even as
// an indirect descendant. Will return true if child is also this view.
bool Contains(const View* view) const;
// Returns the index of |view|, or -1 if |view| is not a child of this view.
int GetIndexOf(const View* view) const;
// Size and disposition ------------------------------------------------------
// Methods for obtaining and modifying the position and size of the view.
// Position is in the coordinate system of the view's parent.
// Position is NOT flipped for RTL. See "RTL positioning" for RTL-sensitive
// position accessors.
// Transformations are not applied on the size/position. For example, if
// bounds is (0, 0, 100, 100) and it is scaled by 0.5 along the X axis, the
// width will still be 100 (although when painted, it will be 50x50, painted
// at location (0, 0)).
void SetBounds(int x, int y, int width, int height);
void SetBoundsRect(const gfx::Rect& bounds);
void SetSize(const gfx::Size& size);
void SetPosition(const gfx::Point& position);
void SetX(int x);
void SetY(int y);
// No transformation is applied on the size or the locations.
const gfx::Rect& bounds() const { return bounds_; }
int x() const { return bounds_.x(); }
int y() const { return bounds_.y(); }
int width() const { return bounds_.width(); }
int height() const { return bounds_.height(); }
const gfx::Size& size() const { return bounds_.size(); }
// Returns the bounds of the content area of the view, i.e. the rectangle
// enclosed by the view's border.
gfx::Rect GetContentsBounds() const;
// Returns the bounds of the view in its own coordinates (i.e. position is
// 0, 0).
gfx::Rect GetLocalBounds() const;
以下还有很多方法。。。。。
Button::Button(ButtonListener* listener)
: listener_(listener),
tag_(-1) {
set_accessibility_focusable(true);
}
button 添加响应方法