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_selectNext(TimPanel* self);
|
||||||
void TimPanel_selectPrev(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);
|
void tim_scroll_view(TimScrollView* self, i32 x, i32 y, i32 w, i32 h, TimStyle style);
|
||||||
|
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|||||||
105
src/panel.c
105
src/panel.c
@@ -10,7 +10,7 @@ void TimPanel_selectPrev(TimPanel* l){
|
|||||||
l->cur--;
|
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
|
// select item with keyboard
|
||||||
if(tim_is_key_press(self->is_horizontal ? TimKey_Left : TimKey_Up))
|
if(tim_is_key_press(self->is_horizontal ? TimKey_Left : TimKey_Up))
|
||||||
{
|
{
|
||||||
@@ -25,61 +25,66 @@ TimPanelItem* tim_panel(TimPanel* self, bool is_panel_selected, i32 x, i32 y, i3
|
|||||||
if(self->cur < self->len)
|
if(self->cur < self->len)
|
||||||
tim->focus = self->items[self->cur].focus_target;
|
tim->focus = self->items[self->cur].focus_target;
|
||||||
|
|
||||||
tim_scope(x, y, w, h)
|
// TODO: draw current item and as much previous items as possible in scope
|
||||||
{
|
TimRect absolute = tim_scope_rect_to_absolute(x1, y1, w1, h1);
|
||||||
TimRect content_scope = tim->scopes[tim->scope];
|
TimRect scope = tim->scopes[tim->scope];
|
||||||
// TODO: draw current item and as much previous items as possible in scope
|
TimRect item_place = {
|
||||||
TimRect item_place = { 0 };
|
.x = absolute.x - scope.x,
|
||||||
for(i32 i = 0; i < self->len; i++){
|
.y = absolute.y - scope.y,
|
||||||
TimPanelItem* item = &self->items[i];
|
.w = 0,
|
||||||
|
.h = 0
|
||||||
|
};
|
||||||
|
for(i32 i = 0; i < self->len; i++){
|
||||||
|
TimPanelItem* item = &self->items[i];
|
||||||
|
|
||||||
item_place.w = item->w;
|
// calculate item width
|
||||||
if(item_place.w == A){
|
item_place.w = item->w;
|
||||||
if(self->is_horizontal){
|
if(item_place.w == A){
|
||||||
item_place.w = content_scope.w / self->len ;
|
|
||||||
// add remaining width to the last item
|
|
||||||
if(i == self->len - 1)
|
|
||||||
item_place.w += content_scope.w % self->len;
|
|
||||||
else item_place.w -= self->spacing;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
item_place.w = content_scope.w;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
item_place.h = item->h;
|
|
||||||
if(item_place.h == A){
|
|
||||||
if(self->is_horizontal){
|
|
||||||
item_place.h = content_scope.h;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
item_place.h = content_scope.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;
|
|
||||||
else item_place.h -= self->spacing;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// select item with mouse click
|
|
||||||
if(tim_is_mouse_click_over(tim_scope_rect_to_absolute(item_place.x, item_place.y, item_place.w, item_place.h))){
|
|
||||||
self->cur = i;
|
|
||||||
tim->focus = item->focus_target;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_item_selected = false;
|
|
||||||
if(is_panel_selected)
|
|
||||||
is_item_selected = i == self->cur;
|
|
||||||
item->draw(item->data, item_place, is_item_selected);
|
|
||||||
|
|
||||||
// adjust place for next item
|
|
||||||
if(self->is_horizontal){
|
if(self->is_horizontal){
|
||||||
item_place.x += item_place.w + self->spacing;
|
item_place.w = absolute.w / self->len ;
|
||||||
|
// add remaining width to the last item
|
||||||
|
if(i == self->len - 1)
|
||||||
|
item_place.w += absolute.w % self->len;
|
||||||
|
else item_place.w -= self->spacing;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
item_place.y += item_place.h + self->spacing;
|
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 = absolute.h;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
item_place.h = absolute.h / self->len - self->spacing;
|
||||||
|
// add remaining height to the last item
|
||||||
|
if(i == self->len - 1)
|
||||||
|
item_place.h += absolute.h % self->len;
|
||||||
|
else item_place.h -= self->spacing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// select item with mouse click
|
||||||
|
if(tim_is_mouse_click_over(tim_scope_rect_to_absolute(item_place.x, item_place.y, item_place.w, item_place.h))){
|
||||||
|
self->cur = i;
|
||||||
|
tim->focus = item->focus_target;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_item_selected = false;
|
||||||
|
if(is_panel_selected)
|
||||||
|
is_item_selected = i == self->cur;
|
||||||
|
item->draw(item->data, item_place, is_item_selected);
|
||||||
|
|
||||||
|
// adjust place for next item
|
||||||
|
if(self->is_horizontal){
|
||||||
|
item_place.x += item_place.w + self->spacing;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
item_place.y += item_place.h + self->spacing;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &self->items[self->cur];
|
return &self->items[self->cur];
|
||||||
|
|||||||
15
src/scope.c
15
src/scope.c
@@ -17,17 +17,18 @@ TimRect tim_scope_rect_to_absolute(i32 x, i32 y, i32 w, i32 h) {
|
|||||||
if (x == A) { //
|
if (x == A) { //
|
||||||
x = p.x + (p.w - w) / 2; // center x on parent
|
x = p.x + (p.w - w) / 2; // center x on parent
|
||||||
} else { //
|
} else { //
|
||||||
if (x < 0) { //
|
// if (x < 0) { //
|
||||||
x += p.w - w + 1; // anchor x to right
|
// x += p.w - w + 1; // anchor x to right
|
||||||
} //
|
// } //
|
||||||
x += p.x; // anchor x to left
|
if(x >= 0)
|
||||||
|
x += p.x; // anchor x to left
|
||||||
} //
|
} //
|
||||||
if (y == A) { //
|
if (y == A) { //
|
||||||
y = p.y + (p.h - h) / 2; // center y on parent
|
y = p.y + (p.h - h) / 2; // center y on parent
|
||||||
} else { //
|
} else { //
|
||||||
if (y < 0) { //
|
// if (y < 0) { //
|
||||||
y += p.h - h + 1; // anchor y to bottom
|
// y += p.h - h + 1; // anchor y to bottom
|
||||||
} //
|
// } //
|
||||||
y += p.y; // anchor y to top
|
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;
|
tim->scopes[tim->scope] = content_scope;
|
||||||
|
|
||||||
// draw content
|
// 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);
|
self->draw(self->data, content_place);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user