diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..414297c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,158 @@ +name: Deploy + +on: + workflow_dispatch: + inputs: + version: + description: Pass the version + required: true + type: string + release_info: + description: Information about release + required: true + type: string + dry_run: + description: Perform test without releasing + type: choice + required: true + default: "true" + options: + - "true" + - "false" + push: + tags: + - "[0-9]+.[0-9]+.[0-9]+" + +permissions: + contents: write + +jobs: + setup: + name: Prepare job settings + runs-on: ubuntu-latest + outputs: + version: ${{ steps.setup.outputs.version }} + dry_run: ${{ steps.setup.outputs.dry_run }} + info: ${{ steps.setup.outputs.info }} + steps: + - name: Checkout + uses: actions/checkout@v4 + if: ${{ github.event_name == 'push' }} + - name: Get the release version from the tag and info from commit + id: version_push + shell: bash + if: ${{ github.event_name == 'push' }} + run: | + echo version=${GITHUB_REF#refs/tags/} >> $GITHUB_OUTPUT + echo info=$(git tag -l --format='%(contents)' ${GITHUB_REF#refs/tags/}) >> $GITHUB_OUTPUT + - name: Get the release version from the input + id: version_dispatch + shell: bash + if: ${{ github.event_name == 'workflow_dispatch' }} + run: | + echo + echo version=$(echo ${{ inputs.version }} | xargs) >> $GITHUB_OUTPUT + echo dry_run=$(echo ${{ inputs.dry_run }} | xargs) >> $GITHUB_OUTPUT + echo info="${{ inputs.release_info }}" >> $GITHUB_OUTPUT + - name: Setup + id: setup + shell: bash + run: | + echo version=$(if [ -n "${{ steps.version_dispatch.outputs.version }}" ]; then echo "${{ steps.version_dispatch.outputs.version }}"; else echo "${{ steps.version_push.outputs.version }}"; fi) >> $GITHUB_OUTPUT + echo dry_run=$(if [ -n "${{ steps.version_dispatch.outputs.dry_run }}" ]; then echo "${{ steps.version_dispatch.outputs.dry_run }}"; else echo "false"; fi) >> $GITHUB_OUTPUT + echo info=$(if [ -n "${{ steps.version_dispatch.outputs.info }}" ]; then echo "${{ steps.version_dispatch.outputs.info }}"; else echo "${{ steps.version_push.outputs.info }}"; fi) >> $GITHUB_OUTPUT + - name: Display settings + shell: bash + run: echo "Version ${{ steps.setup.outputs.version }}, Dry run- ${{ steps.setup.outputs.dry_run }}, info- ${{ steps.setup.outputs.info }}" + - name: Validate input + shell: bash + run: | + if [ -z "${{ steps.setup.outputs.version }}" ]; then exit 1; fi; + if [ -z "${{ steps.setup.outputs.dry_run }}" ]; then exit 1; fi; + if [ -z "${{ steps.setup.outputs.info }}" ]; then exit 1; fi; + if [[ "${{ steps.setup.outputs.version }}" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+).*?$ ]]; then echo "Valid version"; else echo "INVALID VERSION FORMAT!";exit 1; fi; + build-and-upload: + name: Build and upload + needs: + - setup + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - build: linux + os: ubuntu-latest + target: x86_64-unknown-linux-musl + steps: + - name: Checkout + uses: actions/checkout@v4 + - uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ github.ref || github.run_id }} + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target }} + - name: Build + uses: actions-rs/cargo@v1 + with: + use-cross: true + command: build + args: --verbose --release --target ${{ matrix.target }} + - name: Extract changelog content + id: extract_changelog + shell: bash + run: | + version="${{ needs.setup.outputs.version }}" + echo "${{ needs.setup.outputs.info }}" > changelog_output.txt + awk "/^## \\[$version\\]/ {flag=1; next} /^## \\[/ && flag {flag=0} flag" CHANGELOG.md >> changelog_output.txt + - name: Display extracted content + run: cat changelog_output.txt + - name: Release + if: ${{ needs.setup.outputs.dry_run == 'false'}} + uses: softprops/action-gh-release@v2 + with: + body_path: changelog_output.txt + deploy-to-crates-io: + needs: + - setup + - build-and-upload + name: Deploy to crates.io + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ github.ref || github.run_id }} + - uses: dtolnay/rust-toolchain@stable + - uses: taiki-e/cache-cargo-install-action@v2 + with: + tool: cargo-release + - name: cargo publish dry run + if: ${{ needs.setup.outputs.dry_run == 'true'}} + run: cargo publish --dry-run + - name: cargo login + run: cargo login ${{ secrets.CRATES_IO_TOKEN }} + - name: "cargo release publish" + if: ${{ needs.setup.outputs.dry_run == 'false'}} + run: |- + cargo release \ + publish \ + --workspace \ + --all-features \ + --allow-branch HEAD \ + --no-confirm \ + --no-verify \ + --execute diff --git a/CHANGELOG.md b/CHANGELOG.md index c49a96a..0fcd03c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # CHANGELOG +## [0.3.0] + +## Added + +- scroll to bottom and top functions for `ScrollableContent` component. + +## Changed + +- Updated to Bevy 0.15 + +## [0.2.0] + +## Changed + +- Updated to Bevy 0.14 + ## [0.1.0] - Initial version diff --git a/Cargo.toml b/Cargo.toml index 363a02c..1bde28b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_simple_scroll_view" -version = "0.2.0" +version = "0.3.0" edition = "2021" exclude = [".github/","wasm/", "record.gif"] categories = ["game-development", "gui"] @@ -11,10 +11,14 @@ license = "MIT OR Apache-2.0" description = "Simple to use plugin implementing ScrollView into Bevy engine." [dependencies.bevy] -version = "0.14" +version = "0.15.0-rc.3" default-features = false features = ["bevy_ui", "bevy_asset", "bevy_text"] [dev-dependencies.bevy] -version = "0.14" +version = "0.15.0-rc.3" default-features = true + +[features] +default = [] +extra_logs = [] \ No newline at end of file diff --git a/examples/simple.rs b/examples/simple.rs index 94cb8ea..cbf709e 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -1,10 +1,10 @@ use bevy::prelude::*; use bevy_simple_scroll_view::*; -const CLR_1: Color = Color::rgb(0.168, 0.168, 0.168); -const CLR_2: Color = Color::rgb(0.109, 0.109, 0.109); -const CLR_3: Color = Color::rgb(0.569, 0.592, 0.647); -const CLR_4: Color = Color::rgb(0.902, 0.4, 0.004); +const CLR_1: Color = Color::srgb(0.168, 0.168, 0.168); +const CLR_2: Color = Color::srgb(0.109, 0.109, 0.109); +const CLR_3: Color = Color::srgb(0.569, 0.592, 0.647); +const CLR_4: Color = Color::srgb(0.902, 0.4, 0.004); fn main() { App::new() @@ -15,62 +15,66 @@ fn main() { } fn prepare(mut commands: Commands) { - commands.spawn(Camera2dBundle::default()); + commands.spawn(Camera2d::default()); commands - .spawn(NodeBundle { - style: Style { + .spawn(( + BackgroundColor(CLR_1), + Node { width: Val::Percent(100.0), height: Val::Percent(100.0), padding: UiRect::all(Val::Px(15.0)), ..default() }, - background_color: CLR_1.into(), - ..default() - }) + )) .with_children(|p| { - p.spawn(ButtonBundle { - style: Style { - margin: UiRect::all(Val::Px(15.0)), - padding: UiRect::all(Val::Px(15.0)), - max_height: Val::Px(100.0), - border: UiRect::all(Val::Px(3.0)), - align_items: AlignItems::Center, - ..default() - }, - background_color: CLR_2.into(), - border_color: CLR_4.into(), + p.spawn(Node { + width: Val::Percent(20.0), + margin: UiRect::all(Val::Px(10.0)), + flex_direction: FlexDirection::Column, ..default() }) .with_children(|p| { - p.spawn(TextBundle::from_section( - "Reset scroll", - TextStyle { - font_size: 25.0, - color: CLR_4, - ..default() - }, - )); + for btn_action in [ScrollButton::MoveToTop, ScrollButton::MoveToBottom] { + p.spawn(( + Node { + margin: UiRect::all(Val::Px(15.0)), + padding: UiRect::all(Val::Px(15.0)), + max_height: Val::Px(100.0), + border: UiRect::all(Val::Px(3.0)), + align_items: AlignItems::Center, + ..default() + }, + BackgroundColor(CLR_2), + BorderColor(CLR_4), + Button, + btn_action.clone(), + )) + .with_children(|p| { + p.spawn(( + Text::new(format!("{:#?}", btn_action)), + TextFont { + font_size: 25.0, + ..default() + }, + TextColor(CLR_4), + )); + }); + } }); p.spawn(( - NodeBundle { - style: Style { - width: Val::Percent(80.0), - margin: UiRect::all(Val::Px(15.0)), - ..default() - }, - background_color: CLR_2.into(), + Node { + width: Val::Percent(80.0), + margin: UiRect::all(Val::Px(15.0)), ..default() }, + BackgroundColor(CLR_2), ScrollView::default(), )) .with_children(|p| { p.spawn(( - NodeBundle { - style: Style { - flex_direction: bevy::ui::FlexDirection::Column, - width: Val::Percent(100.0), - ..default() - }, + Node { + flex_direction: bevy::ui::FlexDirection::Column, + width: Val::Percent(100.0), ..default() }, ScrollableContent::default(), @@ -78,29 +82,26 @@ fn prepare(mut commands: Commands) { .with_children(|scroll_area| { for i in 0..21 { scroll_area - .spawn(NodeBundle { - style: Style { + .spawn(( + Node { min_width: Val::Px(200.0), margin: UiRect::all(Val::Px(15.0)), border: UiRect::all(Val::Px(5.0)), padding: UiRect::all(Val::Px(30.0)), ..default() }, - border_color: CLR_3.into(), - ..default() - }) + BorderColor(CLR_3), + )) .with_children(|p| { - p.spawn( - TextBundle::from_section( - format!("Nr {}", i), - TextStyle { - font_size: 25.0, - color: CLR_3, - ..default() - }, - ) - .with_text_justify(JustifyText::Center), - ); + p.spawn(( + Text::new(format!("Nr {}", i)), + TextFont { + font_size: 25.0, + ..default() + }, + TextColor(CLR_3), + TextLayout::new_with_justify(JustifyText::Center), + )); }); } }); @@ -108,15 +109,26 @@ fn prepare(mut commands: Commands) { }); } +#[derive(Component, PartialEq, Debug, Clone, Copy)] +enum ScrollButton { + MoveToTop, + MoveToBottom, +} + fn reset_scroll( - q: Query<(&Button, &Interaction), Changed>, + q: Query<(&Interaction, &ScrollButton), (Changed, With