Compare commits
1 Commits
ee6375f553
...
5ef7f91764
| Author | SHA1 | Date | |
|---|---|---|---|
| 5ef7f91764 |
@@ -350,7 +350,8 @@ TimPanelItem* tim_panel(TimPanel* self, bool is_selected, i32 x, i32 y, i32 w, i
|
||||
void TimPanel_selectNext(TimPanel* self);
|
||||
void TimPanel_selectPrev(TimPanel* self);
|
||||
|
||||
///
|
||||
/// Scrollable scope.
|
||||
/// WARNING: draw it before anything else or it will overlap
|
||||
void tim_scroll_view(TimScrollView* self, i32 x, i32 y, i32 w, i32 h, TimStyle style);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
29
src/panel.c
29
src/panel.c
@@ -10,7 +10,7 @@ void TimPanel_selectPrev(TimPanel* l){
|
||||
l->cur--;
|
||||
}
|
||||
|
||||
TimPanelItem* tim_panel(TimPanel* self, bool is_panel_selected, i32 x, i32 y, i32 w, i32 h){
|
||||
TimPanelItem* tim_panel(TimPanel* self, bool is_panel_selected, i32 x1, i32 y1, i32 w1, i32 h1){
|
||||
// select item with keyboard
|
||||
if(tim_is_key_press(self->is_horizontal ? TimKey_Left : TimKey_Up))
|
||||
{
|
||||
@@ -25,38 +25,44 @@ TimPanelItem* tim_panel(TimPanel* self, bool is_panel_selected, i32 x, i32 y, i3
|
||||
if(self->cur < self->len)
|
||||
tim->focus = self->items[self->cur].focus_target;
|
||||
|
||||
tim_scope(x, y, w, h)
|
||||
{
|
||||
TimRect content_scope = tim->scopes[tim->scope];
|
||||
// TODO: draw current item and as much previous items as possible in scope
|
||||
TimRect item_place = { 0 };
|
||||
TimRect absolute = tim_scope_rect_to_absolute(x1, y1, w1, h1);
|
||||
TimRect scope = tim->scopes[tim->scope];
|
||||
TimRect item_place = {
|
||||
.x = absolute.x - scope.x,
|
||||
.y = absolute.y - scope.y,
|
||||
.w = 0,
|
||||
.h = 0
|
||||
};
|
||||
for(i32 i = 0; i < self->len; i++){
|
||||
TimPanelItem* item = &self->items[i];
|
||||
|
||||
// calculate item width
|
||||
item_place.w = item->w;
|
||||
if(item_place.w == A){
|
||||
if(self->is_horizontal){
|
||||
item_place.w = content_scope.w / self->len ;
|
||||
item_place.w = absolute.w / self->len ;
|
||||
// add remaining width to the last item
|
||||
if(i == self->len - 1)
|
||||
item_place.w += content_scope.w % self->len;
|
||||
item_place.w += absolute.w % self->len;
|
||||
else item_place.w -= self->spacing;
|
||||
}
|
||||
else {
|
||||
item_place.w = content_scope.w;
|
||||
item_place.w = absolute.w;
|
||||
}
|
||||
}
|
||||
|
||||
// calculate item height
|
||||
item_place.h = item->h;
|
||||
if(item_place.h == A){
|
||||
if(self->is_horizontal){
|
||||
item_place.h = content_scope.h;
|
||||
item_place.h = absolute.h;
|
||||
}
|
||||
else {
|
||||
item_place.h = content_scope.h / self->len - self->spacing;
|
||||
item_place.h = absolute.h / self->len - self->spacing;
|
||||
// add remaining height to the last item
|
||||
if(i == self->len - 1)
|
||||
item_place.h += content_scope.h % self->len;
|
||||
item_place.h += absolute.h % self->len;
|
||||
else item_place.h -= self->spacing;
|
||||
}
|
||||
}
|
||||
@@ -80,7 +86,6 @@ TimPanelItem* tim_panel(TimPanel* self, bool is_panel_selected, i32 x, i32 y, i3
|
||||
item_place.y += item_place.h + self->spacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return &self->items[self->cur];
|
||||
}
|
||||
|
||||
13
src/scope.c
13
src/scope.c
@@ -17,17 +17,18 @@ TimRect tim_scope_rect_to_absolute(i32 x, i32 y, i32 w, i32 h) {
|
||||
if (x == A) { //
|
||||
x = p.x + (p.w - w) / 2; // center x on parent
|
||||
} else { //
|
||||
if (x < 0) { //
|
||||
x += p.w - w + 1; // anchor x to right
|
||||
} //
|
||||
// if (x < 0) { //
|
||||
// x += p.w - w + 1; // anchor x to right
|
||||
// } //
|
||||
if(x >= 0)
|
||||
x += p.x; // anchor x to left
|
||||
} //
|
||||
if (y == A) { //
|
||||
y = p.y + (p.h - h) / 2; // center y on parent
|
||||
} else { //
|
||||
if (y < 0) { //
|
||||
y += p.h - h + 1; // anchor y to bottom
|
||||
} //
|
||||
// if (y < 0) { //
|
||||
// y += p.h - h + 1; // anchor y to bottom
|
||||
// } //
|
||||
y += p.y; // anchor y to top
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ void tim_scroll_view(TimScrollView* self, i32 x, i32 y, i32 w, i32 h, TimStyle s
|
||||
tim->scopes[tim->scope] = content_scope;
|
||||
|
||||
// draw content
|
||||
TimRect content_place = { .x = 0, .y = -self->offset - 1, .w = content_scope.w, .h = content_scope.h };
|
||||
TimRect content_place = { .x = 0, .y = -self->offset, .w = content_scope.w, .h = content_scope.h };
|
||||
self->draw(self->data, content_place);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user