зеркало из https://github.com/electron/electron.git
Add View.addChildView API
This commit is contained in:
Родитель
322bde526c
Коммит
2c8dc9e0bd
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "atom/browser/api/atom_api_view.h"
|
||||
#include "atom/common/api/constructor.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
|
||||
|
@ -42,6 +43,11 @@ BoxLayout::BoxLayout(views::BoxLayout::Orientation orientation)
|
|||
|
||||
BoxLayout::~BoxLayout() {}
|
||||
|
||||
void BoxLayout::SetFlexForView(mate::Handle<View> view, int flex) {
|
||||
auto* box_layout = static_cast<views::BoxLayout*>(layout_manager());
|
||||
box_layout->SetFlexForView(view->view(), flex);
|
||||
}
|
||||
|
||||
// static
|
||||
mate::WrappableBase* BoxLayout::New(mate::Arguments* args,
|
||||
views::BoxLayout::Orientation orientation) {
|
||||
|
@ -52,7 +58,11 @@ mate::WrappableBase* BoxLayout::New(mate::Arguments* args,
|
|||
|
||||
// static
|
||||
void BoxLayout::BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype) {}
|
||||
v8::Local<v8::FunctionTemplate> prototype) {
|
||||
prototype->SetClassName(mate::StringToV8(isolate, "BoxLayout"));
|
||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||
.SetMethod("setFlexForView", &BoxLayout::SetFlexForView);
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
|
||||
|
|
|
@ -6,12 +6,15 @@
|
|||
#define ATOM_BROWSER_API_ATOM_API_BOX_LAYOUT_H_
|
||||
|
||||
#include "atom/browser/api/atom_api_layout_manager.h"
|
||||
#include "native_mate/handle.h"
|
||||
#include "ui/views/layout/box_layout.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
||||
class View;
|
||||
|
||||
class BoxLayout : public LayoutManager {
|
||||
public:
|
||||
static mate::WrappableBase* New(mate::Arguments* args,
|
||||
|
@ -20,6 +23,8 @@ class BoxLayout : public LayoutManager {
|
|||
static void BuildPrototype(v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype);
|
||||
|
||||
void SetFlexForView(mate::Handle<View> view, int flex);
|
||||
|
||||
protected:
|
||||
explicit BoxLayout(views::BoxLayout::Orientation orientation);
|
||||
~BoxLayout() override;
|
||||
|
|
|
@ -30,6 +30,18 @@ void View::SetLayoutManager(mate::Handle<LayoutManager> layout_manager) {
|
|||
view()->SetLayoutManager(layout_manager->TakeOver().release());
|
||||
}
|
||||
|
||||
void View::AddChildView(mate::Handle<View> child) {
|
||||
AddChildViewAt(child, child_views_.size());
|
||||
}
|
||||
|
||||
void View::AddChildViewAt(mate::Handle<View> child, size_t index) {
|
||||
if (index > child_views_.size())
|
||||
return;
|
||||
child_views_.emplace(child_views_.begin() + index, // index
|
||||
isolate(), child->GetWrapper()); // v8::Global(args...)
|
||||
view()->AddChildViewAt(child->view(), index);
|
||||
}
|
||||
|
||||
// static
|
||||
mate::WrappableBase* View::New(mate::Arguments* args) {
|
||||
auto* view = new View();
|
||||
|
@ -42,7 +54,9 @@ void View::BuildPrototype(v8::Isolate* isolate,
|
|||
v8::Local<v8::FunctionTemplate> prototype) {
|
||||
prototype->SetClassName(mate::StringToV8(isolate, "View"));
|
||||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||
.SetMethod("setLayoutManager", &View::SetLayoutManager);
|
||||
.SetMethod("setLayoutManager", &View::SetLayoutManager)
|
||||
.SetMethod("addChildView", &View::AddChildView)
|
||||
.SetMethod("addChildViewAt", &View::AddChildViewAt);
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#define ATOM_BROWSER_API_ATOM_API_VIEW_H_
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/browser/api/atom_api_layout_manager.h"
|
||||
#include "native_mate/handle.h"
|
||||
|
@ -23,6 +24,8 @@ class View : public mate::TrackableObject<View> {
|
|||
v8::Local<v8::FunctionTemplate> prototype);
|
||||
|
||||
void SetLayoutManager(mate::Handle<LayoutManager> layout_manager);
|
||||
void AddChildView(mate::Handle<View> view);
|
||||
void AddChildViewAt(mate::Handle<View> view, size_t index);
|
||||
|
||||
views::View* view() const { return view_; }
|
||||
|
||||
|
@ -36,6 +39,7 @@ class View : public mate::TrackableObject<View> {
|
|||
|
||||
private:
|
||||
v8::Global<v8::Object> layout_manager_;
|
||||
std::vector<v8::Global<v8::Object>> child_views_;
|
||||
|
||||
bool delete_view_ = true;
|
||||
views::View* view_ = nullptr;
|
||||
|
|
|
@ -14,7 +14,7 @@ DelayedNativeViewHost::~DelayedNativeViewHost() {}
|
|||
void DelayedNativeViewHost::ViewHierarchyChanged(
|
||||
const ViewHierarchyChangedDetails& details) {
|
||||
NativeViewHost::ViewHierarchyChanged(details);
|
||||
if (details.is_add)
|
||||
if (details.is_add && GetWidget())
|
||||
Attach(native_view_);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче