Improve the showing of scrollbars.
The not needed scrollbars are no longer shown, the space reserved for them is not always freed. (Easyclose still doesn't work as wanted.)
This commit is contained in:
parent
1a138d7505
commit
c916ead0ad
6 changed files with 88 additions and 40 deletions
|
@ -25,11 +25,6 @@ again by the load-game dialog.
|
|||
|
||||
***
|
||||
|
||||
The drawing engine for the new widgets is rewritten, the engine does show
|
||||
scrollbars too often, which will be fixed later.
|
||||
|
||||
***
|
||||
|
||||
The game now has two ingame dialogs, the old one and a new one. The new one
|
||||
shows a transparent portait which will be scaled to fit nicely on the screen.
|
||||
This might need some tuning. This means all portraits made by Kitty and the new
|
||||
|
|
|
@ -104,6 +104,7 @@
|
|||
definition = "default"
|
||||
|
||||
vertical_scrollbar_mode = "never"
|
||||
horizontal_scrollbar_mode = "never"
|
||||
assume_fixed_row_size = "true"
|
||||
|
||||
[list_definition]
|
||||
|
|
|
@ -181,6 +181,38 @@ tpoint tscrollbar_container::calculate_best_size() const
|
|||
return result;
|
||||
}
|
||||
|
||||
static void set_scrollbar_mode(tgrid* scrollbar_grid, tscrollbar_* scrollbar,
|
||||
tscrollbar_container::tscrollbar_mode& scrollbar_mode,
|
||||
const unsigned items, const unsigned visible_items)
|
||||
{
|
||||
|
||||
assert(scrollbar_grid && scrollbar);
|
||||
if(scrollbar_mode != tscrollbar_container::HIDE) {
|
||||
|
||||
scrollbar->set_item_count(items);
|
||||
scrollbar->set_visible_items(visible_items);
|
||||
|
||||
const bool scrollbar_needed =
|
||||
items > visible_items;
|
||||
|
||||
if(!scrollbar_needed) {
|
||||
|
||||
// Hide the scrollbar
|
||||
if(scrollbar_mode == tscrollbar_container::SHOW_WHEN_NEEDED) {
|
||||
if(true) { // extra setting
|
||||
scrollbar_mode = tscrollbar_container::HIDE;
|
||||
} else {
|
||||
scrollbar_grid->set_visible(twidget::HIDDEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(scrollbar_mode == tscrollbar_container::HIDE) {
|
||||
scrollbar_grid->set_visible(twidget::INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
void tscrollbar_container::
|
||||
set_size(const tpoint& origin, const tpoint& size)
|
||||
{
|
||||
|
@ -214,21 +246,22 @@ void tscrollbar_container::
|
|||
|
||||
|
||||
// Set vertical scrollbar
|
||||
assert(vertical_scrollbar_);
|
||||
if(vertical_scrollbar_mode_ != HIDE) {
|
||||
vertical_scrollbar_->set_item_count(content_grid_size.y);
|
||||
vertical_scrollbar_->set_visible_items(content_->get_height());
|
||||
}
|
||||
set_scrollbar_mode(vertical_scrollbar_grid_, vertical_scrollbar_,
|
||||
vertical_scrollbar_mode_,
|
||||
content_grid_->get_height(),
|
||||
content_->get_height());
|
||||
|
||||
// Set horizontal scrollbar
|
||||
assert(horizontal_scrollbar_);
|
||||
if(horizontal_scrollbar_mode_ != HIDE) {
|
||||
horizontal_scrollbar_->set_item_count(content_grid_size.x);
|
||||
horizontal_scrollbar_->set_visible_items(content_->get_width());
|
||||
}
|
||||
set_scrollbar_mode(horizontal_scrollbar_grid_, horizontal_scrollbar_,
|
||||
horizontal_scrollbar_mode_,
|
||||
content_grid_->get_width(),
|
||||
content_->get_width());
|
||||
|
||||
// Update the buttons.
|
||||
set_scrollbar_button_status();
|
||||
}
|
||||
|
||||
void tscrollbar_container:: set_origin(const tpoint& origin)
|
||||
void tscrollbar_container::set_origin(const tpoint& origin)
|
||||
{
|
||||
// Inherited.
|
||||
tcontainer_::set_origin(origin);
|
||||
|
@ -373,6 +406,8 @@ void tscrollbar_container::finalize_setup()
|
|||
vertical_scrollbar_->
|
||||
set_callback_positioner_move(callback_vertical_scrollbar);
|
||||
|
||||
show_vertical_scrollbar();
|
||||
|
||||
/***** Setup horizontal scrollbar *****/
|
||||
horizontal_scrollbar_grid_ =
|
||||
find_widget<tgrid>("_horizontal_scrollbar_grid", false, true);
|
||||
|
@ -383,6 +418,8 @@ void tscrollbar_container::finalize_setup()
|
|||
horizontal_scrollbar_->
|
||||
set_callback_positioner_move(callback_horizontal_scrollbar);
|
||||
|
||||
show_horizontal_scrollbar();
|
||||
|
||||
/***** Setup the scrollbar buttons *****/
|
||||
typedef std::pair<std::string, tscrollbar_::tscroll> hack;
|
||||
foreach(const hack& item, scroll_lookup()) {
|
||||
|
@ -430,7 +467,7 @@ void tscrollbar_container::
|
|||
{
|
||||
if(vertical_scrollbar_mode_ != scrollbar_mode) {
|
||||
vertical_scrollbar_mode_ = scrollbar_mode;
|
||||
show_vertical_scrollbar(vertical_scrollbar_mode_ != HIDE);
|
||||
show_vertical_scrollbar();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -439,20 +476,34 @@ void tscrollbar_container::
|
|||
{
|
||||
if(horizontal_scrollbar_mode_ != scrollbar_mode) {
|
||||
horizontal_scrollbar_mode_ = scrollbar_mode;
|
||||
show_horizontal_scrollbar(horizontal_scrollbar_mode_ != HIDE);
|
||||
show_horizontal_scrollbar();
|
||||
}
|
||||
}
|
||||
|
||||
void tscrollbar_container::show_vertical_scrollbar(const bool /*show*/)
|
||||
void tscrollbar_container::show_vertical_scrollbar()
|
||||
{
|
||||
/** @todo implement the new visibility. */
|
||||
// vertical_scrollbar_grid_->set_visible(show);
|
||||
if(!vertical_scrollbar_grid_) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(vertical_scrollbar_mode_ == HIDE) {
|
||||
vertical_scrollbar_grid_->set_visible(twidget::INVISIBLE);
|
||||
} else {
|
||||
vertical_scrollbar_grid_->set_visible(twidget::VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
void tscrollbar_container::show_horizontal_scrollbar(const bool /*show*/)
|
||||
void tscrollbar_container::show_horizontal_scrollbar()
|
||||
{
|
||||
/** @todo implement the new visibility. */
|
||||
// horizontal_scrollbar_grid_->set_visible(show);
|
||||
if(!horizontal_scrollbar_grid_) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(horizontal_scrollbar_mode_ == HIDE) {
|
||||
horizontal_scrollbar_grid_->set_visible(twidget::INVISIBLE);
|
||||
} else {
|
||||
horizontal_scrollbar_grid_->set_visible(twidget::VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
void tscrollbar_container::set_scrollbar_button_status()
|
||||
|
|
|
@ -233,21 +233,11 @@ private:
|
|||
*/
|
||||
virtual void finalize_subclass() {}
|
||||
|
||||
/**
|
||||
* Shows the vertical scrollbar.
|
||||
*
|
||||
* @param show If true the scrollbar is shown, hidden
|
||||
* otherwise.
|
||||
*/
|
||||
void show_vertical_scrollbar(const bool show);
|
||||
/** Sets the visible state of the vertical scrollbar. */
|
||||
void show_vertical_scrollbar();
|
||||
|
||||
/**
|
||||
* Shows the horizontal scrollbar.
|
||||
*
|
||||
* @param show If true the scrollbar is shown, hidden
|
||||
* otherwise.
|
||||
*/
|
||||
void show_horizontal_scrollbar(const bool show);
|
||||
/** Sets the visible state of the horizontal scrollbar. */
|
||||
void show_horizontal_scrollbar();
|
||||
|
||||
/** Inherited from tcontrol. */
|
||||
const std::string& get_control_type() const
|
||||
|
|
|
@ -685,7 +685,10 @@ twidget* tbuilder_label::build() const
|
|||
|
||||
tbuilder_listbox::tbuilder_listbox(const config& cfg) :
|
||||
tbuilder_control(cfg),
|
||||
scrollbar_mode(get_scrollbar_mode(cfg["vertical_scrollbar_mode"])),
|
||||
vertical_scrollbar_mode(
|
||||
get_scrollbar_mode(cfg["vertical_scrollbar_mode"])),
|
||||
horizontal_scrollbar_mode(
|
||||
get_scrollbar_mode(cfg["horizontal_scrollbar_mode"])),
|
||||
header(cfg.child("header") ? new tbuilder_grid(*(cfg.child("header"))) : 0),
|
||||
footer(cfg.child("footer") ? new tbuilder_grid(*(cfg.child("footer"))) : 0),
|
||||
list_builder(0),
|
||||
|
@ -705,6 +708,9 @@ tbuilder_listbox::tbuilder_listbox(const config& cfg) :
|
|||
* vertical_scrollbar_mode (scrollbar_mode = auto)
|
||||
* Determines whether or not to show the
|
||||
* scrollbar.
|
||||
* horizontal_scrollbar_mode (scrollbar_mode = auto)
|
||||
* Determines whether or not to show the
|
||||
* scrollbar.
|
||||
*
|
||||
* header (section = []) Defines the grid for the optional header.
|
||||
* footer (section = []) Defines the grid for the optional footer.
|
||||
|
@ -776,6 +782,9 @@ twidget* tbuilder_listbox::build() const
|
|||
|
||||
listbox->set_list_builder(list_builder); // FIXME in finalize???
|
||||
|
||||
listbox->set_vertical_scrollbar_mode(vertical_scrollbar_mode);
|
||||
listbox->set_horizontal_scrollbar_mode(horizontal_scrollbar_mode);
|
||||
|
||||
DBG_GUI << "Window builder: placed listbox '" << id << "' with defintion '"
|
||||
<< definition << "'.\n";
|
||||
|
||||
|
|
|
@ -158,7 +158,9 @@ public:
|
|||
|
||||
twidget* build () const;
|
||||
|
||||
tscrollbar_container::tscrollbar_mode scrollbar_mode;
|
||||
tscrollbar_container::tscrollbar_mode
|
||||
vertical_scrollbar_mode,
|
||||
horizontal_scrollbar_mode;
|
||||
|
||||
tbuilder_grid_ptr header;
|
||||
tbuilder_grid_ptr footer;
|
||||
|
|
Loading…
Add table
Reference in a new issue