Skip to content
This repository was archived by the owner on Jun 17, 2024. It is now read-only.

Commit c4eb444

Browse files
committed
feat: add button for open new tab
1 parent 4e124a2 commit c4eb444

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/ui/stylesheets/views/_browser.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,20 @@
66
background-color: $browser-tabbar-bg;
77
padding: 8px 8px 0 8px;
88
}
9+
10+
.v-browser__btn-add-tab {
11+
width: 28px;
12+
font-size: 18px;
13+
line-height: 28px;
14+
border-radius: 14px;
15+
margin-left: 10px;
16+
text-align: center;
17+
margin-top: 4px;
18+
19+
&:hover {
20+
background-color: $browser-btn-add-tab-bg-hover;
21+
}
22+
&:active {
23+
background-color: $browser-btn-add-tab-bg-active;
24+
}
25+
}

src/ui/views/browser.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <LCUI.h>
2+
#include <LCDesign.h>
23
#include <LCUI/gui/widget.h>
34
#include "../components/frame-tab.h"
45
#include "browser.h"
@@ -17,12 +18,18 @@ typedef struct PageRec_ {
1718
typedef struct BrowserViewRec_ {
1819
int page_id_count;
1920
Page current_page;
21+
LCUI_Widget btn_add;
2022
LCUI_Widget tabbar;
2123
LinkedList pages;
2224
} BrowserViewRec, *BrowserView;
2325

2426
static LCUI_WidgetPrototype browser_proto;
2527

28+
static void BrowserView_OnBtnAddTabClick(LCUI_Widget w, LCUI_WidgetEvent e, void *arg)
29+
{
30+
BrowserView_Active(e->data, BrowserView_Load(e->data, NULL));
31+
}
32+
2633
static void BrowserView_OnInit(LCUI_Widget w)
2734
{
2835
BrowserView self;
@@ -31,10 +38,15 @@ static void BrowserView_OnInit(LCUI_Widget w)
3138
self->tabbar = LCUIWidget_New(NULL);
3239
self->page_id_count = 0;
3340
self->current_page = NULL;
41+
self->btn_add = LCUIWidget_New("icon");
3442
LinkedList_Init(&self->pages);
43+
Icon_SetName(self->btn_add, "plus");
3544
Widget_AddClass(w, "v-browser");
45+
Widget_AddClass(self->btn_add, "v-browser__btn-add-tab");
3646
Widget_AddClass(self->tabbar, "v-browser__tabbar");
47+
Widget_Append(self->tabbar, self->btn_add);
3748
Widget_Append(w, self->tabbar);
49+
Widget_BindEvent(self->btn_add, "click", BrowserView_OnBtnAddTabClick, w, NULL);
3850
BrowserView_Load(w, NULL);
3951
}
4052

@@ -107,6 +119,7 @@ int BrowserView_Load(LCUI_Widget w, const char *path)
107119
FrameTab_SetTextW(page->tab, page->title);
108120
FrameTab_SetLoading(page->tab, TRUE);
109121
Widget_Append(self->tabbar, page->tab);
122+
Widget_Append(self->tabbar, self->btn_add);
110123
Widget_BindEvent(page->tab, "mousedown", BrowserView_OnPageTabClick,
111124
page, NULL);
112125
Widget_BindEvent(page->tab, "TabClose", BrowserView_OnPageTabClose,

0 commit comments

Comments
 (0)