[qwaq] Hook up the scroll bar

It's mostly working now, just some issues with clicking on the bar and
the thumb tab doesn't work.
This commit is contained in:
Bill Currie 2020-03-30 22:50:29 +09:00
parent b8005a99c9
commit 1a34f3663a
4 changed files with 47 additions and 23 deletions

View file

@ -73,6 +73,7 @@
file_proxy = [ProxyView withView: current_file];
[[current_file gotoLine:state.line - 1] highlightLine];
[[current_file onEvent] addListener: self :@selector(proxy_event::)];
[current_file setVerticalScrollBar:scrollbar];
//FIXME id<View>?
[source_window insertSelected: (View *) file_proxy];
[source_window setTitle: [current_file filename]];
@ -95,9 +96,11 @@
printf ("%s:%d\n", state.file, state.line);
if (current_file != file) {
[current_file setVerticalScrollBar:nil];
[[current_file onEvent] removeListener:self :@selector(proxy_event::)];
[file_proxy setView:file];
[[file onEvent] addListener:self :@selector(proxy_event::)];
[file setVerticalScrollBar:scrollbar];
[source_window setTitle: [file filename]];
current_file = file;
}

View file

@ -25,19 +25,15 @@
return [[[self alloc] initWithRect:rect file:filename] autorelease];
}
-(void)onScroll:(id)sender
{
}
-setVerticalScrollBar:(ScrollBar *)scrollbar
{
[scrollbar retain];
[[vScrollBar onScroll] removeListener:self :@selector(onScroll)];
[[vScrollBar onScroll] removeListener:self :@selector(onScroll:)];
[vScrollBar release];
vScrollBar = scrollbar;
[vScrollBar setRange:line_count];
[[vScrollBar onScroll] addListener:self :@selector(onScroll)];
[[vScrollBar onScroll] addListener:self :@selector(onScroll:)];
return self;
}
@ -164,6 +160,22 @@ static int handleEvent (Editor *self, qwaq_event_t *event)
return self;
}
-scrollTo:(unsigned)target
{
if (target > scroll.y) {
base_index = [buffer nextLine:base_index :target - scroll.y];
} else if (target < scroll.y) {
base_index = [buffer prevLine:base_index :scroll.y - target];
}
scroll.y = target;
return self;
}
-(void)onScroll:(id)sender
{
[self scrollTo:[sender index]];
}
-recenter:(int) force
{
if (!force) {
@ -177,12 +189,7 @@ static int handleEvent (Editor *self, qwaq_event_t *event)
} else {
target = cursor.y - ylen / 2;
}
if (target > scroll.y) {
base_index = [buffer nextLine:base_index :target - scroll.y];
} else if (target < scroll.y) {
base_index = [buffer prevLine:base_index :scroll.y - target];
}
scroll.y = target;
[self scrollTo:target];
return self;
}

View file

@ -32,6 +32,7 @@
-setPageStep:(unsigned)pageStep;
-setSingleStep:(unsigned)singleStep;
-setIndex:(unsigned)index;
-(unsigned)index;
@end
#endif//__qwaq_ui_scrollbar_h

View file

@ -10,6 +10,7 @@
if (!(self = [super initWithRect:rect])) {
return nil;
}
options = ofRelativeEvents;
buffer = [[DrawBuffer buffer:size] retain];
objects = [[Group withContext:buffer owner:self] retain];
onScroll = [[ListenerGroup listener] retain];
@ -27,13 +28,13 @@
[icons[0] addch:acs_char (ACS_UARROW)];
[icons[1] addch:acs_char (ACS_DARROW)];
thumbPos = {0, 1};
thumbSel = @selector(verticalSlide);
thumbSel = @selector(verticalSlide:);
growMode &= ~gfGrowLoY;
} else {
[icons[0] addch:acs_char (ACS_LARROW)];
[icons[1] addch:acs_char (ACS_RARROW)];
thumbPos = {1, 0};
thumbSel = @selector(horizontalSlide);
thumbSel = @selector(horizontalSlide:);
growMode &= ~gfGrowLoX;
}
bgchar = acs_char (ACS_CKBOARD);
@ -44,8 +45,8 @@
thumbTab = [Button withPos:thumbPos
releasedIcon:icons[2] pressedIcon:icons[2]];
[[backButton onPress] addListener:self :@selector(scrollBack:)];
[[forwardButton onPress] addListener:self :@selector(scrollForward:)];
[[backButton onClick] addListener:self :@selector(scrollBack:)];
[[forwardButton onClick] addListener:self :@selector(scrollForward:)];
[[thumbTab onPress] addListener:self :thumbSel];
singleStep = 1;
@ -86,16 +87,14 @@
-draw
{
syncprintf("scrollbar start");
if (vertical) {
[self mvvline:pos, bgchar, ylen];
} else {
[self mvhline:pos, bgchar, xlen];
}
[super draw];
if (vertical) {
[buffer mvvline:{0,0}, bgchar, ylen];
} else {
[buffer mvhline:{0,0}, bgchar, xlen];
}
[objects draw];
[textContext blitFromBuffer:buffer to:pos from:[buffer rect]];
syncprintf("scrollbar end");
return self;
}
@ -112,6 +111,7 @@ position_tab (ScrollBar *self)
}
}
[self.thumbTab move:{p.x - o.x, p.y - o.y}];
[self redraw];
}
-resize:(Extent)delta
@ -177,6 +177,14 @@ page (ScrollBar *self, Point pos)
[self page:singleStep dir:1];
}
-(void)horizontalSlide:(id)sender
{
}
-(void)verticalSlide:(id)sender
{
}
-handleEvent:(qwaq_event_t *)event
{
[super handleEvent: event];
@ -224,4 +232,9 @@ page (ScrollBar *self, Point pos)
return self;
}
-(unsigned)index
{
return index;
}
@end